This project simulates traffic control at a road intersection in a city. The primary objective is to manage the flow of vehicles through the intersection using traffic lights and ensure that traffic congestion is minimized while avoiding collisions.
- Create a traffic control strategy.
- Visualize the strategy with a simulation.
- Use the SDL2 library for visualization.
- Two roads crossing each other, forming an intersection.
- Each road has one lane in each direction.
- Vehicles can turn left, turn right, or go straight.
- Positioned at the points where each lane enters the intersection.
- Have only two states: red and green.
- Control algorithm to minimize congestion (not more than 8 vehicles) and avoid collisions.
- Painted in colors indicating their route.
- Fixed velocity.
- Maintain a safe distance from other vehicles.
- Stop at red lights and proceed on green.
- ↑ Up: Spawn a vehicle moving from the south.
- ↓ Down: Spawn a vehicle moving from the north.
- → Right: Spawn a vehicle moving from the west.
- ← Left: Spawn a vehicle moving from the east.
- r: Spawn a vehicle from a random direction.
- Esc: End the simulation.
- Documentation for SDL2.
- Rust programming language installed
- SDL2 library
1. Clone the repository:
git clone https://github.com/moussadiengsala/road_intersection.git
cd road_intersection
2. Install dependencies:
cargo build
3. Usage
cargo run
Use the keyboard controls to spawn vehicles and observe the traffic flow.
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License.