Skip to content

Commit 7a088e0

Browse files
Make naming of stopTransferCost/stopBoardAlightCost consistent
1 parent 23cd12e commit 7a088e0

File tree

29 files changed

+166
-110
lines changed

29 files changed

+166
-110
lines changed

docs/BuildConfiguration.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ but we want to calculate the transfers always from OSM data.
744744
Should there be some preference or aversion for transfers at stops that are part of a station.
745745

746746
This parameter sets the generic level of preference. What is the actual cost can be changed
747-
with the `stopTransferCost` parameter in the router configuration.
747+
with the `stopBoardAlightDuringTransferCost` parameter in the router configuration.
748748

749749

750750
<h3 id="islandPruning_adaptivePruningDistance">adaptivePruningDistance</h3>
@@ -993,7 +993,7 @@ but we want to calculate the transfers always from OSM data.
993993
Should there be some preference or aversion for transfers at stops that are part of a station. Overrides the value specified in `gtfsDefaults`.
994994

995995
This parameter sets the generic level of preference. What is the actual cost can be changed
996-
with the `stopTransferCost` parameter in the router configuration.
996+
with the `stopBoardAlightDuringTransferCost` parameter in the router configuration.
997997

998998

999999
<h3 id="tf_1_groupFilePattern">groupFilePattern</h3>

docs/RouteRequest.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ The wait time is used to prevent *back-travel*, the `backTravelWaitTimeFactor` i
947947

948948
Add an extra board- and alight-cost for prioritized stops.
949949

950-
A stopBoardAlightCosts is added to the generalized-cost during routing. But this cost
950+
A stopBoardAlightTransferCosts is added to the generalized-cost during routing. But this cost
951951
cannot be too high, because that would add extra cost to the transfer, and favor other
952952
alternative paths. But, when optimizing transfers, we do not have to take other paths
953953
into consideration and can *boost* the stop-priority-cost to allow transfers to

