Search in sources :

Example 21 with StateEditor

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

the class ParkAndRideEdge method traverse.

@Override
public State traverse(State s0) {
    RoutingRequest request = s0.getOptions();
    if (!request.parkAndRide) {
        return null;
    }
    if (request.arriveBy) {
        /*
             * To get back a car, we need to walk and have car mode enabled.
             */
        if (s0.getNonTransitMode() != TraverseMode.WALK) {
            return null;
        }
        if (!s0.isCarParked()) {
            throw new IllegalStateException("Stolen car?");
        }
        StateEditor s1 = s0.edit(this);
        int time = request.carDropoffTime;
        s1.incrementWeight(time);
        s1.incrementTimeInSeconds(time);
        s1.setCarParked(false);
        s1.setBackMode(TraverseMode.LEG_SWITCH);
        return s1.makeState();
    } else {
        /*
             * To park a car, we need to be in one and have allowed walk modes.
             */
        if (s0.getNonTransitMode() != TraverseMode.CAR) {
            return null;
        }
        if (s0.isCarParked()) {
            throw new IllegalStateException("Can't drive 2 cars");
        }
        StateEditor s1 = s0.edit(this);
        int time = request.carDropoffTime;
        s1.incrementWeight(time);
        s1.incrementTimeInSeconds(time);
        s1.setCarParked(true);
        s1.setBackMode(TraverseMode.LEG_SWITCH);
        return s1.makeState();
    }
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 22 with StateEditor

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

the class PreAlightEdge 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) tov).getStop())) {
            return null;
        }
    }
    if (!options.bannedStopsHard.isEmpty()) {
        if (options.bannedStopsHard.matches(((TransitStop) tov).getStop())) {
            return null;
        }
    }
    if (options.arriveBy) {
        // options can be used to find transit stops without boarding vehicles.
        if (!options.modes.isTransit())
            return null;
        TransitStop toVertex = (TransitStop) getToVertex();
        // 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.boardSlack;
        } else {
            slack = options.alightSlack;
        }
        long alight_before = t0 - slack;
        int 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(alight_before);
        long wait_cost = t0 - alight_before;
        s1.incrementWeight(wait_cost + transfer_penalty);
        s1.setBackMode(getMode());
        return s1.makeState();
    } else {
        /* Forward traversal: not so much to do */
        StateEditor s1 = s0.edit(this);
        TransitStop toVertex = (TransitStop) getToVertex();
        s1.alightTransit();
        s1.incrementTimeInSeconds(options.alightSlack);
        s1.setBackMode(getMode());
        return s1.makeState();
    }
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) StateEditor(org.opentripplanner.routing.core.StateEditor) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 23 with StateEditor

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

the class PreAlightEdge 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)

Example 24 with StateEditor

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

the class RentABikeAbstractEdge method traverseDropoff.

protected State traverseDropoff(State s0) {
    RoutingRequest options = s0.getOptions();
    /*
         * To dropoff a bike, we need to have rented one.
         */
    if (!s0.isBikeRenting() || !hasCompatibleNetworks(networks, s0.getBikeRentalNetworks()))
        return null;
    BikeRentalStationVertex pickup = (BikeRentalStationVertex) tov;
    if (options.useBikeRentalAvailabilityInformation && pickup.getSpacesAvailable() == 0) {
        return null;
    }
    StateEditor s1e = s0.edit(this);
    s1e.incrementWeight(options.arriveBy ? options.bikeRentalPickupCost : options.bikeRentalDropoffCost);
    s1e.incrementTimeInSeconds(options.arriveBy ? options.bikeRentalPickupTime : options.bikeRentalDropoffTime);
    s1e.setBikeRenting(false);
    s1e.setBackMode(TraverseMode.WALK);
    State s1 = s1e.makeState();
    return s1;
}
Also used : BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) StateEditor(org.opentripplanner.routing.core.StateEditor) State(org.opentripplanner.routing.core.State) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 25 with StateEditor

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

the class RentABikeAbstractEdge method traverseRent.

protected State traverseRent(State s0) {
    RoutingRequest options = s0.getOptions();
    /*
         * If we already have a bike (rented or own) we won't go any faster by having a second one.
         */
    if (!s0.getNonTransitMode().equals(TraverseMode.WALK))
        return null;
    /*
         * To rent a bike, we need to have BICYCLE in allowed modes.
         */
    if (!options.modes.contains(TraverseMode.BICYCLE))
        return null;
    BikeRentalStationVertex dropoff = (BikeRentalStationVertex) tov;
    if (options.useBikeRentalAvailabilityInformation && dropoff.getBikesAvailable() == 0) {
        return null;
    }
    StateEditor s1 = s0.edit(this);
    s1.incrementWeight(options.arriveBy ? options.bikeRentalDropoffCost : options.bikeRentalPickupCost);
    s1.incrementTimeInSeconds(options.arriveBy ? options.bikeRentalDropoffTime : options.bikeRentalPickupTime);
    s1.setBikeRenting(true);
    s1.setBikeRentalNetwork(networks);
    s1.setBackMode(s0.getNonTransitMode());
    State s1b = s1.makeState();
    return s1b;
}
Also used : BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) 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