Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ihfaz297/MND/llms.txt

Use this file to discover all available pages before exploring further.

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

Find a single bus that serves both origin and destination stops, with no transfers required.

Advantages

  • Zero cost (free university buses)
  • No transfers (simplest route)
  • Predictable schedule

Example

TILAGOR → [Bus 1 @ 08:25] → CAMPUS
Time: 45 minutes | Cost: 0 BDT | Transfers: 0

Strategy 2: Bus + Local Hybrid

Take a bus as far as possible, then use local transport (CNG/rickshaw) for the final segment.

When to Use

  • ✅ Destination not directly served by bus
  • ✅ Reduces wait time (get off earlier, take local)
  • ✅ Balances cost and speed

Example

NAIORPUL → [Bus 3 @ 08:30] → SUBIDBAZAR → [CNG] → HOSPITAL
Time: 35 minutes | Cost: 40 BDT | Transfers: 1

Strategy 3: Bus Transfers

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

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

1

Deduplication

Remove duplicate routes (same stops, mode, and timing)
2

Find Fastest

Route with minimum totalTimeMin (including wait time)
3

Find Least Local

Route with minimum localTimeMin (paid transport time)
4

Add Alternatives

Include 1-2 additional routes if available (max 3 total)

Comparison Function

private compareRoutes(options: RouteOption[]): RouteOption[] {
    if (options.length === 0) return [];
    
    // Remove duplicates
    const unique = this.deduplicateOptions(options);
    
    // Find fastest
    let fastest = unique[0];
    for (const option of unique) {
        if (option.totalTimeMin < fastest.totalTimeMin) {
            fastest = option;
        }
    }
    
    // Find least local
    let leastLocal = unique[0];
    for (const option of unique) {
        if (option.localTimeMin < leastLocal.localTimeMin) {
            leastLocal = option;
        }
    }
    
    // Mark categories
    fastest.category = 'fastest';
    fastest.label = 'Fastest Route';
    
    leastLocal.category = 'least_local';
    leastLocal.label = 'Least Local Transport';
    
    // Return top options (avoid duplicates)
    const result: RouteOption[] = [fastest];
    if (this.getOptionId(leastLocal) !== this.getOptionId(fastest)) {
        result.push(leastLocal);
    }
    
    return result;
}
Source: MND-backend/src/core/planner.ts:412-462

Performance Optimizations

Google Maps API calls are expensive (₹0.50 per request). MND caches results:
// Cache entry structure
interface CacheEntry {
    distanceMeters: number;
    durationSeconds: number;
    timestamp: number; // Unix timestamp
}

// Cache lookup
const cacheKey = `${from}-${to}-${mode}`;
const cached = this.cache.get(cacheKey);

if (cached && (Date.now() - cached.timestamp) < 7 * 24 * 60 * 60 * 1000) {
    return { ok: true, ...cached, fromCache: true };
}
Cache Duration: 7 days
All 4 strategies run concurrently using async/await:
const options: RouteOption[] = [];

// Execute strategies in parallel
for (const route of allRoutes) {
    const [directOption, hybridOption] = await Promise.all([
        this.directBusRoute(route, from, to, requestTime),
        this.busToLocalRoute(route, from, to, requestTime)
    ]);
    
    if (directOption) options.push(directOption);
    if (hybridOption) options.push(hybridOption);
}
Performance: Reduces response time by ~40%
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
Graph edges are pre-computed into an adjacency list on server startup:
// Before: O(E) lookup for each neighbor query
edges.filter(edge => edge.from === nodeId)

// After: O(1) lookup
adjacencyList[nodeId] // → [edge1, edge2, ...]
Speedup: 10x faster for Dijkstra’s algorithm

Real-World Example

Let’s trace a complete route planning request:
GET /api/routes?from=TILAGOR&to=LAKKATURA&time=08:20
Scenario:
  • 📍 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

Build docs developers (and LLMs) love