Skip to content

Commit

Permalink
Merge pull request #270 from HSLdevcom/multi-exception-routes
Browse files Browse the repository at this point in the history
Multi exception routes
  • Loading branch information
vesameskanen authored Nov 14, 2018
2 parents 9dadd50 + ad10ab7 commit a689222
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ the License, or (at your option) any later version.
import org.opentripplanner.routing.core.FareRuleSet;
import org.opentripplanner.routing.core.State;
import org.opentripplanner.routing.edgetype.HopEdge;
import org.opentripplanner.routing.edgetype.TransitBoardAlight;
import org.opentripplanner.routing.graph.Edge;
import org.opentripplanner.routing.spt.GraphPath;
import org.opentripplanner.routing.impl.DefaultFareServiceImpl;
Expand All @@ -50,10 +51,13 @@ protected List<Ride> createRides(GraphPath path) {
boolean newRide = true;
for (State state : path.states) {
Edge edge = state.getBackEdge();
if (!(edge instanceof HopEdge)) {
if (edge instanceof TransitBoardAlight) {
newRide = true;
continue;
}
if (!(edge instanceof HopEdge)) {
continue;
}
HopEdge hEdge = (HopEdge) edge;
if (newRide == true) {
ride = new Ride();
Expand Down Expand Up @@ -101,13 +105,22 @@ protected FareAndId getBestFareAndId(FareType fareType, List<Ride> rides, Collec

/* HSL specific logig: all exception routes start and end from the defined zone set,
but visit temporarily (maybe 1 stop only) an 'external' zone */
float bestSpecialFare = Float.POSITIVE_INFINITY;
Set<String> ruleZones = null;
for (FareRuleSet ruleSet : fareRules) {
if(ruleSet.getRoutes().contains(ride.route) &&
ruleSet.getContains().contains(ride.startZone) &&
ruleSet.getContains().contains(ride.endZone)) {
ruleZones = ruleSet.getContains();
break;
// check validity of this special rule and that it is the cheapest applicable one
FareAttribute attribute = ruleSet.getFareAttribute();
if (!attribute.isTransferDurationSet() ||
lastRideStartTime - startTime < attribute.getTransferDuration()) {
float newFare = getFarePrice(attribute, fareType);
if (newFare < bestSpecialFare) {
bestSpecialFare = newFare;
ruleZones = ruleSet.getContains();
}
}
}
}
if (ruleZones != null) { // the special case
Expand Down

0 comments on commit a689222

Please sign in to comment.