Overview
MND’s routing algorithm combines 4 distinct strategies to find the best path from origin to destination. The system balances three key factors:Total Time
Minimize journey duration including wait time
Cost
Prefer free bus routes over paid local transport
Convenience
Reduce transfers and walking distance
The 4 Routing Strategies
The algorithm runs all 4 strategies in parallel, then selects the top 2-3 options to present to the user.
Strategy 1: Direct Bus Route
- Overview
- Algorithm
- Example
Strategy 2: Bus + Local Hybrid
- Overview
- Algorithm
- Example
Strategy 3: Bus Transfers
- Overview
- Algorithm
- Example
Connect multiple bus routes by transferring at common stops.
Transfer Points
Key hubs where multiple routes intersect:- AMBARKHANA - 5 routes converge
- SUBIDBAZAR - 6 routes pass through
- CHOWHATTA - 4 routes intersect
Constraints
- ⏱️ Wait time ≤ 15 minutes at transfer point
- 🚶 No walking between stops (same location)
- 📅 Next bus must arrive after previous bus
Strategy 4: Local Transport Only
- Overview
- Algorithm
- Example
Fallback option when buses are unavailable or inconvenient.
Use Cases
- 🕐 Late night (no buses running)
- 🚫 No bus route serves the origin/destination
- ⚡ Urgent trip (can’t wait for next bus)
Transport Options
- CNG (auto-rickshaw): 20-50 BDT, moderate speed
- Rickshaw: 10-30 BDT, slower
- Walking: Free, very slow
Route Comparison & Ranking
After running all 4 strategies, the system compares routes and selects the best options:Ranking Criteria
Comparison Function
MND-backend/src/core/planner.ts:412-462
Performance Optimizations
Distance Matrix Caching
Distance Matrix Caching
Google Maps API calls are expensive (₹0.50 per request). MND caches results:Cache Duration: 7 days
Parallel Strategy Execution
Parallel Strategy Execution
All 4 strategies run concurrently using async/await:Performance: Reduces response time by ~40%
Early Termination
Early Termination
Stop searching once optimal routes are found:
- If direct bus exists, skip expensive transfer searches
- Limit transfer wait time to ≤ 15 minutes
- Reject routes with totalTimeMin > 2 hours
Adjacency List Pre-computation
Adjacency List Pre-computation
Graph edges are pre-computed into an adjacency list on server startup:Speedup: 10x faster for Dijkstra’s algorithm
Real-World Example
Let’s trace a complete route planning request:- Request
- Strategy Results
- Final Response
- 📍 Origin: TILAGOR (residential area)
- 📍 Destination: LAKKATURA (residential area)
- ⏰ Time: 08:20 (morning commute)
Next Steps
Graph Model
Explore the 19 nodes and 289 edges
Transport Modes
Learn about buses, CNGs, and walking
API Reference
Try the routing API yourself
Architecture
Understand the full system design