use of org.opentripplanner.routing.core.StateEditor in project OpenTripPlanner by opentripplanner.
the class IntersectionTransitLink method traverse.
@Override
public State traverse(State s0) {
RoutingRequest options = s0.getOptions();
StateEditor s1 = s0.edit(this);
boolean cycling = options.modes.contains(TraverseMode.BICYCLE) && !options.walkingBike;
double speed = cycling ? options.bikeSpeed : options.walkSpeed;
// speed in m/s, length in mm, so we get milliseconds
s1.incrementTimeInMilliseconds((long) (length_mm / speed));
if (!cycling)
s1.incrementWalkDistance(length_mm / 1000d);
return s1.makeState();
}
use of org.opentripplanner.routing.core.StateEditor in project OpenTripPlanner by opentripplanner.
the class ParkAndRideLinkEdge method traverse.
@Override
public State traverse(State s0) {
// Do not enter park and ride mechanism if it's not activated in the routing request.
if (!s0.getOptions().parkAndRide) {
return null;
}
Edge backEdge = s0.getBackEdge();
boolean back = s0.getOptions().arriveBy;
// shortcut.
if ((back != exit) && !(backEdge instanceof ParkAndRideEdge))
return null;
StateEditor s1 = s0.edit(this);
TraverseMode mode = s0.getNonTransitMode();
if (mode == TraverseMode.WALK) {
// Walking
double walkTime = linkDistance * WALK_OBSTRUCTION_FACTOR / s0.getOptions().walkSpeed;
s1.incrementTimeInSeconds((int) Math.round(walkTime));
s1.incrementWeight(walkTime);
s1.incrementWalkDistance(linkDistance);
s1.setBackMode(TraverseMode.WALK);
} else if (mode == TraverseMode.CAR) {
// Driving
double driveTime = linkDistance * DRIVE_OBSTRUCTION_FACTOR / DRIVE_SPEED_MS;
s1.incrementTimeInSeconds((int) Math.round(driveTime));
s1.incrementWeight(driveTime);
s1.setBackMode(TraverseMode.CAR);
} else {
// Can't cycle in/out a P+R.
return null;
}
return s1.makeState();
}
use of org.opentripplanner.routing.core.StateEditor in project OpenTripPlanner by opentripplanner.
the class BikeParkEdge method traversePark.
protected State traversePark(State s0) {
RoutingRequest options = s0.getOptions();
/*
* To park a bike, we need to be riding one, (not rented) and be allowed to walk and to park
* it.
*/
if (s0.getNonTransitMode() != TraverseMode.BICYCLE || !options.modes.getWalk() || s0.isBikeRenting() || s0.isBikeParked())
return null;
BikeParkVertex bikeParkVertex = (BikeParkVertex) tov;
if (bikeParkVertex.getSpacesAvailable() == 0) {
return null;
}
StateEditor s0e = s0.edit(this);
s0e.incrementWeight(options.bikeParkCost);
s0e.incrementTimeInSeconds(options.bikeParkTime);
s0e.setBackMode(TraverseMode.LEG_SWITCH);
s0e.setBikeParked(true);
State s1 = s0e.makeState();
return s1;
}
Aggregations