UNPKG

raptor-journey-planner

Version:

Implementation of the Round bAsed Public Transit Optimized Router (Raptor) journey planning algorithm.

40 lines (39 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RangeQuery = void 0; const GroupStationDepartAfterQuery_1 = require("./GroupStationDepartAfterQuery"); /** * Use the Raptor algorithm to generate a full day of results. */ class RangeQuery { raptor; resultsFactory; maxSearchDays; filters; ONE_DAY = 24 * 60 * 60; groupQuery; constructor(raptor, resultsFactory, maxSearchDays = 3, filters = []) { this.raptor = raptor; this.resultsFactory = resultsFactory; this.maxSearchDays = maxSearchDays; this.filters = filters; this.groupQuery = new GroupStationDepartAfterQuery_1.GroupStationDepartAfterQuery(raptor, resultsFactory, maxSearchDays); } /** * Perform a query at midnight, and then continue to search one minute after the earliest departure of each set of * results. */ plan(origin, destination, date, time = 1, endTime = this.ONE_DAY) { const results = []; while (time < endTime) { const newResults = this.groupQuery.plan([origin], [destination], date, time); results.push(...newResults); if (newResults.length === 0) { break; } time = Math.min(...newResults.map(j => j.departureTime)) + 1; } return this.filters.reduce((rs, filter) => filter.apply(rs), results); } } exports.RangeQuery = RangeQuery;