minotor
Version:
A lightweight client-side transit routing library.
99 lines (98 loc) • 4.11 kB
TypeScript
import { StopId } from '../stops/stops.js';
import { Time } from '../timetable/time.js';
import { Timetable } from '../timetable/timetable.js';
import { QueryOptions } from './query.js';
import { RoutingEdge } from './state.js';
/**
* Common interface for all variants of RAPTOR routing.
*/
export interface IRaptorState {
/** Origin stop IDs for this run. */
readonly origins: StopId[];
/** Per-round routing graph; `graph[round][stop]` is the best edge used to reach `stop`. */
readonly graph: (RoutingEdge | undefined)[][];
/** Per-run earliest arrival at a stop. Used for boarding decisions. */
arrivalTime(stop: StopId): Time;
/**
* Tightest known upper bound on the arrival time at `stop` in `round`.
*/
improvementBound(round: number, stop: StopId): Time;
/**
* Best known arrival time at any destination.
*/
readonly destinationBest: Time;
/** Latest arrival time allowed by the current query/run. */
readonly maxArrivalTime: Time;
/** Returns `true` if `stop` is one of the query's destination stops. */
isDestination(stop: StopId): boolean;
/**
* Records a new arrival at `stop`, updating all relevant state.
*
* In Range RAPTOR mode this also updates the cross-run shared labels.
*/
updateArrival(stop: StopId, time: Time, round: number): void;
/**
* Propagates labels from round `k-1` into round `k` before routes are scanned.
* No-op in standard RAPTOR mode.
*/
initRound(round: number): void;
}
/**
* Encapsulates the core RAPTOR algorithm, operating on a {@link Timetable} and
* an {@link IRaptorState} provided by the caller.
*
* @see https://www.microsoft.com/en-us/research/wp-content/uploads/2012/01/raptor_alenex.pdf
*/
export declare class Raptor {
private readonly timetable;
constructor(timetable: Timetable);
run(options: QueryOptions, state: IRaptorState): void;
/**
* Finds trip continuations for the given marked stops and edges at the current round.
* @param markedStops The set of marked stops.
* @param edgesAtCurrentRound The array of edges at the current round, indexed by stop ID.
* @returns An array of trip continuations.
*/
private findTripContinuations;
/**
* Scans a route for an in-seat trip continuation.
*
* The boarded trip and entry stop are fixed, so there is no need to probe for
* earlier boardings.
*
* @param route The route to scan
* @param hopOnStopIndex The stop index where the continuation begins
* @param round The current RAPTOR round
* @param routingState Current routing state
* @param tripContinuation The in-seat continuation descriptor
* @param shared Optional shared state for Range RAPTOR mode
*/
private scanRouteContinuation;
/**
* Scans a route using the standard RAPTOR boarding logic.
*
* Iterates through all stops from the hop-on point, maintaining the current
* best trip and improving arrival times when possible. At each marked stop it
* also checks whether an earlier (or first) trip can be boarded, upgrading the
* active trip when one is found.
*
* @param route The route to scan
* @param hopOnStopIndex The stop index where passengers can first board
* @param round The current RAPTOR round
* @param state Current routing state
* @param options Query options (minTransferTime, etc.)
*/
private scanRoute;
/**
* Processes all currently marked stops to find available transfers
* and determines if using these transfers would result in earlier arrival times
* at destination stops. It handles different transfer types including in-seat
* transfers and walking transfers with appropriate minimum transfer times.
*
* @param options Query options (minTransferTime, etc.)
* @param round The current round number in the RAPTOR algorithm
* @param markedStops The set of currently marked stops
* @param state Current routing state
*/
private considerTransfers;
}