@@ -27,6 +27,7 @@ the License, or (at your option) any later version.
27
27
import org .opentripplanner .routing .core .FareRuleSet ;
28
28
import org .opentripplanner .routing .core .State ;
29
29
import org .opentripplanner .routing .edgetype .HopEdge ;
30
+ import org .opentripplanner .routing .edgetype .TransitBoardAlight ;
30
31
import org .opentripplanner .routing .graph .Edge ;
31
32
import org .opentripplanner .routing .spt .GraphPath ;
32
33
import org .opentripplanner .routing .impl .DefaultFareServiceImpl ;
@@ -50,10 +51,13 @@ protected List<Ride> createRides(GraphPath path) {
50
51
boolean newRide = true ;
51
52
for (State state : path .states ) {
52
53
Edge edge = state .getBackEdge ();
53
- if (!( edge instanceof HopEdge ) ) {
54
+ if (edge instanceof TransitBoardAlight ) {
54
55
newRide = true ;
55
56
continue ;
56
57
}
58
+ if (!(edge instanceof HopEdge )) {
59
+ continue ;
60
+ }
57
61
HopEdge hEdge = (HopEdge ) edge ;
58
62
if (newRide == true ) {
59
63
ride = new Ride ();
@@ -101,13 +105,22 @@ protected FareAndId getBestFareAndId(FareType fareType, List<Ride> rides, Collec
101
105
102
106
/* HSL specific logig: all exception routes start and end from the defined zone set,
103
107
but visit temporarily (maybe 1 stop only) an 'external' zone */
108
+ float bestSpecialFare = Float .POSITIVE_INFINITY ;
104
109
Set <String > ruleZones = null ;
105
110
for (FareRuleSet ruleSet : fareRules ) {
106
111
if (ruleSet .getRoutes ().contains (ride .route ) &&
107
112
ruleSet .getContains ().contains (ride .startZone ) &&
108
113
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
+ }
111
124
}
112
125
}
113
126
if (ruleZones != null ) { // the special case
0 commit comments