docs/RouterConfiguration.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ A full list of them can be found in the [RouteRequest](RouteRequest.md).
6161
|       [minWindow](#transit_dynamicSearchWindow_minWindow) | `duration` | The constant minimum duration for a raptor-search-window. | *Optional* | `"PT40M"` | 2.2 |
6262
|       [stepMinutes](#transit_dynamicSearchWindow_stepMinutes) | `integer` | Used to set the steps the search-window is rounded to. | *Optional* | `10` | 2.1 |
6363
|    [pagingSearchWindowAdjustments](#transit_pagingSearchWindowAdjustments) | `duration[]` | The provided array of durations is used to increase the search-window for the next/previous page. | *Optional* | | na |
64-
|    [stopTransferCost](#transit_stopTransferCost) | `enum map of integer` | Use this to set a stop transfer cost for the given transfer priority | *Optional* | | 2.0 |
64+
|    [stopBoardAlightDuringTransferCost](#transit_stopBoardAlightDuringTransferCost) | `enum map of integer` | Costs for boarding and alighting during transfers at stops with a given transfer priority. | *Optional* | | 2.0 |
6565
|    [transferCacheRequests](#transit_transferCacheRequests) | `object[]` | Routing requests to use for pre-filling the stop-to-stop transfer cache. | *Optional* | | 2.3 |
6666
| transmodelApi | `object` | Configuration for the Transmodel GraphQL API. | *Optional* | | 2.1 |
6767
|    [hideFeedId](#transmodelApi_hideFeedId) | `boolean` | Hide the FeedId in all API output, and add it to input. | *Optional* | `false` | na |
@@ -358,19 +358,21 @@ previous page cursor. See JavaDoc for [TransitTuningParameters#pagingSearchWindo
358358
for more info."
359359

360360

361-
<h3 id="transit_stopTransferCost">stopTransferCost</h3>
361+
<h3 id="transit_stopBoardAlightDuringTransferCost">stopBoardAlightDuringTransferCost</h3>
362362

363363
**Since version:** `2.0`**Type:** `enum map of integer`**Cardinality:** `Optional`
364364
**Path:** /transit
365365
**Enum keys:** `discouraged` | `allowed` | `recommended` | `preferred`
366366

367-
Use this to set a stop transfer cost for the given transfer priority
367+
Costs for boarding and alighting during transfers at stops with a given transfer priority.
368368

369-
The cost is applied to boarding and alighting at all stops. All stops have a transfer cost priority
370-
set, the default is `allowed`. The `stopTransferCost` parameter is optional, but if listed all
369+
This cost is applied **both to boarding and alighting** at stops during transfers. All stops have a transfer cost priority
370+
set, the default is `allowed`. The `stopBoardAlightDuringTransferCost` parameter is optional, but if listed all
371371
values must be set.
372372

373-
If not set the `stopTransferCost` is ignored. This is only available for NeTEx imported Stops.
373+
When a transfer occurs at the same stop, the cost will be applied twice since the cost is both for boarding and alighting,
374+
375+
If not set the `stopBoardAlightDuringTransferCost` is ignored. This is only available for NeTEx imported Stops.
374376

375377
The cost is a scalar, but is equivalent to the felt cost of riding a transit trip for 1 second.
376378

@@ -382,7 +384,7 @@ The cost is a scalar, but is equivalent to the felt cost of riding a transit tri
382384
| `preferred` | The best place to do transfers. Should be set to `0`(zero). | int |
383385

384386
Use values in a range from `0` to `100 000`. **All key/value pairs are required if the
385-
`stopTransferCost` is listed.**
387+
`stopBoardAlightDuringTransferCost` is listed.**
386388

387389

388390
<h3 id="transit_transferCacheRequests">transferCacheRequests</h3>
@@ -608,7 +610,7 @@ Used to group requests when monitoring OTP.
608610
"minWindow" : "1h",
609611
"maxWindow" : "5h"
610612
},
611-
"stopTransferCost" : {
613+
"stopBoardAlightDuringTransferCost" : {
612614
"DISCOURAGED" : 1500,
613615
"ALLOWED" : 75,
614616
"RECOMMENDED" : 30,

docs/examples/entur/router-config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"minWindow" : "1h",
9292
"maxWindow" : "5h"
9393
},
94-
"stopTransferCost" : {
94+
"stopBoardAlightDuringTransferCost" : {
9595
"DISCOURAGED" : 1500,
9696
"ALLOWED" : 75,
9797
"RECOMMENDED" : 30,

docs/examples/skanetrafiken/router-config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"24h",
1616
"0h"
1717
],
18-
"stopTransferCost": {
18+
"stopBoardAlightDuringTransferCost": {
1919
"DISCOURAGED": 3000,
2020
"ALLOWED": 150,
2121
"RECOMMENDED": 60,

src/main/java/org/opentripplanner/model/Timetable.java

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class Timetable implements Serializable {
6161

6262
private final List<FrequencyEntry> frequencyEntries = new ArrayList<>();
6363

64+
@Nullable
6465
private final LocalDate serviceDate;
6566

6667
/** Construct an empty Timetable. */

src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/router/TransitRouter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private TransitRouterResult route() {
146146
requestTransitDataProvider.stopNameResolver(),
147147
serverContext.transitService().getTransferService(),
148148
requestTransitDataProvider,
149-
transitLayer.getStopBoardAlightCosts(),
149+
transitLayer.getStopBoardAlightTransferCosts(),
150150
request.preferences().transfer().optimization(),
151151
raptorRequest.multiCriteria()
152152
);

src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/TransitLayer.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ public class TransitLayer {
4848

4949
private final TransferIndexGenerator transferIndexGenerator;
5050

51-
private final int[] stopBoardAlightCosts;
51+
/**
52+
* @see #getStopBoardAlightTransferCosts()
53+
*/
54+
@Nullable
55+
private final int[] stopBoardAlightTransferCosts;
5256

5357
/**
5458
* Makes a shallow copy of the TransitLayer, except for the tripPatternsForDate, where a shallow
@@ -65,7 +69,7 @@ public TransitLayer(TransitLayer transitLayer) {
6569
transitLayer.transferCache,
6670
transitLayer.constrainedTransfers,
6771
transitLayer.transferIndexGenerator,
68-
transitLayer.stopBoardAlightCosts
72+
transitLayer.stopBoardAlightTransferCosts
6973
);
7074
}
7175

@@ -78,7 +82,7 @@ public TransitLayer(
7882
RaptorRequestTransferCache transferCache,
7983
ConstrainedTransfersForPatterns constrainedTransfers,
8084
TransferIndexGenerator transferIndexGenerator,
81-
int[] stopBoardAlightCosts
85+
@Nullable int[] stopBoardAlightTransferCosts
8286
) {
8387
this.tripPatternsRunningOnDate = new HashMap<>(tripPatternsRunningOnDate);
8488
this.transfersByStopIndex = transfersByStopIndex;
@@ -88,7 +92,7 @@ public TransitLayer(
8892
this.transferCache = transferCache;
8993
this.constrainedTransfers = constrainedTransfers;
9094
this.transferIndexGenerator = transferIndexGenerator;
91-
this.stopBoardAlightCosts = stopBoardAlightCosts;
95+
this.stopBoardAlightTransferCosts = stopBoardAlightTransferCosts;
9296
}
9397

9498
@Nullable
@@ -166,8 +170,13 @@ public TransferIndexGenerator getTransferIndexGenerator() {
166170
return transferIndexGenerator;
167171
}
168172

169-
public int[] getStopBoardAlightCosts() {
170-
return stopBoardAlightCosts;
173+
/**
174+
* Costs for both boarding and alighting at a given stop during transfer. Note that this is in
175+
* raptor centi-second units.
176+
*/
177+
@Nullable
178+
public int[] getStopBoardAlightTransferCosts() {
179+
return stopBoardAlightTransferCosts;
171180
}
172181

173182
/**

src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/TransitTuningParameters.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface TransitTuningParameters {
1313
* These tuning parameters are typically used in unit tests. The values are:
1414
* <pre>
1515
* enableStopTransferPriority : true
16-
* stopTransferCost : {
16+
* stopBoardAlightDuringTransferCost : {
1717
* DISCOURAGED: 3600 (equivalent of 1 hour penalty)
1818
* ALLOWED: 60 (60 seconds penalty)
1919
* RECOMMENDED: 20 (20 seconds penalty)
@@ -28,7 +28,7 @@ public boolean enableStopTransferPriority() {
2828
}
2929

3030
@Override
31-
public Integer stopTransferCost(StopTransferPriority key) {
31+
public Integer stopBoardAlightDuringTransferCost(StopTransferPriority key) {
3232
switch (key) {
3333
case DISCOURAGED:
3434
return 3600;
@@ -70,10 +70,11 @@ public List<RouteRequest> transferCacheRequests() {
7070
boolean enableStopTransferPriority();
7171

7272
/**
73-
* The stop transfer cost for the given {@link StopTransferPriority}. The cost applied to boarding
74-
* and alighting all stops with the given priority.
73+
* The stop board alight transfer cost for the given {@link StopTransferPriority}. The cost
74+
* applied during transfers to <b>both boarding and alighting</b> of stops with the given
75+
* priority.
7576
*/
76-
Integer stopTransferCost(StopTransferPriority key);
77+
Integer stopBoardAlightDuringTransferCost(StopTransferPriority key);
7778

7879
/**
7980
* The maximum number of transfer RouteRequests for which the pre-calculated transfers should be

src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/cost/CostCalculatorFactory.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package org.opentripplanner.routing.algorithm.raptoradapter.transit.cost;
22

3+
import javax.annotation.Nullable;
34
import org.opentripplanner.raptor.spi.RaptorCostCalculator;
45

56
public class CostCalculatorFactory {
67

78
public static <T extends DefaultTripSchedule> RaptorCostCalculator<T> createCostCalculator(
89
GeneralizedCostParameters generalizedCostParameters,
9-
int[] stopBoardAlightCosts
10+
@Nullable int[] stopBoardAlightTransferCosts
1011
) {
1112
RaptorCostCalculator<T> calculator = new DefaultCostCalculator<>(
1213
generalizedCostParameters,
13-
stopBoardAlightCosts
14+
stopBoardAlightTransferCosts
1415
);
1516

1617
if (generalizedCostParameters.wheelchairEnabled()) {

src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/cost/DefaultCostCalculator.java

+29-17
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,28 @@ public final class DefaultCostCalculator<T extends DefaultTripSchedule>
1919
private final int boardAndTransferCost;
2020
private final int waitFactor;
2121
private final FactorStrategy transitFactors;
22-
private final int[] stopTransferCost;
22+
23+
/**
24+
* Costs for boarding and alighting at a given stop during transfer.
25+
* See TransitLayer.getStopBoardAlightTransferCosts()
26+
*/
27+
@Nullable
28+
private final int[] stopBoardAlightTransferCosts;
2329

2430
/**
2531
* Cost unit: SECONDS - The unit for all input parameters are in the OTP TRANSIT model cost unit
2632
* (in Raptor the unit for cost is centi-seconds).
2733
*
28-
* @param stopTransferCost Unit centi-seconds. This parameter is used "as-is" and not transformed
29-
* into the Raptor cast unit to avoid the transformation for each request.
30-
* Use {@code null} to ignore stop cost.
34+
* @param stopBoardAlightTransferCosts Unit centi-seconds. This parameter is used "as-is" and not
35+
* transformed into the Raptor cast unit to avoid the transformation for each
36+
* request. Use {@code null} to ignore stop cost.
3137
*/
3238
public DefaultCostCalculator(
3339
int boardCost,
3440
int transferCost,
3541
double waitReluctanceFactor,
3642
@Nullable double[] transitReluctanceFactors,
37-
@Nullable int[] stopTransferCost
43+
@Nullable int[] stopBoardAlightTransferCosts
3844
) {
3945
this.boardCostOnly = RaptorCostConverter.toRaptorCost(boardCost);
4046
this.transferCostOnly = RaptorCostConverter.toRaptorCost(transferCost);
@@ -46,16 +52,19 @@ public DefaultCostCalculator(
4652
? new SingleValueFactorStrategy(GeneralizedCostParameters.DEFAULT_TRANSIT_RELUCTANCE)
4753
: new IndexBasedFactorStrategy(transitReluctanceFactors);
4854

49-
this.stopTransferCost = stopTransferCost;
55+
this.stopBoardAlightTransferCosts = stopBoardAlightTransferCosts;
5056
}
5157

52-
public DefaultCostCalculator(GeneralizedCostParameters params, int[] stopTransferCost) {
58+
public DefaultCostCalculator(
59+
GeneralizedCostParameters params,
60+
@Nullable int[] stopBoardAlightTransferCosts
61+
) {
5362
this(
5463
params.boardCost(),
5564
params.transferCost(),
5665
params.waitReluctanceFactor(),
5766
params.transitReluctanceFactors(),
58-
stopTransferCost
67+
stopBoardAlightTransferCosts
5968
);
6069
}
6170

@@ -108,8 +117,8 @@ public int transitArrivalCost(
108117

109118
// Add transfer cost on all alighting events.
110119
// If it turns out to be the last one this cost will be removed during costEgress phase.
111-
if (stopTransferCost != null) {
112-
cost += stopTransferCost[toStop];
120+
if (stopBoardAlightTransferCosts != null) {
121+
cost += stopBoardAlightTransferCosts[toStop];
113122
}
114123

115124
return cost;
@@ -134,20 +143,22 @@ public int calculateRemainingMinCost(int minTravelTime, int minNumTransfers, int
134143
// Remove cost that was added during alighting similar as we do in the costEgress() method
135144
int fixedCost = transitFactors.minFactor() * minTravelTime;
136145

137-
return stopTransferCost == null ? fixedCost : fixedCost - stopTransferCost[fromStop];
146+
return stopBoardAlightTransferCosts == null
147+
? fixedCost
148+
: fixedCost - stopBoardAlightTransferCosts[fromStop];
138149
}
139150
}
140151

141152
@Override
142153
public int costEgress(RaptorAccessEgress egress) {
143154
if (egress.hasRides()) {
144155
return egress.c1() + transferCostOnly;
145-
} else if (stopTransferCost != null) {
156+
} else if (stopBoardAlightTransferCosts != null) {
146157
// Remove cost that was added during alighting.
147158
// We do not want to add this cost on last alighting since it should only be applied on transfers
148159
// It has to be done here because during alighting we do not know yet if it will be
149160
// a transfer or not.
150-
return egress.c1() - stopTransferCost[egress.stop()];
161+
return egress.c1() - stopBoardAlightTransferCosts[egress.stop()];
151162
} else {
152163
return egress.c1();
153164
}
@@ -171,8 +182,8 @@ public int boardingCostRegularTransfer(
171182
cost += firstBoarding ? boardCostOnly : boardAndTransferCost;
172183

173184
// If it's first boarding event then it is not a transfer
174-
if (stopTransferCost != null && !firstBoarding) {
175-
cost += stopTransferCost[boardStop];
185+
if (stopBoardAlightTransferCosts != null && !firstBoarding) {
186+
cost += stopBoardAlightTransferCosts[boardStop];
176187
}
177188
return cost;
178189
}
@@ -210,8 +221,9 @@ private int boardingCostConstrainedTransfer(
210221
// For a guaranteed transfer we skip board- and transfer-cost
211222
final int boardWaitTime = boardTime - prevArrivalTime;
212223

213-
// StopTransferCost is NOT added to the cost here. This is because a trip-to-trip constrained transfer take
214-
// precedence over stop-to-stop transfer priority (NeTEx station transfer priority).
224+
// StopBoardAlightTransferCost is NOT added to the cost here. This is because a trip-to-trip
225+
// constrained transfer take precedence over stop-to-stop transfer priority (NeTEx station
226+
// transfer priority).
215227
return waitFactor * boardWaitTime;
216228
}
217229

src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/mappers/TransitLayerMapper.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.Map;
1414
import java.util.Set;
1515
import java.util.stream.Collectors;
16+
import javax.annotation.Nullable;
1617
import org.opentripplanner.framework.application.OTPFeature;
1718
import org.opentripplanner.model.Timetable;
1819
import org.opentripplanner.routing.algorithm.raptoradapter.transit.Transfer;
@@ -103,7 +104,7 @@ private TransitLayer map(TransitTuningParameters tuningParameters) {
103104
transferCache,
104105
constrainedTransfers,
105106
transferIndexGenerator,
106-
createStopTransferCosts(stopModel, tuningParameters)
107+
createStopBoardAlightTransferCosts(stopModel, tuningParameters)
107108
);
108109
}
109110

@@ -179,19 +180,23 @@ private HashMap<LocalDate, List<TripPatternForDate>> keyByRunningPeriodDates(
179180
}
180181

181182
/**
182-
* Create static board/alight cost for Raptor to include for each stop.
183+
* Create static board/alight cost for Raptor to apply during transfer
183184
*/
184-
static int[] createStopTransferCosts(StopModel stops, TransitTuningParameters tuningParams) {
185+
@Nullable
186+
static int[] createStopBoardAlightTransferCosts(
187+
StopModel stops,
188+
TransitTuningParameters tuningParams
189+
) {
185190
if (!tuningParams.enableStopTransferPriority()) {
186191
return null;
187192
}
188-
int[] stopTransferCosts = new int[stops.stopIndexSize()];
193+
int[] stopBoardAlightTransferCosts = new int[stops.stopIndexSize()];
189194

190195
for (int i = 0; i < stops.stopIndexSize(); ++i) {
191196
StopTransferPriority priority = stops.stopByIndex(i).getPriority();
192-
int domainCost = tuningParams.stopTransferCost(priority);
193-
stopTransferCosts[i] = RaptorCostConverter.toRaptorCost(domainCost);
197+
int domainCost = tuningParams.stopBoardAlightDuringTransferCost(priority);
198+
stopBoardAlightTransferCosts[i] = RaptorCostConverter.toRaptorCost(domainCost);
194199
}
195-
return stopTransferCosts;
200+
return stopBoardAlightTransferCosts;
196201
}
197202
}

src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/request/RaptorRoutingRequestTransitData.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public RaptorRoutingRequestTransitData(
104104
this.generalizedCostCalculator =
105105
CostCalculatorFactory.createCostCalculator(
106106
mcCostParams,
107-
transitLayer.getStopBoardAlightCosts()
107+
transitLayer.getStopBoardAlightTransferCosts()
108108
);
109109

110110
this.slackProvider =

0 commit comments

Comments
 (0)