From 8b57862f1ee6af504c968af9455c45d28f4dd80a Mon Sep 17 00:00:00 2001 From: Lukas Connolly Date: Wed, 5 Feb 2025 22:09:28 +0100 Subject: [PATCH] ENH: #181 - Allow delayed initial transfer relaxation in round 1 when doInitialTransferRelaxation (round 0) is false. --- .../naviqore/raptor/router/FootpathRelaxer.java | 7 ++++++- .../java/ch/naviqore/raptor/router/Query.java | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/naviqore/raptor/router/FootpathRelaxer.java b/src/main/java/ch/naviqore/raptor/router/FootpathRelaxer.java index 58b9b27d..add7e5a7 100644 --- a/src/main/java/ch/naviqore/raptor/router/FootpathRelaxer.java +++ b/src/main/java/ch/naviqore/raptor/router/FootpathRelaxer.java @@ -81,6 +81,11 @@ private void expandFootpathsFromStop(int stopIdx, int round) { Stop sourceStop = stops[stopIdx]; QueryState.Label previousLabel = queryState.getLabel(round, stopIdx); + // handle case where initial transfer relaxation was not performed + if( round == 1 && previousLabel == null ){ + previousLabel = queryState.getLabel(0, stopIdx); + } + // do not relax footpath from stop that was only reached by footpath in the same round if (previousLabel == null || previousLabel.type() == QueryState.LabelType.TRANSFER) { return; @@ -116,7 +121,7 @@ private void expandFootpathsFromStop(int stopIdx, int round) { queryState.setBestTime(transfer.targetStopIdx(), comparableTargetTime); // add real target time to label QueryState.Label label = new QueryState.Label(sourceTime, targetTime, QueryState.LabelType.TRANSFER, i, - NO_INDEX, transfer.targetStopIdx(), queryState.getLabel(round, stopIdx)); + NO_INDEX, transfer.targetStopIdx(), previousLabel); queryState.setLabel(round, transfer.targetStopIdx(), label); queryState.mark(transfer.targetStopIdx()); } diff --git a/src/main/java/ch/naviqore/raptor/router/Query.java b/src/main/java/ch/naviqore/raptor/router/Query.java index 73ec878c..6a9fec7b 100644 --- a/src/main/java/ch/naviqore/raptor/router/Query.java +++ b/src/main/java/ch/naviqore/raptor/router/Query.java @@ -75,7 +75,8 @@ class Query { // set up footpath relaxer and route scanner and inject stop labels and times footpathRelaxer = new FootpathRelaxer(queryState, raptorData, config.getMinimumTransferDuration(), - config.getMaximumWalkingDuration(), timeType); + config.getMaximumWalkingDuration(), timeType, config.isAllowSourceTransfer(), + config.isAllowTargetTransfer(), config.isAllowConsecutiveTransfers(), targetStopIndices); routeScanner = new RouteScanner(queryState, raptorData, config, timeType, referenceDate, raptorConfig.getDaysToScan()); } @@ -173,6 +174,16 @@ private void doRounds() { // scan all routs and mark stops that have improved routeScanner.scan(queryState.getRound()); + // this is a special case where no initial transfer relaxation was done, to ensure that transfers from + // source stops are still accounted for these are manually marked in round 1 (after route scanning for + // performance reasons) + if( !config.isDoInitialTransferRelaxation() && queryState.getRound() == 1 ){ + // mark all source stops for transfer relaxation after round 1 + for (int sourceStopIndex : sourceStopIndices) { + queryState.mark(sourceStopIndex); + } + } + // relax footpaths for all newly marked stops footpathRelaxer.relax(queryState.getRound()); @@ -269,6 +280,9 @@ void removeSuboptimalLabelsForRound(int round) { queryState.setLabel(round, stopIdx, null); queryState.unmark(stopIdx); } + } else { + // if label is null there is no reason to mark the stop! + queryState.unmark(stopIdx); } } }