Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ private GraphQLObjectType createGraphQLType() {
.field(
GraphQLFieldDefinition.newFieldDefinition()
.name("elevatorBoardTime")
.description("How long does it take to get on an elevator, on average.")
.description("How long it takes to get on an elevator, on average.")
.type(Scalars.GraphQLInt)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a duration type in the API? I would prefer it rather than the number of seconds (which these presumably are, but not documented.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All time related fields in this file seem to be using the type Scalars.GraphQLInt. Another option would be to not add this to the API at all, it can be added later on if someone needs it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed elevatorBoardSlack from the API and removed the deprecation from elevatorBoardTime

.dataFetcher(env -> preferences.street().elevator().boardTime())
.dataFetcher(env -> preferences.street().elevator().boardSlack().toSeconds())
.build()
)
.field(
Expand All @@ -151,17 +151,26 @@ private GraphQLObjectType createGraphQLType() {
.field(
GraphQLFieldDefinition.newFieldDefinition()
.name("elevatorHopTime")
.description("How long does it take to advance one floor on an elevator?")
.description("How long it takes to advance one floor on an elevator, on average.")
.type(Scalars.GraphQLInt)
.dataFetcher(env -> preferences.street().elevator().hopTime())
.dataFetcher(env -> preferences.street().elevator().hopTime().toSeconds())
.build()
)
.field(
GraphQLFieldDefinition.newFieldDefinition()
.name("elevatorHopCost")
.deprecate("Use elevatorReluctance to set cost instead.")
.description("What is the cost of travelling one floor on an elevator?")
.type(Scalars.GraphQLInt)
.dataFetcher(env -> preferences.street().elevator().hopCost())
.dataFetcher(env -> -1)
.build()
)
.field(
GraphQLFieldDefinition.newFieldDefinition()
.name("elevatorReluctance")
.description("A multiplier to specify how bad using an elevator is.")
.type(Scalars.GraphQLFloat)
.dataFetcher(env -> preferences.street().elevator().reluctance())
.build()
)
.field(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opentripplanner.routing.api.request.preference;

import java.io.Serializable;
import java.time.Duration;
import java.util.Objects;
import java.util.function.Consumer;
import org.opentripplanner.framework.model.Cost;
Expand All @@ -17,22 +18,22 @@ public final class ElevatorPreferences implements Serializable {
public static final ElevatorPreferences DEFAULT = new ElevatorPreferences();

private final Cost boardCost;
private final int boardTime;
private final Cost hopCost;
private final int hopTime;
private final Duration boardSlack;
private final Duration hopTime;
private final double reluctance;

private ElevatorPreferences() {
this.boardCost = Cost.costOfSeconds(90);
this.boardTime = 90;
this.hopCost = Cost.costOfSeconds(20);
this.hopTime = 20;
this.boardCost = Cost.costOfSeconds(15);
this.boardSlack = Duration.ofSeconds(90);
this.hopTime = Duration.ofSeconds(20);
this.reluctance = 2.0;
}

private ElevatorPreferences(Builder builder) {
this.boardCost = builder.boardCost;
this.boardTime = Units.duration(builder.boardTime);
this.hopCost = builder.hopCost;
this.hopTime = Units.duration(builder.hopTime);
this.boardSlack = builder.boardSlack;
this.hopTime = builder.hopTime;
this.reluctance = Units.reluctance(builder.reluctance);
}

public static Builder of() {
Expand All @@ -43,7 +44,9 @@ public Builder copyOf() {
return new Builder(this);
}

/** What is the cost of boarding an elevator? */
/**
* What is the cost of boarding an elevator?
*/
public int boardCost() {
return boardCost.toSeconds();
}
Expand All @@ -53,23 +56,21 @@ public int boardCost() {
* than average, to prevent optimistic trips)? Setting it to "seems like forever," while accurate,
* will probably prevent OTP from working correctly.
*/
public int boardTime() {
return boardTime;
}

/** How long does it take to advance one floor on an elevator? */
public int hopCost() {
return hopCost.toSeconds();
public Duration boardSlack() {
return boardSlack;
}

/**
* What is the cost of travelling one floor on an elevator?
* It is assumed that getting off an elevator is completely free.
* How long does it take to travel one floor on an elevator?
*/
public int hopTime() {
public Duration hopTime() {
return hopTime;
}

public double reluctance() {
return reluctance;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -80,42 +81,42 @@ public boolean equals(Object o) {
}
ElevatorPreferences that = (ElevatorPreferences) o;
return (
boardCost.equals(that.boardCost) &&
boardTime == that.boardTime &&
hopTime == that.hopTime &&
hopCost.equals(that.hopCost)
Objects.equals(boardCost, that.boardCost) &&
Objects.equals(boardSlack, that.boardSlack) &&
Objects.equals(hopTime, that.hopTime) &&
reluctance == that.reluctance
);
}

@Override
public int hashCode() {
return Objects.hash(boardCost, boardTime, hopTime, hopCost);
return Objects.hash(boardCost, boardSlack, hopTime, reluctance);
}

@Override
public String toString() {
return ToStringBuilder.of(ElevatorPreferences.class)
.addObj("boardCost", boardCost, DEFAULT.boardCost)
.addDurationSec("boardTime", boardTime, DEFAULT.boardTime)
.addObj("hopCost", hopCost, DEFAULT.hopCost)
.addDurationSec("hopTime", hopTime, DEFAULT.hopTime)
.addDuration("boardSlack", boardSlack, DEFAULT.boardSlack)
.addDuration("hopTime", hopTime, DEFAULT.hopTime)
.addNum("reluctance", reluctance, DEFAULT.reluctance)
.toString();
}

public static class Builder {

private final ElevatorPreferences original;
private Cost boardCost;
private int boardTime;
private int hopTime;
private Cost hopCost;
private Duration boardSlack;
private Duration hopTime;
private double reluctance;

public Builder(ElevatorPreferences original) {
this.original = original;
this.boardCost = original.boardCost;
this.boardTime = original.boardTime;
this.hopCost = original.hopCost;
this.boardSlack = original.boardSlack;
this.hopTime = original.hopTime;
this.reluctance = original.reluctance;
}

public ElevatorPreferences original() {
Expand All @@ -127,18 +128,18 @@ public Builder withBoardCost(int boardCost) {
return this;
}

public Builder withBoardTime(int boardTime) {
this.boardTime = boardTime;
public Builder withBoardSlack(Duration boardSlack) {
this.boardSlack = boardSlack;
return this;
}

public Builder withHopTime(int hopTime) {
public Builder withHopTime(Duration hopTime) {
this.hopTime = hopTime;
return this;
}

public Builder withHopCost(int hopCost) {
this.hopCost = Cost.costOfSeconds(hopCost);
public Builder withReluctance(double reluctance) {
this.reluctance = reluctance;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_4;
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_5;
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_7;
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_9;
import static org.opentripplanner.standalone.config.routerequest.ItineraryFiltersConfig.mapItineraryFilterParams;
import static org.opentripplanner.standalone.config.routerequest.TransferConfig.mapTransferPreferences;
import static org.opentripplanner.standalone.config.routerequest.TriangleOptimizationConfig.mapOptimizationTriangle;
Expand Down Expand Up @@ -416,6 +417,11 @@ private static void mapBikePreferences(NodeAdapter root, BikePreferences.Builder

private static void mapStreetPreferences(NodeAdapter c, StreetPreferences.Builder builder) {
var dft = builder.original();
NodeAdapter cElevator = c
.of("elevator")
.since(V2_9)
.summary("Elevator preferences.")
.asObject();
NodeAdapter cae = c
.of("accessEgress")
.since(V2_4)
Expand All @@ -441,32 +447,32 @@ private static void mapStreetPreferences(NodeAdapter c, StreetPreferences.Builde
var dftElevator = dft.elevator();
elevator
.withBoardCost(
c
.of("elevatorBoardCost")
.since(V2_0)
cElevator
.of("boardCost")
.since(V2_9)
.summary("What is the cost of boarding a elevator?")
.asInt(dftElevator.boardCost())
)
.withBoardTime(
c
.of("elevatorBoardTime")
.since(V2_0)
.summary("How long does it take to get on an elevator, on average.")
.asInt(dftElevator.boardTime())
)
.withHopCost(
c
.of("elevatorHopCost")
.since(V2_0)
.summary("What is the cost of travelling one floor on an elevator?")
.asInt(dftElevator.hopCost())
.withBoardSlack(
cElevator
.of("boardSlack")
.since(V2_9)
.summary("How long it takes to get on an elevator, on average.")
.asDuration(dftElevator.boardSlack())
)
.withHopTime(
c
.of("elevatorHopTime")
.since(V2_0)
.summary("How long does it take to advance one floor on an elevator?")
.asInt(dftElevator.hopTime())
cElevator
.of("hopTime")
.since(V2_9)
.summary("How long it takes to advance one floor on an elevator, on average.")
.asDuration(dftElevator.hopTime())
)
.withReluctance(
cElevator
.of("reluctance")
.since(V2_9)
.summary("A multiplier to specify how bad using an elevator is.")
.asDouble(dftElevator.reluctance())
);
})
.withAccessEgress(accessEgress -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public State[] traverse(State s0) {

var req = s0.getRequest();

s1.incrementWeight(req.elevator().boardCost());
s1.incrementTimeInSeconds(req.elevator().boardTime());
long time = req.elevator().boardSlack().toSeconds();
s1.incrementWeight(req.elevator().boardCost() + req.elevator().reluctance() * time);
s1.incrementTimeInSeconds(time);

return s1.makeStateArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,11 @@ public State[] traverse(State s0) {
//
// X ElevatorHopVertex
// --- ElevatorHopEdge
s1.incrementWeight(
this.travelTime > 0 ? this.travelTime : (request.elevator().hopCost() * this.levels)
);
s1.incrementTimeInSeconds(
this.travelTime > 0 ? this.travelTime : (int) (request.elevator().hopTime() * this.levels)
);
int time = this.travelTime > 0
? this.travelTime
: (int) (request.elevator().hopTime().toSeconds() * this.levels);
s1.incrementWeight(request.elevator().reluctance() * time);
s1.incrementTimeInSeconds(time);
return s1.makeStateArray();
}

Expand Down
Loading
Loading