Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (42 loc) · 1.48 KB
/
Copy pathmain.cpp
File metadata and controls
54 lines (42 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// main.cpp
#include <iostream>
#include <vector>
#include <memory>
#include <thread>
#include <chrono>
#include <cstdlib>
#include "Aircraft.h"
#include "Logger.h"
#include "RunwayManager.h"
int main() {
Logger::init("log.txt");
std::cout << "🛫 Starting Air Traffic Control Simulation..." << std::endl;
Logger::log("Simulation started.");
RunwayManager manager;
// Simulate adding aircraft every few milliseconds
std::vector<std::thread> generatorThreads;
for (int i = 0; i < 10; ++i) {
generatorThreads.emplace_back([i, &manager]() {
std::this_thread::sleep_for(std::chrono::milliseconds(rand() % 1000));
std::string id = "AC" + std::to_string(1000 + i);
AircraftType type = (i % 2 == 0) ? AircraftType::LANDING : AircraftType::TAKEOFF;
int fuel = rand() % 100;
std::shared_ptr<Aircraft> ac = std::make_shared<Aircraft>(id, type, fuel);
manager.requestAccess(ac);
});
}
// Start runway thread
std::thread runwayThread(&RunwayManager::manageRunway, &manager);
// Wait for all aircraft to be created
for (auto& t : generatorThreads) {
t.join();
}
// Allow runway manager to finish
std::this_thread::sleep_for(std::chrono::seconds(5));
manager.stop();
runwayThread.join();
Logger::log("Simulation ended.");
Logger::close();
std::cout << "✅ Simulation Complete. Check log.txt for details." << std::endl;
return 0;
}