Skip to content

Commit a689222

Browse files
authored
Merge pull request #270 from HSLdevcom/multi-exception-routes
Multi exception routes
2 parents 9dadd50 + ad10ab7 commit a689222

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/main/java/org/opentripplanner/routing/impl/HSLFareServiceImpl.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ the License, or (at your option) any later version.
2727
import org.opentripplanner.routing.core.FareRuleSet;
2828
import org.opentripplanner.routing.core.State;
2929
import org.opentripplanner.routing.edgetype.HopEdge;
30+
import org.opentripplanner.routing.edgetype.TransitBoardAlight;
3031
import org.opentripplanner.routing.graph.Edge;
3132
import org.opentripplanner.routing.spt.GraphPath;
3233
import org.opentripplanner.routing.impl.DefaultFareServiceImpl;
@@ -50,10 +51,13 @@ protected List<Ride> createRides(GraphPath path) {
5051
boolean newRide = true;
5152
for (State state : path.states) {
5253
Edge edge = state.getBackEdge();
53-
if (!(edge instanceof HopEdge)) {
54+
if (edge instanceof TransitBoardAlight) {
5455
newRide = true;
5556
continue;
5657
}
58+
if (!(edge instanceof HopEdge)) {
59+
continue;
60+
}
5761
HopEdge hEdge = (HopEdge) edge;
5862
if (newRide == true) {
5963
ride = new Ride();
@@ -101,13 +105,22 @@ protected FareAndId getBestFareAndId(FareType fareType, List<Ride> rides, Collec
101105

102106
/* HSL specific logig: all exception routes start and end from the defined zone set,
103107
but visit temporarily (maybe 1 stop only) an 'external' zone */
108+
float bestSpecialFare = Float.POSITIVE_INFINITY;
104109
Set<String> ruleZones = null;
105110
for (FareRuleSet ruleSet : fareRules) {
106111
if(ruleSet.getRoutes().contains(ride.route) &&
107112
ruleSet.getContains().contains(ride.startZone) &&
108113
ruleSet.getContains().contains(ride.endZone)) {
109-
ruleZones = ruleSet.getContains();
110-
break;
114+
// check validity of this special rule and that it is the cheapest applicable one
115+
FareAttribute attribute = ruleSet.getFareAttribute();
116+
if (!attribute.isTransferDurationSet() ||
117+
lastRideStartTime - startTime < attribute.getTransferDuration()) {
118+
float newFare = getFarePrice(attribute, fareType);
119+
if (newFare < bestSpecialFare) {
120+
bestSpecialFare = newFare;
121+
ruleZones = ruleSet.getContains();
122+
}
123+
}
111124
}
112125
}
113126
if (ruleZones != null) { // the special case

0 commit comments

Comments
 (0)