This project demonstrates route optimization algorithms (Ant Colony Optimization and Nearest Neighbor) for urban logistics using real geographical coordinates and travel time data from the OpenRouteService API. It supports animated map visualizations and performance analysis.
- Real route travel time matrix generated from OpenRouteService
- Ant Colony Optimization (ACO) with map animation and convergence plots
- Performance comparison plots (ACO: travel time vs. ants and iterations)
- Nearest Neighbor algorithm with dynamic map animation
- Visualizations on OpenStreetMap basemap
- CSV exports of optimal routes and travel time summaries
- Unified launcher (
main.py
) to run all components step-by-step

- Python 3.9+
- Libraries:
networkx
,matplotlib
,contextily
,pandas
,numpy
,openrouteservice
,tqdm
- Map provider: OpenStreetMap via
contextily
- API integration: OpenRouteService
Download and unzip the project archive. Open the extracted folder in your preferred IDE (e.g., Visual Studio Code).
git clone https://github.com/d-kudin/Logistics_Route_Optimization.git
cd Logistics_Route_Optimization
python -m venv venv
venv\Scripts\activate # Windows
source venv/bin/activate # Linux / macOS
pip install -r requirements.txt
Write your API keys to the file .env instead of:
your_ORS_api_key
How to Get an OpenRouteService API Key
- Visit: https://openrouteservice.org/dev/#/signup
- Create a free account.
- Go to Dashboard > API Keys and copy your personal key.
- Copy the generated key and store it in your
.env
file
The file data/data.csv must include the following columns:
ID | ADDRESS | X (lon) | Y (lat) |
---|---|---|---|
0 | 123 Main St, CityName | -95.12 | 29.76 |
1 | 456 Elm St, CityName | -95.43 | 29.78 |
The generate_distance_matrix.py script will query the OpenRouteService Matrix API to generate output/distance_matrix.csv, containing the travel time matrix.
pytest test_generate_distance_matrix.py
python main.py
Generate distance matrix from coordinates:
python generate_distance_matrix.py
Run Ant Colony Optimization with animated map:
python algorithms/ant_colony_with_map.py
Run Nearest Neighbor with animated map:
python algorithms/nearest_neighbor_with_map.py
Run ACO performance benchmark:
python algorithms/ant_colony_with_plot.py
All outputs are stored in output/
If distance_matrix.csv has unusually large values (thousands of seconds), the system will automatically convert them to minutes. All visualizations use OpenStreetMap tiles via contextily. Real driving times ensure realistic logistics approximations. You must be online for distance matrix generation via OpenRouteService.


