Skip to content

Commit

Permalink
REFACTOR: 145 - Remove duplicate bestTime variable in reconstructPare…
Browse files Browse the repository at this point in the history
…toOptimalSolutions.
  • Loading branch information
clukas1 committed Nov 5, 2024
1 parent 48fb7c3 commit 23a2265
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/main/java/ch/naviqore/raptor/router/LabelPostprocessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,12 @@ 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;
int bestTime = timeType == TimeType.DEPARTURE ? INFINITY : -INFINITY;

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

QueryState.Label label = null;
int bestTime = timeType == TimeType.DEPARTURE ? INFINITY : -INFINITY;

for (Map.Entry<Integer, Integer> entry : targetStops.entrySet()) {
int targetStopIdx = entry.getKey();
Expand All @@ -91,17 +87,15 @@ List<Connection> reconstructParetoOptimalSolutions(List<QueryState.Label[]> best

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

0 comments on commit 23a2265

Please sign in to comment.