-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Expand file tree
/
Copy pathTrafficSystemDemo.cpp
More file actions
39 lines (31 loc) · 1.32 KB
/
TrafficSystemDemo.cpp
File metadata and controls
39 lines (31 loc) · 1.32 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
#include "TrafficSystem.hpp"
#include <iostream>
#include <thread>
#include <chrono>
int main() {
TrafficSystem system;
// Create an intersection
Intersection* intersection1 = system.createIntersection();
// Add signals to the intersection
Signal* signal1 = system.addSignal(intersection1->getIntersectionId(), 20, 5, 25);
Signal* signal2 = system.addSignal(intersection1->getIntersectionId(), 20, 5, 25);
// Display initial status
system.displaySystemStatus();
// Simulate traffic system for a few cycles
for (int i = 0; i < 10; i++) {
std::cout << "\nTime step " << i + 1 << ":" << std::endl;
system.updateSystem(5); // Update every 5 seconds
system.displaySystemStatus();
std::this_thread::sleep_for(std::chrono::seconds(1));
}
// Simulate intersection failure
std::cout << "\nSimulating intersection failure..." << std::endl;
system.setIntersectionStatus(intersection1->getIntersectionId(), false);
system.displaySystemStatus();
// Restore intersection
std::cout << "\nRestoring intersection..." << std::endl;
system.setIntersectionStatus(intersection1->getIntersectionId(), true);
system.synchronizeIntersection(intersection1->getIntersectionId());
system.displaySystemStatus();
return 0;
}