Skip to content

Commit

Permalink
FIX: 145 - Make sure only pareto optimal solutions are returned for r…
Browse files Browse the repository at this point in the history
…ange raptor.
  • Loading branch information
clukas1 committed Nov 5, 2024
1 parent d3895b1 commit 48fb7c3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/ch/naviqore/raptor/router/LabelPostprocessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ List<Connection> reconstructParetoOptimalSolutions(List<QueryState.Label[]> best
Map<Integer, Integer> targetStops, LocalDate referenceDate) {
final List<Connection> connections = new ArrayList<>();

// this additional tracking variable is needed to filter out non pareto optimal connections from range raptor,
// as the pareto optimal solution for a later departure might have actually been fastest with more rounds where
// the final best solution has fewer rounds and is faster
int overallBestTime = timeType == TimeType.DEPARTURE ? INFINITY : -INFINITY;

// iterate over all rounds
for (QueryState.Label[] labels : bestLabelsPerRound) {

Expand All @@ -86,15 +91,17 @@ List<Connection> reconstructParetoOptimalSolutions(List<QueryState.Label[]> best

if (timeType == TimeType.DEPARTURE) {
int actualArrivalTime = currentLabel.targetTime() + targetStopWalkingTime;
if (actualArrivalTime < bestTime) {
if (actualArrivalTime < bestTime && actualArrivalTime < overallBestTime) {
label = currentLabel;
bestTime = actualArrivalTime;
overallBestTime = actualArrivalTime;
}
} else {
int actualDepartureTime = currentLabel.targetTime() - targetStopWalkingTime;
if (actualDepartureTime > bestTime) {
if (actualDepartureTime > bestTime && actualDepartureTime > overallBestTime) {
label = currentLabel;
bestTime = actualDepartureTime;
overallBestTime = actualDepartureTime;
}
}
}
Expand Down

0 comments on commit 48fb7c3

Please sign in to comment.