@@ -27,6 +27,7 @@ the License, or (at your option) any later version.
2727import org .opentripplanner .routing .core .FareRuleSet ;
2828import org .opentripplanner .routing .core .State ;
2929import org .opentripplanner .routing .edgetype .HopEdge ;
30+ import org .opentripplanner .routing .edgetype .TransitBoardAlight ;
3031import org .opentripplanner .routing .graph .Edge ;
3132import org .opentripplanner .routing .spt .GraphPath ;
3233import 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