Skip to content

Agent Directive: Dijkstra Routing Engine Implementation

Objective

Implement a spatial route optimisation algorithm in the ERO Cloudflare Worker. The engine must evaluate a user's highlighted schedule, identify overlapping set times (clashes), and calculate the optimal walking path using the established spatial matrix.

Execution Sequence

1. Implement the Algorithm Core

  • Navigate to api/src/utils/. Create a file named optimiser.ts.
  • Import the FESTIVAL_EDGES matrix from distanceMatrix.ts.
  • Implement a scheduling algorithm (based on Dijkstra's shortest path / weighted interval scheduling) that accepts an array of a user's chosen bands (with start/end times and stage IDs).
  • The algorithm must calculate the travel time between consecutive acts. If a clash exists, the algorithm must penalize the overlap and suggest an exact departure time to minimize missed music.

2. Create the Route Generation Endpoint

  • Modify api/src/index.ts.

  • Create a new route: GET /api/route/:username.

  • Logic: 1. Fetch the user's highlighted bands from the D1 database. 2. Pass the schedule into the optimiser.ts engine. 3. Return a JSON response formatted as a strict itinerary payload (e.g., "Act -> Transit -> Act").

    Example Output Schema:

    json
    {
      "username": "pedroneil",
      "itinerary": [
        { "type": "act", "band": "Concrete Age", "stage": "New Blood Stage", "startTime": 1786017600000, "endTime": 1786019400000 },
        { "type": "transit", "instruction": "Walk to Main Stage", "durationMinutes": 8 },
        { "type": "act", "band": "Lamb of God", "stage": "Main Stage", "startTime": 1786020000000, "endTime": 1786023600000 }
      ]
    }