fork download
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <queue>
  5. #include <chrono>
  6. #include <random>
  7.  
  8. // Constants
  9. const int NUM_BASE_STATIONS = 5;
  10. const int NUM_DEVICES = 20;
  11. const int SIMULATION_TIME = 100; // seconds
  12. const int DATA_TRANSFER_RATE = 1000; // Mbps
  13. const int LATENCY = 10; // ms
  14.  
  15. // Structs
  16. struct Device {
  17. int id;
  18. int baseStationId;
  19. int dataToTransfer;
  20. };
  21.  
  22. struct BaseStation {
  23. int id;
  24. int capacity;
  25. std::queue<Device> devices;
  26. };
  27.  
  28. // Function to simulate data transfer
  29. void simulateDataTransfer(BaseStation& baseStation, Device& device) {
  30. int dataTransferred = 0;
  31. int timeElapsed = 0;
  32. while (dataTransferred < device.dataToTransfer && timeElapsed < SIMULATION_TIME) {
  33. int data = std::min(baseStation.capacity, device.dataToTransfer - dataTransferred);
  34. dataTransferred += data;
  35. timeElapsed++;
  36. std::cout << "Device " << (link unavailable) << " transferred " << data << " MB to Base Station " << (link unavailable) << std::endl;
  37. }
  38. }
  39.  
  40. // Function to simulate latency
  41. void simulateLatency(BaseStation& baseStation, Device& device) {
  42. std::cout << "Device " << (link unavailable) << " experienced " << LATENCY << " ms latency to Base Station " << (link unavailable) << std::endl;
  43. }
  44.  
  45. // Main function
  46. int main() {
  47. // Initialize base stations and devices
  48. std::vector<BaseStation> baseStations(NUM_BASE_STATIONS);
  49. for (int i = 0; i < NUM_BASE_STATIONS; i++) {
  50. baseStations[i].id = i;
  51. baseStations[i].capacity = DATA_TRANSFER_RATE;
  52. }
  53. std::vector<Device> devices(NUM_DEVICES);
  54. for (int i = 0; i < NUM_DEVICES; i++) {
  55. devices[i].id = i;
  56. devices[i].baseStationId = i % NUM_BASE_STATIONS;
  57. devices[i].dataToTransfer = 100; // MB
  58. }
  59.  
  60. // Simulate network
  61. for (int i = 0; i < SIMULATION_TIME; i++) {
  62. for (auto& device : devices) {
  63. BaseStation& baseStation = baseStations[device.baseStationId];
  64. simulateDataTransfer(baseStation, device);
  65. simulateLatency(baseStation, device);
  66. }
  67. }
  68.  
  69. // Evaluate performance
  70. int totalDataTransferred = 0;
  71. for (auto& device : devices) {
  72. totalDataTransferred += device.dataToTransfer;
  73. }
  74. std::cout << "Total data transferred: " << totalDataTransferred << " MB" << std::endl;
  75. std::cout << "Average latency: " << LATENCY << " ms" << std::endl;
  76.  
  77. // Identify potential applications and use cases
  78. std::cout << "Potential applications and use cases:" << std::endl;
  79. std::cout << "- IoT devices" << std::endl;
  80. std::cout << "- Smart cities" << std::endl;
  81. std::cout << "- Autonomous vehicles" << std::endl;
  82.  
  83. return 0;
  84. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Enter a value: 5G Network Simulation
---------------------
gNB: Sending data...
UE: Receiving data...