Skip to content

Commit

Permalink
Subtract generalized cost that was previously added
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jan 30, 2024
1 parent 15c17c4 commit ae98a28
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/main/java/org/opentripplanner/model/plan/Itinerary.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public void setElevationGained(Double elevationGained) {

/**
* If a generalized cost is used in the routing algorithm, this should be the total cost computed
* by the algorithm. This is relevant for anyone who want to debug an search and tuning the
* by the algorithm. This is relevant for anyone who want to debug a search and tuning the
* system. The unit should be equivalent to the cost of "one second of transit".
* <p>
* -1 indicate that the cost is not set/computed.
Expand All @@ -498,6 +498,10 @@ public int getGeneralizedCost() {
return generalizedCost;
}

public int getGeneralizedCostIncludingPenalty() {
return generalizedCost - penaltyCost(accessPenalty) - penaltyCost(egressPenalty);
}

public void setGeneralizedCost(int generalizedCost) {
this.generalizedCost = generalizedCost;
}
Expand Down Expand Up @@ -663,4 +667,12 @@ public void setEmissionsPerPerson(Emissions emissionsPerPerson) {
public Emissions getEmissionsPerPerson() {
return this.emissionsPerPerson;
}

private static int penaltyCost(TimeAndCost penalty) {
if (penalty == null) {
return 0;
} else {
return penalty.cost().toSeconds();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public List<Itinerary> flagForRemoval(List<Itinerary> itineraries) {
// ALL itineraries are considered here. Both transit and non-transit
OptionalInt minGeneralizedCost = itineraries
.stream()
.mapToInt(Itinerary::getGeneralizedCost)
.mapToInt(Itinerary::getGeneralizedCostIncludingPenalty)
.min();

if (minGeneralizedCost.isEmpty()) {
Expand All @@ -58,7 +58,7 @@ public List<Itinerary> flagForRemoval(List<Itinerary> itineraries) {

return itineraries
.stream()
.filter(it -> !it.hasTransit() && it.getGeneralizedCost() > maxLimit)
.filter(it -> !it.hasTransit() && it.getGeneralizedCostIncludingPenalty() > maxLimit)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public List<Itinerary> flagForRemoval(List<Itinerary> itineraries) {
OptionalInt minStreetCost = itineraries
.stream()
.filter(Itinerary::isOnStreetAllTheWay)
.mapToInt(Itinerary::getGeneralizedCost)
.mapToInt(Itinerary::getGeneralizedCostIncludingPenalty)
.min();

if (minStreetCost.isEmpty()) {
Expand All @@ -52,7 +52,7 @@ public List<Itinerary> flagForRemoval(List<Itinerary> itineraries) {
// Filter away itineraries that have higher cost than limit cost computed above
return itineraries
.stream()
.filter(it -> !it.isOnStreetAllTheWay() && it.getGeneralizedCost() >= limit)
.filter(it -> !it.isOnStreetAllTheWay() && it.getGeneralizedCostIncludingPenalty() >= limit)
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public List<Itinerary> flagForRemoval(List<Itinerary> itineraries) {

return itineraries
.stream()
.filter(it -> !it.isOnStreetAllTheWay() && it.getGeneralizedCost() >= limit)
.filter(it -> !it.isOnStreetAllTheWay() && it.getGeneralizedCostIncludingPenalty() >= limit)
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ else if (pathLeg.isTransferLeg()) {
}

if (egressPathLeg.egress() instanceof DefaultAccessEgress ae) {
itinerary.setAccessPenalty(ae.penalty());
itinerary.setEgressPenalty(ae.penalty());
}
if (path.isC2Set()) {
itinerary.setGeneralizedCost2(path.c2());
Expand Down

0 comments on commit ae98a28

Please sign in to comment.