Skip to content

Commit 61872ca

Browse files
committed
Add boardCost functionality for cars.
1 parent f580998 commit 61872ca

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

application/src/main/java/org/opentripplanner/apis/gtfs/mapping/routerequest/CarPreferencesMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ static void setCarPreferences(
2727
if (reluctance != null) {
2828
preferences.withReluctance(reluctance);
2929
}
30+
var boardCost = args.getGraphQLBoardCost();
31+
if (boardCost != null) {
32+
preferences.withBoardCost(boardCost.toSeconds());
33+
}
3034
preferences.withParking(parking ->
3135
setCarParkingPreferences(parking, args.getGraphQLParking(), environment)
3236
);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ public static GeneralizedCostParameters map(
2525
.transferCost(preferences.transfer().cost())
2626
.waitReluctanceFactor(preferences.transfer().waitReluctance());
2727

28-
if (request.journey().transfer().mode() == StreetMode.BIKE) {
28+
StreetMode mode = request.journey().transfer().mode();
29+
if (mode == StreetMode.BIKE) {
2930
builder.boardCost(preferences.bike().boardCost());
31+
} else if (mode == StreetMode.CAR) {
32+
builder.boardCost(preferences.car().boardCost());
3033
} else {
3134
builder.boardCost(preferences.walk().boardCost());
3235
}

application/src/main/java/org/opentripplanner/routing/api/request/preference/CarPreferences.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public final class CarPreferences implements Serializable {
2323
public static final CarPreferences DEFAULT = new CarPreferences();
2424

2525
private final double reluctance;
26+
private final Cost boardCost;
2627
private final VehicleParkingPreferences parking;
2728
private final VehicleRentalPreferences rental;
2829
private final Duration pickupTime;
@@ -33,6 +34,7 @@ public final class CarPreferences implements Serializable {
3334
/** Create a new instance with default values. */
3435
private CarPreferences() {
3536
this.reluctance = 2.0;
37+
this.boardCost = Cost.costOfMinutes(10);
3638
this.parking = VehicleParkingPreferences.DEFAULT;
3739
this.rental = VehicleRentalPreferences.DEFAULT;
3840
this.pickupTime = Duration.ofMinutes(1);
@@ -43,6 +45,7 @@ private CarPreferences() {
4345

4446
private CarPreferences(Builder builder) {
4547
this.reluctance = Units.reluctance(builder.reluctance);
48+
this.boardCost = builder.boardCost;
4649
this.parking = builder.parking;
4750
this.rental = builder.rental;
4851
this.pickupTime = Duration.ofSeconds(Units.duration(builder.pickupTime));
@@ -63,6 +66,15 @@ public double reluctance() {
6366
return reluctance;
6467
}
6568

69+
/**
70+
* Separate cost for boarding a vehicle with a car, which is different compared to on foot or with a bicycle. This
71+
* is in addition to the cost of the transfer and waiting-time. It is also in addition to
72+
* the {@link TransferPreferences#cost()}.
73+
*/
74+
public int boardCost() {
75+
return boardCost.toSeconds();
76+
}
77+
6678
/** Parking preferences that can be different per request */
6779
public VehicleParkingPreferences parking() {
6880
return parking;
@@ -106,6 +118,7 @@ public boolean equals(Object o) {
106118
CarPreferences that = (CarPreferences) o;
107119
return (
108120
DoubleUtils.doubleEquals(that.reluctance, reluctance) &&
121+
boardCost.equals(that.boardCost) &&
109122
parking.equals(that.parking) &&
110123
rental.equals(that.rental) &&
111124
Objects.equals(pickupTime, that.pickupTime) &&
@@ -119,6 +132,7 @@ public boolean equals(Object o) {
119132
public int hashCode() {
120133
return Objects.hash(
121134
reluctance,
135+
boardCost,
122136
parking,
123137
rental,
124138
pickupTime,
@@ -133,6 +147,7 @@ public String toString() {
133147
return ToStringBuilder
134148
.of(CarPreferences.class)
135149
.addNum("reluctance", reluctance, DEFAULT.reluctance)
150+
.addObj("boardCost", boardCost, DEFAULT.boardCost)
136151
.addObj("parking", parking, DEFAULT.parking)
137152
.addObj("rental", rental, DEFAULT.rental)
138153
.addObj("pickupTime", pickupTime, DEFAULT.pickupTime)
@@ -147,6 +162,7 @@ public static class Builder {
147162

148163
private final CarPreferences original;
149164
private double reluctance;
165+
private Cost boardCost;
150166
private VehicleParkingPreferences parking;
151167
private VehicleRentalPreferences rental;
152168
private int pickupTime;
@@ -157,6 +173,7 @@ public static class Builder {
157173
public Builder(CarPreferences original) {
158174
this.original = original;
159175
this.reluctance = original.reluctance;
176+
this.boardCost = original.boardCost;
160177
this.parking = original.parking;
161178
this.rental = original.rental;
162179
this.pickupTime = (int) original.pickupTime.toSeconds();
@@ -174,6 +191,15 @@ public Builder withReluctance(double reluctance) {
174191
return this;
175192
}
176193

194+
public Cost boardCost() {
195+
return boardCost;
196+
}
197+
198+
public Builder withBoardCost(int boardCost) {
199+
this.boardCost = Cost.costOfSeconds(boardCost);
200+
return this;
201+
}
202+
177203
public Builder withParking(Consumer<VehicleParkingPreferences.Builder> body) {
178204
this.parking = ifNotNull(this.parking, original.parking).copyOf().apply(body).build();
179205
return this;

0 commit comments

Comments
 (0)