Search in sources :

Example 1 with StateEditor

use of org.opentripplanner.routing.core.StateEditor in project OpenTripPlanner by opentripplanner.

the class StreetBikeRentalLink method traverse.

public State traverse(State s0) {
    // Do not even consider bike rental vertices unless bike rental is enabled.
    if (!s0.getOptions().allowBikeRental) {
        return null;
    }
    // turn restrictions.
    if (s0.getBackEdge() instanceof StreetBikeRentalLink) {
        return null;
    }
    StateEditor s1 = s0.edit(this);
    // assume bike rental stations are more-or-less on-street
    s1.incrementTimeInSeconds(1);
    s1.incrementWeight(1);
    s1.setBackMode(s0.getNonTransitMode());
    return s1.makeState();
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor)

Example 2 with StateEditor

use of org.opentripplanner.routing.core.StateEditor in project OpenTripPlanner by opentripplanner.

the class StreetTransitLink method traverse.

public State traverse(State s0) {
    // Forbid taking shortcuts composed of two street-transit links in a row. Also avoids spurious leg transitions.
    if (s0.backEdge instanceof StreetTransitLink) {
        return null;
    }
    // Do not re-enter the street network following a transfer.
    if (s0.backEdge instanceof SimpleTransfer) {
        return null;
    }
    RoutingRequest req = s0.getOptions();
    if (s0.getOptions().wheelchairAccessible && !wheelchairAccessible) {
        return null;
    }
    if (s0.getOptions().bikeParkAndRide && !s0.isBikeParked()) {
        // Forbid taking your own bike in the station if bike P+R activated.
        return null;
    }
    if (s0.isBikeRenting()) {
        // TODO Check this condition, does this always make sense?
        return null;
    }
    // Do not check here whether any transit modes are selected. A check for the presence of
    // transit modes will instead be done in the following PreBoard edge.
    // This allows searching for nearby transit stops using walk-only options.
    StateEditor s1 = s0.edit(this);
    /* Note that in arriveBy searches this is double-traversing link edges to fork the state into both WALK and CAR mode. This is an insane hack. */
    if (s0.getNonTransitMode() == TraverseMode.CAR) {
        if (req.kissAndRide && !s0.isCarParked()) {
            s1.setCarParked(true);
        } else {
            return null;
        }
    }
    s1.incrementTimeInSeconds(transitStop.getStreetToStopTime() + STL_TRAVERSE_COST);
    s1.incrementWeight(STL_TRAVERSE_COST + transitStop.getStreetToStopTime());
    s1.setBackMode(TraverseMode.LEG_SWITCH);
    return s1.makeState();
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 3 with StateEditor

use of org.opentripplanner.routing.core.StateEditor in project OpenTripPlanner by opentripplanner.

the class PathwayEdge method traverse.

public State traverse(State s0) {
    int time = traversalTime;
    if (s0.getOptions().wheelchairAccessible) {
        if (wheelchairTraversalTime < 0) {
            return null;
        }
        time = wheelchairTraversalTime;
    }
    StateEditor s1 = s0.edit(this);
    s1.incrementTimeInSeconds(time);
    s1.incrementWeight(time);
    s1.setBackMode(getMode());
    return s1.makeState();
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor)

Example 4 with StateEditor

use of org.opentripplanner.routing.core.StateEditor in project OpenTripPlanner by opentripplanner.

the class PreBoardEdge method traverse.

@Override
public State traverse(State s0) {
    RoutingRequest options = s0.getOptions();
    // Ignore this edge if its stop is banned
    if (!options.bannedStops.isEmpty()) {
        if (options.bannedStops.matches(((TransitStop) fromv).getStop())) {
            return null;
        }
    }
    if (!options.bannedStopsHard.isEmpty()) {
        if (options.bannedStopsHard.matches(((TransitStop) fromv).getStop())) {
            return null;
        }
    }
    if (options.arriveBy) {
        /* Traverse backward: not much to do */
        StateEditor s1 = s0.edit(this);
        TransitStop fromVertex = (TransitStop) getFromVertex();
        // apply board slack
        s1.incrementTimeInSeconds(options.boardSlack);
        s1.alightTransit();
        s1.setBackMode(getMode());
        return s1.makeState();
    } else {
        // options can be used to find transit stops without boarding vehicles.
        if (!options.modes.isTransit())
            return null;
        // If we've hit our transfer limit, don't go any further
        if (s0.getNumBoardings() > options.maxTransfers)
            return null;
        /* apply transfer rules */
        /*
             * look in the global transfer table for the rules from the previous stop to this stop.
             */
        long t0 = s0.getTimeSeconds();
        long slack;
        if (s0.isEverBoarded()) {
            slack = options.transferSlack - options.alightSlack;
        } else {
            slack = options.boardSlack;
        }
        long board_after = t0 + slack;
        long transfer_penalty = 0;
        // penalize transfers more heavily if requested by the user
        if (s0.isEverBoarded()) {
            // this is not the first boarding, therefore we must have "transferred" -- whether
            // via a formal transfer or by walking.
            transfer_penalty += options.transferPenalty;
        }
        StateEditor s1 = s0.edit(this);
        s1.setTimeSeconds(board_after);
        long wait_cost = board_after - t0;
        s1.incrementWeight(wait_cost + transfer_penalty);
        s1.setBackMode(getMode());
        return s1.makeState();
    }
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 5 with StateEditor

use of org.opentripplanner.routing.core.StateEditor in project OpenTripPlanner by opentripplanner.

the class PreBoardEdge method optimisticTraverse.

public State optimisticTraverse(State s0) {
    // do not include minimum transfer time in heuristic weight
    // (it is path-dependent)
    StateEditor s1 = s0.edit(this);
    s1.setBackMode(getMode());
    return s1.makeState();
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor)

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