Search in sources :

Example 36 with StateEditor

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();
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 37 with StateEditor

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();
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor) TraverseMode(org.opentripplanner.routing.core.TraverseMode) Edge(org.opentripplanner.routing.graph.Edge)

Example 38 with StateEditor

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;
}
Also used : BikeParkVertex(org.opentripplanner.routing.vertextype.BikeParkVertex) StateEditor(org.opentripplanner.routing.core.StateEditor) State(org.opentripplanner.routing.core.State) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Aggregations

StateEditor (org.opentripplanner.routing.core.StateEditor)38 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)17 State (org.opentripplanner.routing.core.State)5 TraverseMode (org.opentripplanner.routing.core.TraverseMode)4 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)4 Trip (org.onebusaway.gtfs.model.Trip)2 BikeRentalStationVertex (org.opentripplanner.routing.vertextype.BikeRentalStationVertex)2 PatternStopVertex (org.opentripplanner.routing.vertextype.PatternStopVertex)2 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 RoutingContext (org.opentripplanner.routing.core.RoutingContext)1 ServiceDay (org.opentripplanner.routing.core.ServiceDay)1 TransferTable (org.opentripplanner.routing.core.TransferTable)1 Edge (org.opentripplanner.routing.graph.Edge)1 BikeParkVertex (org.opentripplanner.routing.vertextype.BikeParkVertex)1