Search in sources :

Example 16 with GraphPath

use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method testRoutingOverMidnight.

public void testRoutingOverMidnight() throws Exception {
    // this route only runs on weekdays
    Vertex stop_g = graph.getVertex(feedId + ":G_depart");
    Vertex stop_h = graph.getVertex(feedId + ":H_arrive");
    ShortestPathTree spt;
    GraphPath path;
    RoutingRequest options = new RoutingRequest();
    // Friday evening
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 18, 23, 20, 0);
    options.setRoutingContext(graph, stop_g, stop_h);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_h, false);
    assertNotNull(path);
    assertEquals(4, path.states.size());
    // Saturday morning
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 19, 0, 5, 0);
    options.dateTime = startTime;
    options.setRoutingContext(graph, stop_g.getLabel(), stop_h.getLabel());
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_h, false);
    assertNotNull(path);
    assertEquals(4, path.states.size());
    long endTime = path.getEndTime();
    assertTrue(endTime < startTime + 60 * 60);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 17 with GraphPath

use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method testTripBikesAllowed.

public void testTripBikesAllowed() throws Exception {
    Vertex stop_a = graph.getVertex(feedId + ":A");
    Vertex stop_b = graph.getVertex(feedId + ":B");
    Vertex stop_c = graph.getVertex(feedId + ":C");
    Vertex stop_d = graph.getVertex(feedId + ":D");
    RoutingRequest options = new RoutingRequest();
    options.modes.setWalk(false);
    options.modes.setBicycle(true);
    options.modes.setTransit(true);
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 18, 0, 0, 0);
    options.setRoutingContext(graph, stop_a, stop_b);
    ShortestPathTree spt;
    GraphPath path;
    // route: bikes allowed, trip: no value
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_b, false);
    assertNotNull(path);
    // route: bikes allowed, trip: bikes not allowed
    options.setRoutingContext(graph, stop_d, stop_c);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_c, false);
    assertNull(path);
    // route: bikes not allowed, trip: bikes allowed
    options.setRoutingContext(graph, stop_c, stop_d);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_d, false);
    assertNotNull(path);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 18 with GraphPath

use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.

the class GraphPathToTripPlanConverter method generatePlan.

/**
 * Generates a TripPlan from a set of paths
 */
public static TripPlan generatePlan(List<GraphPath> paths, RoutingRequest request) {
    Locale requestedLocale = request.locale;
    GraphPath exemplar = paths.get(0);
    Vertex tripStartVertex = exemplar.getStartVertex();
    Vertex tripEndVertex = exemplar.getEndVertex();
    String startName = tripStartVertex.getName(requestedLocale);
    String endName = tripEndVertex.getName(requestedLocale);
    // Use vertex labels if they don't have names
    if (startName == null) {
        startName = tripStartVertex.getLabel();
    }
    if (endName == null) {
        endName = tripEndVertex.getLabel();
    }
    Place from = new Place(tripStartVertex.getX(), tripStartVertex.getY(), startName);
    Place to = new Place(tripEndVertex.getX(), tripEndVertex.getY(), endName);
    from.orig = request.from.name;
    to.orig = request.to.name;
    TripPlan plan = new TripPlan(from, to, request.getDateTime());
    // Convert GraphPaths to Itineraries, keeping track of the best non-transit (e.g. walk/bike-only) option time
    long bestNonTransitTime = Long.MAX_VALUE;
    List<Itinerary> itineraries = new LinkedList<>();
    for (GraphPath path : paths) {
        Itinerary itinerary = generateItinerary(path, request.showIntermediateStops, request.disableAlertFiltering, requestedLocale);
        itinerary = adjustItinerary(request, itinerary);
        if (itinerary.transitTime == 0 && itinerary.walkTime < bestNonTransitTime) {
            bestNonTransitTime = itinerary.walkTime;
        }
        itineraries.add(itinerary);
    }
    // Filter and add itineraries to plan
    for (Itinerary itinerary : itineraries) {
        // do not include in plan
        if (itinerary.transitTime > 0 && itinerary.walkTime > bestNonTransitTime)
            continue;
        plan.addItinerary(itinerary);
    }
    if (plan != null) {
        for (Itinerary i : plan.itinerary) {
            /* Communicate the fact that the only way we were able to get a response was by removing a slope limit. */
            i.tooSloped = request.rctx.slopeRestrictionRemoved;
            /* fix up from/to on first/last legs */
            if (i.legs.size() == 0) {
                LOG.warn("itinerary has no legs");
                continue;
            }
            Leg firstLeg = i.legs.get(0);
            firstLeg.from.orig = plan.from.orig;
            Leg lastLeg = i.legs.get(i.legs.size() - 1);
            lastLeg.to.orig = plan.to.orig;
        }
    }
    request.rctx.debugOutput.finishedRendering();
    return plan;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) GraphPath(org.opentripplanner.routing.spt.GraphPath) LineString(com.vividsolutions.jts.geom.LineString)

