Skip to content

Commit df1a0a7

Browse files
committed
Implement flex reluctance and change where flex boardCost is added.
1 parent bb67e86 commit df1a0a7

24 files changed

Lines changed: 152 additions & 105 deletions

File tree

application/src/ext-test/java/org/opentripplanner/ext/flex/FlexIntegrationTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,38 @@
4343
*/
4444
public class FlexIntegrationTest {
4545

46+
private static final FlexParameters FLEX_PARAMETERS = new FlexParameters() {
47+
@Override
48+
public Duration maxTransferDuration() {
49+
return FlexParameters.defaultValues().maxTransferDuration();
50+
}
51+
52+
@Override
53+
public Duration maxFlexTripDuration() {
54+
return FlexParameters.defaultValues().maxFlexTripDuration();
55+
}
56+
57+
@Override
58+
public Duration maxAccessWalkDuration() {
59+
return FlexParameters.defaultValues().maxAccessWalkDuration();
60+
}
61+
62+
@Override
63+
public Duration maxEgressWalkDuration() {
64+
return FlexParameters.defaultValues().maxEgressWalkDuration();
65+
}
66+
67+
@Override
68+
public int boardCost() {
69+
return 600;
70+
}
71+
72+
@Override
73+
public double reluctance() {
74+
return 1.0;
75+
}
76+
};
77+
4678
public static final GenericLocation OUTSIDE_FLEX_ZONE = GenericLocation.fromCoordinate(
4779
33.7552,
4880
-84.4631
@@ -84,7 +116,10 @@ static void setup() {
84116
graph,
85117
timetableRepository,
86118
transferRepository,
87-
model.fareServiceFactory().makeFareService()
119+
model.fareServiceFactory().makeFareService(),
120+
null,
121+
null,
122+
FLEX_PARAMETERS
88123
).routingService();
89124
}
90125

application/src/ext-test/java/org/opentripplanner/ext/flex/FlexibleTransitLegTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class FlexibleTransitLegTest implements PlanTestConstants {
3232
1,
3333
2,
3434
LocalDate.of(2025, 1, 15),
35-
new FlexPath(1000, 600, () -> GeometryUtils.makeLineString(1, 1, 2, 2))
35+
new FlexPath(1000, 600, () -> GeometryUtils.makeLineString(1, 1, 2, 2)),
36+
FlexParameters.defaultValues()
3637
);
3738
private static final TransitAlert ALERT = TransitAlert.of(id("alert"))
3839
.withHeaderText(I18NString.of("alert 1"))

application/src/ext-test/java/org/opentripplanner/ext/flex/template/FlexTemplateFactoryTest.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.junit.jupiter.api.Test;
2020
import org.locationtech.jts.geom.Coordinate;
2121
import org.opentripplanner.core.model.i18n.I18NString;
22+
import org.opentripplanner.ext.flex.FlexParameters;
2223
import org.opentripplanner.ext.flex.flexpathcalculator.FlexPathCalculator;
2324
import org.opentripplanner.ext.flex.flexpathcalculator.ScheduledFlexPathCalculator;
2425
import org.opentripplanner.ext.flex.flexpathcalculator.StreetFlexPathCalculator;
@@ -40,11 +41,6 @@ class FlexTemplateFactoryTest {
4041

4142
private static final TimetableRepositoryForTest MODEL = TimetableRepositoryForTest.of();
4243

43-
/**
44-
* This is pass-through information
45-
*/
46-
private static final Duration MAX_TRANSFER_DURATION = Duration.ofMinutes(10);
47-
4844
/**
4945
* Any calculator will do. The only thing we will test here is that a new scheduled calculator
5046
* is created for scheduled-flex-trips.
@@ -94,7 +90,7 @@ void testCreateAccessTemplateForUnscheduledTripWithTwoStopsAndNoBoardRestriction
9490
stopTime(2, STOP_B, BOARD_AND_ALIGHT, T_10_10)
9591
);
9692

97-
var factory = FlexTemplateFactory.of(CALCULATOR, MAX_TRANSFER_DURATION);
93+
var factory = FlexTemplateFactory.of(CALCULATOR, FlexParameters.defaultValues());
9894

9995
// Create template with access boarding at stop A
10096
var subject = factory.createAccessTemplates(closestTrip(flexTrip, STOP_A, 0));
@@ -126,7 +122,7 @@ void testCreateEgressTemplateForUnscheduledTripWithTwoStopsAndNoBoardRestriction
126122
stopTime(2, STOP_B, BOARD_AND_ALIGHT, T_10_10)
127123
);
128124

129-
var factory = FlexTemplateFactory.of(CALCULATOR, MAX_TRANSFER_DURATION);
125+
var factory = FlexTemplateFactory.of(CALCULATOR, FlexParameters.defaultValues());
130126

131127
// Create template with egress alighting at stop B
132128
var subject = factory.createEgressTemplates(closestTrip(flexTrip, STOP_B, 1));
@@ -160,7 +156,7 @@ void testCreateAccessTemplateForUnscheduledTripWithBoardAndAlightRestrictions()
160156
stopTime(4, STOP_D, ALIGHT_ONLY, T_10_30)
161157
);
162158

163-
var factory = FlexTemplateFactory.of(CALCULATOR, MAX_TRANSFER_DURATION);
159+
var factory = FlexTemplateFactory.of(CALCULATOR, FlexParameters.defaultValues());
164160

165161
// Create template with boarding at stop A
166162
var subject = factory.createAccessTemplates(closestTrip(flexTrip, STOP_A, 0));
@@ -201,7 +197,7 @@ void testCreateEgressTemplateForUnscheduledTripWithBoardAndAlightRestrictions()
201197
stopTime(4, STOP_D, ALIGHT_ONLY, T_10_30)
202198
);
203199

204-
var factory = FlexTemplateFactory.of(CALCULATOR, MAX_TRANSFER_DURATION);
200+
var factory = FlexTemplateFactory.of(CALCULATOR, FlexParameters.defaultValues());
205201

206202
// Create template with boarding at stop A
207203
var subject = factory.createEgressTemplates(closestTrip(flexTrip, STOP_D, 3));
@@ -241,7 +237,7 @@ void testCreateAccessTemplateForUnscheduledTripWithTwoGroupsStops() {
241237
stopTime(2, GROUP_STOP_34, ALIGHT_ONLY, T_10_20)
242238
);
243239

244-
var factory = FlexTemplateFactory.of(CALCULATOR, MAX_TRANSFER_DURATION);
240+
var factory = FlexTemplateFactory.of(CALCULATOR, FlexParameters.defaultValues());
245241

246242
// Create template with access boarding at stop A
247243
var subject = factory.createAccessTemplates(closestTrip(flexTrip, STOP_G1, 0));
@@ -264,7 +260,7 @@ void testCreateEgressTemplateForUnscheduledTripWithTwoGroupsStops() {
264260
stopTime(2, GROUP_STOP_34, ALIGHT_ONLY, T_10_20)
265261
);
266262

267-
var factory = FlexTemplateFactory.of(CALCULATOR, MAX_TRANSFER_DURATION);
263+
var factory = FlexTemplateFactory.of(CALCULATOR, FlexParameters.defaultValues());
268264

269265
// Create template with access boarding at stop A
270266
var subject = factory.createEgressTemplates(closestTrip(flexTrip, STOP_G4, 1));
@@ -288,7 +284,7 @@ void testCreateAccessTemplateForScheduledDeviatedTrip() {
288284
stopTime(10, STOP_C, ALIGHT_ONLY, T_10_30)
289285
);
290286

291-
var factory = FlexTemplateFactory.of(CALCULATOR, MAX_TRANSFER_DURATION);
287+
var factory = FlexTemplateFactory.of(CALCULATOR, FlexParameters.defaultValues());
292288

293289
// Create template with access boarding at stop A
294290
var subject = factory.createAccessTemplates(closestTrip(flexTrip, STOP_B, 1));
@@ -310,7 +306,7 @@ void testCreateEgressTemplateForScheduledDeviatedTrip() {
310306
stopTime(10, STOP_C, ALIGHT_ONLY, T_10_30)
311307
);
312308

313-
var factory = FlexTemplateFactory.of(CALCULATOR, MAX_TRANSFER_DURATION);
309+
var factory = FlexTemplateFactory.of(CALCULATOR, FlexParameters.defaultValues());
314310

315311
// Create template with access boarding at stop A
316312
var subject = factory.createEgressTemplates(closestTrip(flexTrip, STOP_B, 1));

application/src/ext/java/org/opentripplanner/ext/flex/FlexParameters.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public interface FlexParameters {
3131
*/
3232
int boardCost();
3333

34+
/**
35+
* See {@link org.opentripplanner.standalone.config.sandbox.FlexConfig}
36+
*/
37+
double reluctance();
38+
3439
/**
3540
* This defines the default values. This will be used by the OTP configuration and by tests,
3641
* avoid using this directly.
@@ -61,6 +66,11 @@ public Duration maxEgressWalkDuration() {
6166
public int boardCost() {
6267
return 600;
6368
}
69+
70+
@Override
71+
public double reluctance() {
72+
return 10.0;
73+
}
6474
};
6575
}
6676
}

application/src/ext/java/org/opentripplanner/ext/flex/FlexRouter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ public List<Itinerary> createFlexOnlyItineraries(boolean arriveBy, RouteRequest
137137
callbackService,
138138
accessFlexPathCalculator,
139139
egressFlexPathCalculator,
140-
flexParameters.maxTransferDuration(),
141-
matcher
140+
matcher,
141+
flexParameters
142142
).calculateDirectFlexPaths(streetAccesses, streetEgresses, dates, requestedTime, arriveBy);
143143

144144
var itineraries = new ArrayList<Itinerary>();
@@ -160,8 +160,8 @@ public Collection<FlexAccessEgress> createFlexAccesses() {
160160
return new FlexAccessFactory(
161161
callbackService,
162162
accessFlexPathCalculator,
163-
flexParameters.maxTransferDuration(),
164-
matcher
163+
matcher,
164+
flexParameters
165165
).createFlexAccesses(streetAccesses, dates);
166166
}
167167

@@ -170,8 +170,8 @@ public Collection<FlexAccessEgress> createFlexEgresses() {
170170
return new FlexEgressFactory(
171171
callbackService,
172172
egressFlexPathCalculator,
173-
flexParameters.maxTransferDuration(),
174-
matcher
173+
matcher,
174+
flexParameters
175175
).createFlexEgresses(streetEgresses, dates);
176176
}
177177

application/src/ext/java/org/opentripplanner/ext/flex/edgetype/FlexTripEdge.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.locationtech.jts.geom.LineString;
66
import org.opentripplanner.core.model.i18n.I18NString;
77
import org.opentripplanner.core.model.id.FeedScopedId;
8+
import org.opentripplanner.ext.flex.FlexParameters;
89
import org.opentripplanner.ext.flex.flexpathcalculator.FlexPath;
910
import org.opentripplanner.ext.flex.trip.FlexTrip;
1011
import org.opentripplanner.street.model.edge.Edge;
@@ -25,6 +26,7 @@ public class FlexTripEdge extends Edge {
2526
private final int alightStopPosInPattern;
2627
private final LocalDate serviceDate;
2728
private final FlexPath flexPath;
29+
private final FlexParameters flexParameters;
2830

2931
public FlexTripEdge(
3032
Vertex v1,
@@ -35,7 +37,8 @@ public FlexTripEdge(
3537
int boardStopPosInPattern,
3638
int alightStopPosInPattern,
3739
LocalDate serviceDate,
38-
FlexPath flexPath
40+
FlexPath flexPath,
41+
FlexParameters flexParameters
3942
) {
4043
super(v1, v2);
4144
this.fromStopId = fromStopId;
@@ -45,6 +48,7 @@ public FlexTripEdge(
4548
this.alightStopPosInPattern = alightStopPosInPattern;
4649
this.serviceDate = serviceDate;
4750
this.flexPath = Objects.requireNonNull(flexPath);
51+
this.flexParameters = flexParameters;
4852
}
4953

5054
public FeedScopedId fromStopId() {
@@ -94,11 +98,11 @@ public double getDistanceMeters() {
9498
public State[] traverse(State s0) {
9599
StateEditor editor = s0.edit(this);
96100
editor.setBackMode(TraverseMode.FLEX);
97-
// TODO: decide good value
98-
editor.incrementWeight(10 * 60);
99101
int timeInSeconds = getTimeInSeconds();
100102
editor.incrementTimeInSeconds(timeInSeconds);
101-
editor.incrementWeight(timeInSeconds);
103+
editor.incrementWeight(
104+
flexParameters.reluctance() * timeInSeconds + flexParameters.boardCost()
105+
);
102106
editor.resetEnteredNoThroughTrafficArea();
103107
return editor.makeStateArray();
104108
}

application/src/ext/java/org/opentripplanner/ext/flex/template/AbstractFlexTemplate.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.opentripplanner.ext.flex.template;
22

3-
import java.time.Duration;
43
import java.time.LocalDate;
54
import java.util.ArrayList;
65
import java.util.Collection;
@@ -10,6 +9,7 @@
109
import javax.annotation.Nullable;
1110
import org.opentripplanner.core.model.id.FeedScopedId;
1211
import org.opentripplanner.ext.flex.FlexAccessEgress;
12+
import org.opentripplanner.ext.flex.FlexParameters;
1313
import org.opentripplanner.ext.flex.FlexPathDurations;
1414
import org.opentripplanner.ext.flex.edgetype.FlexTripEdge;
1515
import org.opentripplanner.ext.flex.flexpathcalculator.FlexPathCalculator;
@@ -50,19 +50,19 @@ abstract class AbstractFlexTemplate {
5050
protected final LocalDate serviceDate;
5151
protected final int requestedBookingTime;
5252
protected final FlexPathCalculator calculator;
53-
private final Duration maxTransferDuration;
53+
protected final FlexParameters flexParameters;
5454

5555
/**
56-
* @param trip The FlexTrip used for this template
57-
* @param accessEgress Path from origin/destination to the point of boarding/alighting for
58-
* this flex trip
59-
* @param transferStop The stop location where this FlexTrip transfers to another transit
60-
* service.
61-
* @param boardStopPosition The stop-board-position in the trip pattern
62-
* @param alightStopPosition The stop-alight-position in the trip pattern
63-
* @param date The service date of this FlexTrip
64-
* @param calculator Calculates the path and duration of the FlexTrip
65-
* @param maxTransferDuration The limit for how long a transfer is allowed to be
56+
* @param trip The FlexTrip used for this template
57+
* @param accessEgress Path from origin/destination to the point of boarding/alighting for
58+
* this flex trip
59+
* @param transferStop The stop location where this FlexTrip transfers to another transit
60+
* service.
61+
* @param boardStopPosition The stop-board-position in the trip pattern
62+
* @param alightStopPosition The stop-alight-position in the trip pattern
63+
* @param date The service date of this FlexTrip
64+
* @param calculator Calculates the path and duration of the FlexTrip
65+
* @param flexParameters Flex configuration parameters (reluctance, boardCost, etc.)
6666
*/
6767
AbstractFlexTemplate(
6868
FlexTrip<?, ?> trip,
@@ -72,7 +72,7 @@ abstract class AbstractFlexTemplate {
7272
int alightStopPosition,
7373
FlexServiceDate date,
7474
FlexPathCalculator calculator,
75-
Duration maxTransferDuration
75+
FlexParameters flexParameters
7676
) {
7777
this.accessEgress = accessEgress;
7878
this.trip = trip;
@@ -83,7 +83,7 @@ abstract class AbstractFlexTemplate {
8383
this.serviceDate = date.serviceDate();
8484
this.requestedBookingTime = date.requestedBookingTime();
8585
this.calculator = calculator;
86-
this.maxTransferDuration = maxTransferDuration;
86+
this.flexParameters = flexParameters;
8787
}
8888

8989
FeedScopedId getTransferStopId() {
@@ -108,7 +108,7 @@ Stream<FlexAccessEgress> createFlexAccessEgressStream(FlexAccessEgressCallbackAd
108108
// transferStop is Location Area/Line
109109
else {
110110
double maxDistanceMeters =
111-
maxTransferDuration.getSeconds() *
111+
flexParameters.maxTransferDuration().getSeconds() *
112112
accessEgress.finalStates.getFirst().getRequest().walk().speed();
113113

114114
return getTransfersFromTransferStop(callback)
@@ -136,7 +136,7 @@ public String toString() {
136136
.addServiceTime("secondsFromStartOfTime", secondsFromStartOfTime)
137137
.addDate("serviceDate", serviceDate)
138138
.addObj("calculator", calculator)
139-
.addDuration("maxTransferDuration", maxTransferDuration)
139+
.addDuration("maxTransferDuration", flexParameters.maxTransferDuration())
140140
.toString();
141141
}
142142

application/src/ext/java/org/opentripplanner/ext/flex/template/FlexAccessFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.opentripplanner.ext.flex.template;
22

3-
import java.time.Duration;
43
import java.util.Collection;
54
import java.util.List;
65
import org.opentripplanner.ext.flex.FlexAccessEgress;
6+
import org.opentripplanner.ext.flex.FlexParameters;
77
import org.opentripplanner.ext.flex.flexpathcalculator.FlexPathCalculator;
88
import org.opentripplanner.place.api.NearbyStop;
99
import org.opentripplanner.transit.model.filter.expr.Matcher;
@@ -18,12 +18,12 @@ public class FlexAccessFactory {
1818
public FlexAccessFactory(
1919
FlexAccessEgressCallbackAdapter callbackService,
2020
FlexPathCalculator pathCalculator,
21-
Duration maxTransferDuration,
22-
Matcher<Trip> matcher
21+
Matcher<Trip> matcher,
22+
FlexParameters flexParameters
2323
) {
2424
this.callbackService = callbackService;
2525
this.matcher = matcher;
26-
this.templateFactory = FlexTemplateFactory.of(pathCalculator, maxTransferDuration);
26+
this.templateFactory = FlexTemplateFactory.of(pathCalculator, flexParameters);
2727
}
2828

2929
public List<FlexAccessEgress> createFlexAccesses(

0 commit comments

Comments
 (0)