Overview
Tesis Rutas features intelligent route generation that automatically creates optimized tourist routes from any starting POI. The algorithm uses geographic proximity and the Haversine formula to suggest the most efficient routes.The route generation algorithm is deterministic and geography-based - it selects the nearest POIs to minimize travel distance.
How It Works
The route generation system follows these steps:Calculate Distances
System calculates the distance from the starting POI to all other active destinations using the Haversine formula.
Select Top N POIs
The algorithm selects the closest N destinations (default: 5) to include in the route.
API Endpoint
POST/rutas/generar-desde-poi
Public endpoint - no authentication required
Request
Response
Implementation
TheGenerarRutaDesdePOI use case (src/application/use_cases/Rutas/generar_ruta_desde_poi.py) implements the core algorithm:
Route Generation Use Case
Distance Calculation
The Haversine formula calculates the great-circle distance between two GPS coordinates:Haversine Formula
Haversine Formula Explained
Haversine Formula Explained
The Haversine formula calculates the shortest distance over the Earth’s surface (great-circle distance):
- R: Earth’s radius (6,371 km)
- dlat, dlng: Delta latitude and longitude in radians
- a: Square of half the chord length between points
- c: Angular distance in radians
- R × c: Distance in kilometers
POI Suggestions While Building
TheSugerirPOIsProximos use case provides real-time suggestions as users build routes:
POST /rutas/sugerencias
Suggestion Algorithm
Request Example
Response Example
Algorithm Characteristics
Greedy Nearest-Neighbor
Selects the closest unvisited POI at each step - fast but may not find the globally optimal route
No Save by Default
Generated routes are ephemeral - they must be explicitly saved by the frontend
Active POIs Only
Only includes destinations where
activo = true, filtering out inactive sitesConfigurable Size
Default generates 5 additional POIs, but
cantidad parameter is configurableUse Cases
Tourist Quick Planning
Visitors can instantly generate a route from any heritage site they’re interested in:- Browse destinations on the map
- Click “Generate Route from Here” on any POI
- Review suggested nearby sites (with distances)
- Save the route or modify it manually
Admin Route Creation
Administrators can use route generation as a starting point:- Generate initial route from a central POI
- Review the auto-generated suggestions
- Add/remove POIs manually via suggestions endpoint
- Customize route name, description, and category
- Save the finalized route
Limitations
Why Not Optimal TSP?
Why Not Optimal TSP?
Computing the optimal TSP solution has O(n!) time complexity, making it impractical for real-time route generation. The nearest-neighbor heuristic provides:
- Fast execution: O(n²) complexity
- Good results: Typically within 25% of optimal
- Acceptable for tourism: Routes prioritize accessibility over absolute optimization
Best Practices
Start from Central Locations
Generate routes from well-known, centrally-located POIs for better coverage of nearby sites.
Review Before Saving
Always review auto-generated routes - the algorithm doesn’t consider factors like opening hours, accessibility, or thematic coherence.
Combine with Manual Curation
Use generation as a starting point, then manually adjust based on cultural/historical themes.
Related Features
- Tourist Routes - Manual route creation and management
- Destinations - POI data used by the generation algorithm
- API Reference - Complete API documentation