This repository was archived by the owner on Feb 16, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
98 lines (80 loc) · 2.74 KB
/
Copy pathmain.cpp
File metadata and controls
98 lines (80 loc) · 2.74 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <algorithm>
#include <fstream>
#include <iostream>
#include "include/RoadSpreader.h"
#include "include/TrafficSystem.h"
#include "include/Factories/VehicleFactory.h"
#include "include/Intersections/FixedCycleIntersection.h"
#include "include/Intersections/FourStopIntersection.h"
#include "include/Intersections/Intersection.h"
#include "include/Intersections/PriorityIntersection.h"
int main()
{
#ifdef _WIN32
// Fix UTF-8 encoding on Windows
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
#endif
TrafficSystem system;
// Create roads
Road northRoad{"Route Nord", NORTH};
Road southRoad{"Route Sud", SOUTH};
Road eastRoad{"Route Est", EAST};
Road westRoad{"Route Ouest", WEST};
std::vector<std::shared_ptr<Road>> roads;
roads.push_back(std::make_shared<Road>(northRoad));
roads.push_back(std::make_shared<Road>(southRoad));
roads.push_back(std::make_shared<Road>(eastRoad));
roads.push_back(std::make_shared<Road>(westRoad));
// Choose one of the following scenarios:
// Scenario 1: Spread traffic evenly on all roads
spreadEvenly(roads, 120);
// Scenario 2: Spread traffic evenly on all roads in the given directions
//spreadOnDirections(roads, NORTH | SOUTH, 120);
// Scenario 3: Unbalanced traffic (50 vehicles N-S, 10 vehicles E-W = 120 total)
//spreadUnbalanced(roads, 50, 10);
// Scenario 4: Unbalanced traffic (60 vehicles N, 60 vehicles W)
//spreadUnbalancedOnDirections(roads, 60, 60);
// Create intersection - choose one type:
// Type 1: Priority Light (dynamic based on traffic)
PriorityIntersection intersection{
"Intersection Principale",
roads,
3,
5
};
// Type 2: Fixed Light (alternating cycle)
/*FixedCycleIntersection intersection{
"Intersection Principale",
roads,
3,
3
};*/
// Type 3: Four-Way Stop (one vehicle at a time)
/*FourStopIntersection intersection{
"Intersection Principale",
roads
};*/
system.addIntersection(&intersection);
// Simulation
for (int turn = 1; system.hasVehicles(); turn++)
{
// Uncomment the following lines to see detailed simulation
//std::cout << "========== Tour " << turn << " ==========" << std::endl;
//system.display(std::cout);
system.process();
//std::cout << std::endl;
}
const auto processedCount = system.getProcessedVehicles();
const auto totalWaitTime = system.getTotalWaitTime();
std::cout << "========== Résultats finaux ==========" << std::endl;
std::cout << "Véhicules traités: " << processedCount << std::endl;
std::cout << "Temps d'attente total: " << totalWaitTime << " tours" << std::endl;
std::cout << "Temps d'attente moyen: ";
if (processedCount > 0)
std::cout << static_cast<float>(totalWaitTime) / static_cast<float>(processedCount);
else
std::cout << 0;
std::cout << " tours / véhicule" << std::endl;
return 0;
}