- Introduction
- System Requirements
- Preparing to Work with the Software
- Deploying the Software
- Project Structure
- Code Overview
- Visualization
- Results and Interpretation
- License
This project simulates and optimizes traffic flow at an adjustable crossroads using Petri nets and a modified genetic algorithm. The simulation models traffic movement in four directions, considering traffic light phases and arrival rates. The genetic algorithm optimizes the duration of traffic light phases to minimize the maximum average number of waiting cars. This approach aims to reduce traffic congestion and improve overall traffic flow efficiency at the intersection.
The increasing number of vehicles in urban areas leads to frequent traffic congestion, especially at intersections. Inefficiently configured traffic lights can exacerbate these issues. This project aims to address the challenge of optimizing traffic light timings to minimize the average queue lengths at a four-way intersection. The traffic light cycle consists of four phases: green for one set of directions, followed by a yellow phase, then green for the opposite set of directions, and a final yellow phase. The goal is to determine the optimal durations for the green phases to minimize traffic congestion, using a combination of Petri net modeling and a genetic algorithm.
- Processor type: Pentium 2 266 MHz
- RAM: 1 GB
- Internet connection: at least 2 megabits
- JDK version: 20.0.2 or higher
- Processor type: AMD Ryzen 9 6900HS or equivalent
- RAM: 16 GB
- Internet connection: at least 100 megabits
- JDK version: 21.0.1 or higher
- Ensure you have the required JDK version installed.
- Clone the repository:
git clone https://github.com/your-username/adjustable-crossroads.git
- Navigate to the project directory.
1. Compile the Java code: `javac *.java` (within the respective `EVOLUTIONARY_SELECTION` and `POM` directories)
- Run the simulation:
java LibTest.TERM_PAPER.POM.AdjustableCrossroads
- Run the optimization:
java LibTest.TERM_PAPER.EVOLUTIONARY_SELECTION.TrafficLightOptimizer
- Run the CSV export:
java AdjustableCrossroadsCSVExport
- To generate visualizations, execute the Python scripts in the
VISUALIZATION
directory (requires Python and necessary libraries likematplotlib
,pandas
,opencv-python
). For example:python visualization.py
,python stability_crossroads_simulation.py
, andpython fitness_video_generator.py
- EVOLUTIONARY_SELECTION: Contains Java classes for the genetic algorithm ( Individual.java, Population.java, TrafficLightOptimizer.java).
- VISUALIZATION: Contains Python scripts for visualization ( visualization.py, stability_crossroads_simulation.py, results_3d.py, fitness_video_generator.py).
- POM: Contains Java classes for the Petri net simulation (AdjustableCrossroads.java, AdjustableCrossroadsCSVExport.java).
- media: Stores generated media files (images and videos).
- README.md: This file.
The Java code utilizes the PetriObj
library (https://github.com/StetsenkoInna/PetriObjModelPaint),
developed by Inna Stetsenko, for modeling the crossroads as a Petri net. This library provides the necessary
functionalities for creating and simulating Petri net models. The AdjustableCrossroads
class simulates the
traffic flow, while TrafficLightOptimizer
uses a genetic algorithm to find optimal phase times. The
Individual
class represents a solution (chromosome) in the genetic algorithm, and the Population
class manages a
collection of these solutions.
The Python scripts handle the visualization of the simulation and optimization data. They use libraries like
matplotlib
, pandas
, and opencv-python
to generate plots, charts, and animations.
visualization.py generates plots of fitness data over generations, including the best fitness, mean fitness, and box plots.
stability_crossroads_simulation.py creates plots of simulation statistics such as mean queue lengths and car counts over time for different iterations.
results_3d.py generates a 3D surface plot visualizing the fitness landscape, showing how different combinations of phase durations affect the maximum average queue length.
fitness_video_generator.py creates an animated 3D surface plot showing the evolution of the genetic algorithm over generations, which visually demonstrates the optimization process as the algorithm searches for the best phase timings.
The animation can also be viewed on YouTube: https://youtube.com/shorts/hXU6NNPJgXo.
This section interprets the results obtained from the simulation and optimization process, providing insights into the behavior of the traffic model and the effectiveness of the optimization approach.
Experimental results demonstrate that average queue lengths in different directions are dependent on the duration of the first and third phases of the traffic light cycle. Increasing the duration of the first phase (green light for directions 1 and 2) from 20 seconds to 40 seconds resulted in a 25% reduction in queue lengths for directions 1 and 2 but increased queues for directions 3 and 4 by 40%. Similarly, increasing the third phase from 30 seconds to 60 seconds reduced queues in directions 3 and 4 by 30% while increasing queues in directions 1 and 2 by 50%. These findings indicate the importance of balance in the time allocated to each direction.
The modified evolutionary algorithm demonstrated its capability to converge to optimal phase durations, which minimizes the average queue lengths at the intersection. The algorithm's use of tournament selection, elitism, mutation, and crossover allowed it to effectively explore the solution space. Comparison with combinatorial search results confirmed the correctness of the evolutionary algorithm's findings, showing a divergence of less than 2%.
The modeling results indicated that the optimal durations for the first and third phases are 25 and 10 seconds, respectively. With these settings, the maximum average number of waiting cars at any direction is approximately 0.91 cars, which is the lowest recorded among all the tested combinations.
The optimized parameters enable the traffic lights to operate more efficiently, reducing the average queues at the intersection by 40-50% compared to the initial (20 and 30 seconds) settings and reducing the delay for vehicles.
Analysis of the model's stability at the optimal phase durations showed that the simulation model is stable, with the queue lengths at each direction not deviating more than 10% from their steady-state values, which indicates the efficiency of the optimized parameters.
The simulation results showed the advantage of an optimized traffic light system over imbalanced configurations. A non-optimized system doesn't guarantee minimized delay, with a 30-40% increase in queue lengths for directions with shorter green times, compared to directions with longer green times. Adaptive traffic management systems, while potentially more effective, are more computationally intensive and complex to implement.
The project is licensed under the CC BY-NC 4.0 License.