This project simulates a traffic management system at a junction connecting four major roads (A, B, C, and D). Each road has three lanes with specific rules for vehicle movement, traffic lights, and priority management. The system uses queues to manage vehicle flow and priority lanes, aiming to solve real-world traffic issues through data structures.
- Fair Vehicle Distribution: Ensures equal dispatch from each lane under normal conditions.
- Priority Management: Prioritizes lanes with high waiting vehicles to reduce congestion.
- Traffic Light Simulation: Manages traffic flow using state-based lights (Red - Stop, Green - Go).
- Queue Management: Utilizes vehicle and priority lane queues to optimize traffic flow.
- Real-time Visualization: Simulates and visualizes vehicle movement at the junction.
- Four Major Roads: A, B, C, D.
- Three Lanes per Road:
- L1: Incoming Lane
- L2: Outgoing Lane (Priority Lane)
- L3: Free Lane (Left Turn Only)
- Normal Lane: Default state for all lanes unless declared as priority.
- Priority Lane:
- Lane AL2 is designated as a priority lane.
- If more than 10 vehicles are waiting, this lane is served first until the count drops below 5.
- Resumes normal condition when the vehicle count is less than 5.
- Four Traffic Lights controlling opposite lanes.
- States:
- Red Light: Stop
- Green Light: Go Straight or Turn
- Timing Calculation:
- The green light duration is calculated based on the average number of waiting vehicles.
- Vehicle Queue: Maintains vehicles for each road.
- Lane/Light Priority Queue: Manages lane priorities dynamically, especially for priority lane AL2.
-
Initialization:
- Set up vehicle queues for each road (A, B, C, D).
- Initialize a priority queue for lane management.
-
Traffic Light Management:
- Pair lights to control opposite lanes.
- Calculate green light duration using:
-
Vehicle Dispatching:
- Under normal conditions, serve vehicles equally from each lane.
- Under high-priority conditions, serve priority lane (AL2) until vehicles < 5.
- Resume normal condition afterward.
-
Queue Management:
- Use a priority queue for lane management.
- Update priority dynamically based on vehicle count in AL2.
dsa-queue-generator
├── demo.gif
├── Makefile
├── README.md
└── src
├── generator.c
├── main.c
├── traffic_simulation.c
└── traffic_simulation.h
- Clone the repository:
git clone https://github.com/LORDSINE/dsa-queue-generator.git
- Navigate to the project directory:
cd dsa-queue-generator
- Compile and run the simulation:
make run
- Configure the number of vehicles for each lane in the input file.
- Run the simulation to see how vehicles are managed at the junction.
- Observe the priority changes and green light timings.
- Normal Condition: Vehicles are served equally across lanes.
- High-Priority Condition: Lane AL2 gets priority if more than 10 vehicles are waiting.
- Free Lane: L3 of each road is free and allowed to turn left without light conditions.
- Visual Output: The simulation displays vehicle movements and light states.
- Programming Language: C
- Data Structure: Queue, Priority Queue
- Compiler: gcc
Contributions are welcome! Feel free to open issues or submit pull requests.
- Fork the repository.
- Create a new branch:
git checkout -b feature-branch-name
- Make your changes and commit:
git commit -m "Add your message here"
- Push to the branch:
git push origin feature-branch-name
- Submit a pull request.
- Kathmandu University for inspiring this project.
- Course instructors for guidance on queue management systems.