Search in sources :

Example 86 with RoutingRequest

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

the class PatternHop method optimisticTraverse.

public State optimisticTraverse(State state0) {
    RoutingRequest options = state0.getOptions();
    // Ignore this edge if either of its stop is banned hard
    if (!options.bannedStopsHard.isEmpty()) {
        if (options.bannedStopsHard.matches(((PatternStopVertex) fromv).getStop()) || options.bannedStopsHard.matches(((PatternStopVertex) tov).getStop())) {
            return null;
        }
    }
    int runningTime = getPattern().scheduledTimetable.getBestRunningTime(stopIndex);
    StateEditor s1 = state0.edit(this);
    s1.incrementTimeInSeconds(runningTime);
    s1.setBackMode(getMode());
    s1.incrementWeight(runningTime);
    return s1.makeState();
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) PatternStopVertex(org.opentripplanner.routing.vertextype.PatternStopVertex)

Example 87 with RoutingRequest

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

the class PatternHop method traverse.

public State traverse(State s0) {
    RoutingRequest options = s0.getOptions();
    // Ignore this edge if either of its stop is banned hard
    if (!options.bannedStopsHard.isEmpty()) {
        if (options.bannedStopsHard.matches(((PatternStopVertex) fromv).getStop()) || options.bannedStopsHard.matches(((PatternStopVertex) tov).getStop())) {
            return null;
        }
    }
    TripTimes tripTimes = s0.getTripTimes();
    int runningTime = tripTimes.getRunningTime(stopIndex);
    StateEditor s1 = s0.edit(this);
    s1.incrementTimeInSeconds(runningTime);
    if (s0.getOptions().arriveBy)
        s1.setZone(getBeginStop().getZoneId());
    else
        s1.setZone(getEndStop().getZoneId());
    // s1.setRoute(pattern.getExemplar().route.getId());
    s1.incrementWeight(runningTime);
    s1.setBackMode(getMode());
    return s1.makeState();
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) PatternStopVertex(org.opentripplanner.routing.vertextype.PatternStopVertex)

Example 88 with RoutingRequest

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

the class ElevatorBoardEdge method traverse.

@Override
public State traverse(State s0) {
    RoutingRequest options = s0.getOptions();
    StateEditor s1 = s0.edit(this);
    // We always walk in elevators, even when we have a bike with us
    s1.setBackMode(TraverseMode.WALK);
    s1.incrementWeight(options.elevatorBoardCost);
    s1.incrementTimeInSeconds(options.elevatorBoardTime);
    return s1.makeState();
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 89 with RoutingRequest

use of org.opentripplanner.routing.core.RoutingRequest 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 90 with RoutingRequest

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

the class AnalystProfileRouterPrototype method findClosestStops.

/**
 * Perform an on-street search around a point with a specific mode to find nearby stops.
 * TODO merge with NearbyStopFinder
 */
private TObjectIntMap<Stop> findClosestStops(final TraverseMode mode) {
    RoutingRequest rr = new RoutingRequest(mode);
    GenericLocation gl = new GenericLocation(request.fromLat, request.fromLon);
    rr.from = gl;
    // FIXME destination must be set, even though this is meaningless for one-to-many
    rr.to = gl;
    rr.setRoutingContext(graph);
    // Set batch after context, so both origin and dest vertices will be found.
    rr.batch = (true);
    rr.walkSpeed = request.walkSpeed;
    // RR dateTime defaults to currentTime.
    // If elapsed time is not capped, searches are very slow.
    int minAccessTime = 0;
    int maxAccessTime = request.maxWalkTime;
    rr.worstTime = (rr.dateTime + maxAccessTime * 60);
    AStar astar = new AStar();
    rr.dominanceFunction = new DominanceFunction.EarliestArrival();
    rr.setNumItineraries(1);
    StopFinderTraverseVisitor visitor = new StopFinderTraverseVisitor(mode, minAccessTime * 60);
    astar.setTraverseVisitor(visitor);
    // timeout in seconds
    astar.getShortestPathTree(rr, 5);
    rr.cleanup();
    return visitor.stopsFound;
}
Also used : AStar(org.opentripplanner.routing.algorithm.AStar) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction)

Aggregations

RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)124 GraphPath (org.opentripplanner.routing.spt.GraphPath)56 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)52 State (org.opentripplanner.routing.core.State)42 Test (org.junit.Test)35 Vertex (org.opentripplanner.routing.graph.Vertex)35 Graph (org.opentripplanner.routing.graph.Graph)24 GenericLocation (org.opentripplanner.common.model.GenericLocation)21 Edge (org.opentripplanner.routing.graph.Edge)18 StateEditor (org.opentripplanner.routing.core.StateEditor)17 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)17 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)17 AStar (org.opentripplanner.routing.algorithm.AStar)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)12 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)11 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)11 Trip (org.onebusaway.gtfs.model.Trip)9