Example 19 with GraphPath

use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.

the class TestIntermediatePlaces method handleRequest.

private void handleRequest(GenericLocation from, GenericLocation to, GenericLocation[] via, String modes, boolean arriveBy) {
    RoutingRequest request = new RoutingRequest(modes);
    request.setDateTime("2016-04-20", "13:00", timeZone);
    request.setArriveBy(arriveBy);
    request.from = from;
    request.to = to;
    for (GenericLocation intermediateLocation : via) {
        request.addIntermediatePlace(intermediateLocation);
    }
    List<GraphPath> pathList = graphPathFinder.graphPathFinderEntryPoint(request);
    assertNotNull(pathList);
    assertFalse(pathList.isEmpty());
    TripPlan plan = GraphPathToTripPlanConverter.generatePlan(pathList, request);
    assertLocationIsVeryCloseToPlace(from, plan.from);
    assertLocationIsVeryCloseToPlace(to, plan.to);
    assertTrue(1 <= plan.itinerary.size());
    for (Itinerary itinerary : plan.itinerary) {
        validateIntermediatePlacesVisited(itinerary, via);
        assertTrue(via.length < itinerary.legs.size());
        validateLegsTemporally(request, itinerary);
        validateLegsSpatially(plan, itinerary);
        if (modes.contains("TRANSIT")) {
            assert itinerary.transitTime > 0;
        }
    }
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) TripPlan(org.opentripplanner.api.model.TripPlan) Itinerary(org.opentripplanner.api.model.Itinerary) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 20 with GraphPath

use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.

the class TestUnroutable method testOnBoardRouting.

/**
 * Search for a path across the Willamette river. This OSM data includes a bridge that is not yet built and is
 * therefore tagged highway=construction.
 * TODO also test unbuilt, proposed, raceways etc.
 */
public void testOnBoardRouting() throws Exception {
    RoutingRequest options = new RoutingRequest();
    Vertex from = graph.getVertex("osm:node:2003617278");
    Vertex to = graph.getVertex("osm:node:40446276");
    options.setRoutingContext(graph, from, to);
    options.setMode(TraverseMode.BICYCLE);
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(to, false);
    // is filtered out, thus the null check.
    if (path != null) {
        for (Edge edge : path.edges) {
            assertFalse("Path should not use the as-yet unbuilt Tilikum Crossing bridge.", "Tilikum Crossing".equals(edge.getName()));
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

GraphPath (org.opentripplanner.routing.spt.GraphPath)76 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)56 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)47 Vertex (org.opentripplanner.routing.graph.Vertex)39 State (org.opentripplanner.routing.core.State)25 Test (org.junit.Test)18 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)17 Edge (org.opentripplanner.routing.graph.Edge)15 Graph (org.opentripplanner.routing.graph.Graph)13 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)11 Stop (org.onebusaway.gtfs.model.Stop)10 HashSet (java.util.HashSet)9 Trip (org.onebusaway.gtfs.model.Trip)9 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)9 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)8 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)6 File (java.io.File)5 TransitBoardAlight (org.opentripplanner.routing.edgetype.TransitBoardAlight)5 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)5