simulation
A large part of our project consisted of developing and creating a simulation to accurately represent cars, roads and intersections using MATLAB, our programming language of choice. We created a small scale system of 4 intersections using 4 two-lane roads, all of identical length.
In order to fit into the confines of MATLAB's primarily numerical data structures, we created 3 main structures to simulate our system: Cars, Roads, and Intersections. Each of these three "structs" held all the information of all the respective elements that excites in our simulation. For example, the Cars struct contained all the cars of the system, as well as all the information associated with each car. The same idea was applied to Roads and Intersections.
The following is an outline of the structures:
In order to fit into the confines of MATLAB's primarily numerical data structures, we created 3 main structures to simulate our system: Cars, Roads, and Intersections. Each of these three "structs" held all the information of all the respective elements that excites in our simulation. For example, the Cars struct contained all the cars of the system, as well as all the information associated with each car. The same idea was applied to Roads and Intersections.
The following is an outline of the structures:
Cars
The Cars struct is made up of the following:
- The car's position on the map
- A boolean telling if the car still exists in the system
- A randomly generated color (used for visualization)
- A unique index
- A velocity (1 or 2 cells per time-step)
- A boolean telling if the car has moved at a give time-step
- An integer recording the time a car has waited in the system
- An integer recording the traveling time for the car in the system
- The car's destination on the map
- A route that the car follows to traverse the roads from its position to destination
- The car's position on the map
- A boolean telling if the car still exists in the system
- A randomly generated color (used for visualization)
- A unique index
- A velocity (1 or 2 cells per time-step)
- A boolean telling if the car has moved at a give time-step
- An integer recording the time a car has waited in the system
- An integer recording the traveling time for the car in the system
- The car's destination on the map
- A route that the car follows to traverse the roads from its position to destination
Roads
The Roads structure is a little harder to understand. In our model, we have 4 roads and 4 intersections. Each Road contains a structure of 2 lanes. We define each of the lanes to be in opposite directions. Each lane contains an index {1 or 2} and a structure of "car_cells" which is a column vector containing the index of each car that resides in the respective cell of each Road{r}.lane{l} (where r is a road number, and l is a lane number).
For example, if Car 1 was in position [2 1 1] (as seen above), this vector correlates to the Car 1's current position being Road 2. Lane 1, Cell 1.
Thus, the Road structure would look like such. There do not appear to be any other cars on Road 2, Lane 1.
We can use the Roads structure to see if any other cars are head of any given car and then move if it not.
Thus, the Road structure would look like such. There do not appear to be any other cars on Road 2, Lane 1.
We can use the Roads structure to see if any other cars are head of any given car and then move if it not.
Intersections
The Intersections structure holds the position of each intersection (which two roads intersect) as well as the traffic lights for each of the four intersections in our model.
The position vector corresponds to which two roads intersect at the given intersection.
As you can see, at Intersection 1, Road 1 and Road 3 intersect.
The lights vector corresponds to the status of the traffic lights. We used 0 for red and 1 for green lights. A lights vector of [0 1] means that Road 1 has a red light, while Road 3 has a green light.
As you can see, at Intersection 1, Road 1 and Road 3 intersect.
The lights vector corresponds to the status of the traffic lights. We used 0 for red and 1 for green lights. A lights vector of [0 1] means that Road 1 has a red light, while Road 3 has a green light.
visualization
In order to make these data structures become easier to view and understand, we created a visualization that plots the roads, traffic lights and each car's position at each time step.
Below, there is a sample of our visualization for a system with 10 cars.
Below, there is a sample of our visualization for a system with 10 cars.
** Note: The visualization is of British Roads.
Dynamics
The dynamics we created for our simulation imitate that of a real light traffic situation.
We discretized the road cells to more easily simulate traffic, but only one car can exist in each road cell. Cars move ahead one or two cells in each time-step, depending on the car's max velocity. A car will only move ahead if the cell in front of it is empty (without a car), and a car with velocity of 2 cells per time-step will move 1 head if there is a car two cells ahead.
Cars stop at red lights and go at green lights. We developed traffic light controllers (outlined in the Algorithms Tab) to change the traffic lights non-adaptively and adaptively. As you can see, in the Results Tab, the adaptive (Reinforcement Learning) controller outperform the non-adaptive (alternating set-time lights) controllers.
We discretized the road cells to more easily simulate traffic, but only one car can exist in each road cell. Cars move ahead one or two cells in each time-step, depending on the car's max velocity. A car will only move ahead if the cell in front of it is empty (without a car), and a car with velocity of 2 cells per time-step will move 1 head if there is a car two cells ahead.
Cars stop at red lights and go at green lights. We developed traffic light controllers (outlined in the Algorithms Tab) to change the traffic lights non-adaptively and adaptively. As you can see, in the Results Tab, the adaptive (Reinforcement Learning) controller outperform the non-adaptive (alternating set-time lights) controllers.