Skip to content

Commit

Permalink
ENH: #181 - Allow delayed initial transfer relaxation in round 1 when…
Browse files Browse the repository at this point in the history
… doInitialTransferRelaxation (round 0) is false.
  • Loading branch information
clukas1 committed Feb 5, 2025
1 parent a6ff697 commit 8b57862
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/main/java/ch/naviqore/raptor/router/FootpathRelaxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/ch/naviqore/raptor/router/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 8b57862

Please sign in to comment.