A modular route optimization system supporting multiple algorithms for different routing problems.
Route Optimizer is a flexible framework for solving various route optimization problems using real street networks from OpenStreetMap. It provides a pluggable architecture where different algorithms can be applied depending on your use case.
| Algorithm | Problem Type | Best For |
|---|---|---|
| CPP (Chinese Postman) | Edge coverage | Street sweeping, patrol routes, inspections |
| TSP (Traveling Salesman) | Node visits | Deliveries, pickups, point-to-point routes |
The system is designed to be extensible - new algorithms (VRP, CVRP, etc.) can be added easily.
- ๐งฎ Multiple algorithms - CPP, TSP, with extensible architecture
- ๐บ๏ธ Real street networks - Downloads from OpenStreetMap
- ๐ Zone-based routing - Define areas with polygons
- ๐ Excel export - Detailed route coordinates
- ๐จ Visualization - Map plots with matplotlib
- โ๏ธ JSON configuration - Easy setup and maintenance
- ๐ณ Docker support - Quick setup with all dependencies
Docker handles all geospatial dependencies (GDAL, GEOS, PROJ) automatically.
git clone <repository-url>
cd route-optimizer
make buildOption A - Development (interactive shell):
Best for development and experimentation. Enter the container and run scripts manually.
make shell
# Now inside the container:
python parking_enforcement.py # CPP example
python delivery_route.py # TSP exampleOption B - Quick execution (run directly):
Best for one-off runs without entering the container.
docker compose run --rm app python parking_enforcement.py
docker compose run --rm app python delivery_route.py# System dependencies (Ubuntu/Debian)
sudo apt-get install gdal-bin libgdal-dev libgeos-dev libproj-dev libspatialindex-dev
# Setup
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# Verify installation
python verify_install.py
# Run examples
python parking_enforcement.py # CPP - cover all streets
python delivery_route.py # TSP - visit pointsSee QUICKSTART.md for detailed installation instructions.
route-optimizer/
โโโ algorithms/ # ๐งฎ Algorithm implementations
โ โโโ base.py # Abstract base solver
โ โโโ cpp/ # Chinese Postman Problem
โ โ โโโ solver.py
โ โโโ tsp/ # Traveling Salesman Problem
โ โโโ solver.py
โโโ route_optimizer.py # Main RouteOptimizer class
โโโ config_loader.py # JSON configuration loader
โโโ zone_config.json # Example configuration
โโโ parking_enforcement.py # CPP example (cover all streets)
โโโ delivery_route.py # TSP example (visit points)
โโโ verify_install.py # Verify dependencies
โโโ algorithms.md # Algorithm documentation
โโโ Dockerfile # Docker setup
โโโ docker-compose.yml
โโโ Makefile
โโโ requirements.txt
from route_optimizer import RouteOptimizer, Zone
from shapely.geometry import Polygon
from datetime import time
# Define your area
zone = Zone(
name="downtown",
polygon=Polygon([
(-73.99, 40.73), (-73.98, 40.73),
(-73.98, 40.74), (-73.99, 40.74),
]),
start_time=time(8, 0),
end_time=time(18, 0),
weekdays=[0, 1, 2, 3, 4],
color="gold"
)
# Create optimizer
optimizer = RouteOptimizer(
bbox=(-74.00, 40.72, -73.97, 40.75),
start_point=(40.735, -73.985),
zones=[zone]
)
# Download street network
optimizer.download_street_network()
optimizer.label_zones()
# Solve with CPP (cover all streets)
route, distance = optimizer.solve_cpp("full")
# Or solve with TSP (visit all intersections)
route, distance = optimizer.solve_tsp("full")from config_loader import load_configuration
from route_optimizer import RouteOptimizer
bbox, start_point, zones, _ = load_configuration('zone_config.json')
optimizer = RouteOptimizer(bbox, start_point, zones)| Your Problem | Algorithm | Method |
|---|---|---|
| Cover all streets in an area | CPP | solve_cpp() |
| Visit specific points | TSP | solve_tsp() |
| Patrol/sweep entire neighborhood | CPP | solve_cpp() |
| Deliver packages to addresses | TSP | solve_tsp() |
| Inspect all roads | CPP | solve_cpp() |
| Pick up items at locations | TSP | solve_tsp() |
๐ See algorithms.md for detailed algorithm documentation.
Cover every street in the city with minimum repeated travel.
route, distance = optimizer.solve_cpp("full")
print(f"Route covers all streets in {distance/1000:.1f} km")Visit specific delivery points efficiently.
delivery_points = [node1, node2, node3, node4]
route, distance = optimizer.solve_tsp("full", nodes_to_visit=delivery_points)Ensure all parking meters are checked.
route, distance = optimizer.solve_cpp("downtown_zone")
optimizer.export_results({"patrol": (route, distance)}, "patrol_routes.xlsx")Visit all meter locations.
route, distance = optimizer.solve_tsp("full")
detailed_route = solver.get_detailed_route(route) # Include intermediate nodes{
"configuration": {
"bbox": {"west": -74.00, "south": 40.72, "east": -73.97, "north": 40.75},
"start_point": {"latitude": 40.735, "longitude": -73.985}
},
"zones": [
{
"name": "downtown",
"polygon": [[-73.99, 40.73], [-73.98, 40.73], [-73.98, 40.74], [-73.99, 40.74]],
"schedule": {"start": "08:00", "end": "18:00"},
"weekdays": [0, 1, 2, 3, 4],
"color": "gold"
}
],
"route_types": {
"full": {"zones": ["downtown", "midtown"]},
"morning": {"zones": ["downtown"]}
}
}- Google Maps: Right click โ "What's here?"
- OpenStreetMap: Shift+Click
- GeoJSON.io: Draw polygon and export
[longitude, latitude] (reversed from typical lat/lon!)
results = {
"full_coverage": optimizer.solve_cpp("full"),
"delivery_route": optimizer.solve_tsp("full", nodes_to_visit=points)
}
optimizer.export_results(results, "routes.xlsx")Output sheets:
- Summary: Distance comparison for all routes
- Per-route sheets: Sequence, Node_ID, Latitude, Longitude, Zone
optimizer.visualize_zones(save_path="map.png")
optimizer.visualize_route(route, graph, "My Route", save_path="route.png")The system is built for extensibility. To add a new algorithm:
# algorithms/vrp/solver.py
from algorithms.base import BaseSolver
class VRPSolver(BaseSolver):
name = "Vehicle Routing Problem"
description = "Multiple vehicles, capacity constraints"
use_cases = ["Fleet delivery", "Logistics"]
def solve(self):
# Your implementation
route = [...]
distance = self.calculate_route_distance(route)
return route, distanceThen register in algorithms/__init__.py.
| Issue | Solution |
|---|---|
| Network doesn't download | Check bbox coordinates and internet |
| "Not strongly connected" | โ Handled automatically |
| Empty results | Verify zone polygons cover the area |
| Import errors | Install dependencies: pip install -r requirements.txt |
- QUICKSTART.md - Get started in 3 steps
- algorithms.md - Detailed algorithm documentation
- SUMMARY.md - Project overview
- VRP (Vehicle Routing Problem) - multiple vehicles
- CVRP (Capacitated VRP) - vehicle capacity constraints
- Time windows support
- Interactive web interface
- Google Maps/Mapbox integration
- Real-time traffic consideration
- Fork the repository
- Create a feature branch
- Add your algorithm in
algorithms/your_algorithm/ - Submit a pull request
MIT License - see LICENSE
Developed by Data Crew Consulting
Version: 1.0.0
Last updated: December 2025
