This project is a Python-based framework designed to automate the optimization of urban traffic flow. The system integrates three major components:
- Perception – Detects and tracks vehicles from video data.
- Flow Prediction – Computes real-time traffic flow metrics and predicts future trends using machine learning models.
- Flow Optimization – Determines network flow rate for different routes to maximize throughput and regulate congestion.
.
├── dataset
├── optimization
│ ├── linear-program/
│ │ ├── network_model/ # OOP classes for building traffic network
│ │ ├── lp_solver.py # Optimization solver via linear program
│ │ └── main.py
│ └── README.md
├── perception
│ ├── model/ # Trained model weights, not tracked
│ ├── results/
│ └── src
│ ├── utils/
│ └── main.py
├── prediction
│ ├── results
│ │ ├── analysis/
│ │ └── dataframe/
│ └── src
│ ├── random_forest/
│ ├── utils/
│ └── main.py
├── README.md
└── requirements.txt
Further details about each functional module are described below.
The perception portion of the framework handles the following tasks:
- Trains YOLOv8 model for vehicle detection.
- Tracks detected objects using DeepSort.
- Iterates through
.mp4videos indataset/vid(local only, not committed). - Exports frame-by-frame detection and tracking results to
perception/resultsin the following JSON structure:
{
"vid_id": "vid_id",
"detections": [
[
{
"TRACK_ID": [X_1, Y_1, X_2, Y_2]
},
...
],
...
]
}
The flow prediction module is responsible for:
- Processes each JSON file in
perception/resultsto compute traffic metrics: average speed, density, and flow. - Uses these features to train a Random Forest regression model for traffic flow prediction.
- Evaluates performance using standard metrics such as MAE and RMSE.
The optimization module includes:
- Simulating traffic networks using directed graphs.
- Determining capacities, thresholds, and flow constraints for each edge and path.
- Formulating graph-based Linear Programming (LP) problems to optimize network flow and regulate congestion.
- Detailed mathematical setup is documented in ./optimization/README.md.