Search in sources :

Example 91 with RoutingRequest

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

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

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

Example 94 with RoutingRequest

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

the class TripTimes method tripAcceptable.

/**
 * Once a trip has been found departing or arriving at an appropriate time, check whether that
 * trip fits other restrictive search criteria such as bicycle and wheelchair accessibility
 * and transfers with minimum time or forbidden transfers.
 */
public boolean tripAcceptable(final State state0, final int stopIndex) {
    final RoutingRequest options = state0.getOptions();
    final BannedStopSet banned = options.bannedTrips.get(trip.getId());
    if (banned != null && banned.contains(stopIndex)) {
        return false;
    }
    if (options.wheelchairAccessible && trip.getWheelchairAccessible() != 1) {
        return false;
    }
    // Establish whether we have a rented _or_ owned bicycle.
    final boolean bicycle = state0.getNonTransitMode() == TraverseMode.BICYCLE;
    if (bicycle && BikeAccess.fromTrip(trip) != BikeAccess.ALLOWED) {
        return false;
    }
    return true;
}
Also used : BannedStopSet(org.opentripplanner.routing.request.BannedStopSet) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 95 with RoutingRequest

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

the class TestHalfEdges method testRouteToSameEdge.

@Test
public void testRouteToSameEdge() {
    RoutingRequest options = new RoutingRequest();
    HashSet<Edge> turns = new HashSet<Edge>();
    turns.add(left);
    turns.add(leftBack);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
    TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end", new NonLocalizedString("end"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.8).getCoordinate(left.getGeometry()), true);
    assertEquals(start.getX(), end.getX(), 0.0001);
    assertTrue(start.getY() < end.getY());
    Collection<Edge> edges = end.getIncoming();
    assertEquals(2, edges.size());
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
    options.dateTime = startTime;
    options.setRoutingContext(graph, start, end);
    options.setMaxWalkDistance(Double.MAX_VALUE);
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(end, false);
    assertNotNull("There must be a path from start to end", path);
    assertEquals(1, path.edges.size());
    options.cleanup();
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

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