GUI for a road traffic simulation coded in C++ by Luc and Claire PREVOST.
Traffic Simulator requires the folowing dependencies:
and uses from std:
- Array
- List
- Vector
- Iterator
- Algorithm
- Time
- Iostream (in debug mode)
- Cassert (in debug mode for unit tests)
The easyest way to execute the program is with Visual Studio: open the .sln file and hit F5!
After launching the program, a window pops up with a random network.
Relevants parameters are stored in the Constants.h file.
A network has a size (X, Y), a flow, a maximal number of car and a boost parameter. The flow gives the frequency of appearance of cars in the network. The boost parameter accelerate the simulation by keeping the ratios.
Intersections have a positon and input/output roads as parameters. Each intersection is initialized with a random points on a squared grid. Intersections manages the traffic lights. Input roads have the green light one by one.
Roads have a lenght parameter and contains a list of vehicle. They are initialised by doing a Delaunay triangulation. This gives a nice visuals by avoiding overlay and crossy roads, but also ensure the existence of a path between two intersections. More specifically, we use the Bowyer-Watson algorithm from the delaunator-cpp library.
There are 3 types of vehicles:
- Cars 🚗
- Trucks 🚛
- Bikes 🏍️
Each of them have a maximum speed and an acceleration parameter. They have a smooth displacement. Every Vehicules is initialized on a random road with a random target intersection. Their itinerary is obtained using the Dijkstra algorithm. Finally, the vehicles are not Britich, they drive on the right lane.
We are making a real time optimizer to optimize the discrete traffic flow, playing with traffic light having a non constant period. Below is a descrition of our approach to the problem. The relevant local input data at each intersection are:
- the number of road
and for each road:
- the number of vehicule
- the speed of the first car
- the distance of the first car
we can then introduce the folowing normalized parameters:
- N = number of cars / road capacity
- S = first car speed / speed max
- D = the distance of the first car / max distance
We can therefore define the folowing function: road index green = argmax{αN(i)+ßS(i)+(1-α-ß)D(i)}
with α,ß constants to be found by the optimizer, and i the road index. α and ß will tell which parameter is the most important to consider. We initialized them both at 1/3 to give a neutral initialization.
As this is a non differentiable problem, we discretize the set of solution, find the values of the control points, and fill the set of solution by doing a 2D interpolation. Finally, we find the maximum value of this set.
This code is well commented for Doxygen. Hence for more informations, a full documentation can be generated with Doxygen.
Now it is your turn to create traffic jams !
Thank you for using Traffic Simulator 🙂
Just simulate !