Skip to content

prishakhichadi/trafficnetworkoptimisation

Repository files navigation

Libraries you required to import are: Customtkinter Threading Time Networkx Subprocess Json Cma Numpy Csv Os Sys Random String Simpy Collections Matplotlib Pygame

Syntax Error - Team Raw Ingredients

Please run custom_tinker.py to start the program

Problem Statement: Modern day dense city road networks are a cause of lot of traffic jams as well as unnecessary delays. Some of the sources of the traffic may be irreducible but we explore the idea of optimization of traffic lane priorities at intersections to see its effect on traffic.

Our method to find a solution: We built a simulation in python using the simpy module where there were many cars incoming from each endpoint. This is used to represent very heavy traffic found in local transportation. Each car is fundamentally a simple object which has a defined fixed path randomly generated, it follows two rules, 1- if there is a car in front of it in the lane it waits, 2- if the light is red it waits. Our traffic lights are inspired by modern traffic lights with the implementation of camera to measure the traffic density in each lane. It decides the priority number a lane has according to the simple relation (a constant) multiplied by the number of cars in the lane. What this implies is the light is never green for lanes with no cars and directly prioritized for lanes with more cars. For a single intersection this logic of allowing lane with max cars to pass through makes sense but for a city network there comes heavy interdependency between intersections which we wish to exploit.

Our solution: We have used evolutionary strategies as our way to optimize this problem. We have used this over other methods as this is a black box type optimization problem where the ML-agent only sets the parameter and gets a reward instead of any active information about the state. These parameters are the earlier mentioned constants for each lane which are used to set the green light priority. Specifically we found greater success in using CMA - ES which stands for covariance matrix adaptation evolutionary strategies and uses a more advanced way to generate a more accurate next set of parameters from the information gained. Simpler algorithms required almost 30 times more computation time to reach the same average efficiency of this strategy.

To better illustrate what information our optimization program gets this is real sample data from our test simulations.

The mean wait represents the mean waiting time of all cars in our system. Our agent tries to minimize that by varying the lane_multipliers or the constants regarding each lane which are seen in columns after the mean waiting time. You can see in 12 generations which would take approx 1.2 minutes to compute it got the mean wait time down from 101.36 to 97.5964. When we talk about efficiency: here efficiency is the relative amount of time saved as compared to when no strategy was applied and all constants were 1.

Efficiency = (mean_wait_timeall constants = 1-mean_wait_timeoptimal rl model)/mean_wait_timeall constants = 1

How to recreate our results: From our github repository you would need to run the file named custom_tinker.py. It opens a simple GUI interface made by customtkinter. On the starting page there would be two options: 1- Gallery: It contains 3 example city networks we have already made and applied our optimization program to for approximately 30 minutes. These are used to show how the efficiency of our program increases as we allow it to run for more time,

2- Customize your own map: This allows users to make their own map using a simple pygame popup, It allows them to create nodes and intersection. Then we train our model for a small amount of time approximately 2 minutes on this exact city map after which it instantly runs and animation for the unoptimized version of the program(the node positions might change but functionally the layout is same). After you close this animation window a new window will pop up and run a animation based on the lane priorities set by our optimization program. Again closing out of this tab opens a new tab with the results. The result times considered are an average of many runs(can be set in main.py). We also plot a graph to showcase how much time our program after running for n many generations.

These hyperparameters can be changed in the main.py file if the user wishes to train their own city network more rigorously. Increasing generations, population size are common ways to find more optimal solution but they come at a cost of computation time.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages