Search in sources :

Example 41 with GraphPath

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

the class TestBikeRental method testBasic.

public void testBasic() throws Exception {
    // generate a very simple graph
    Graph graph = new Graph();
    StreetVertex v1 = new IntersectionVertex(graph, "v1", -77.0492, 38.856, "v1");
    StreetVertex v2 = new IntersectionVertex(graph, "v2", -77.0492, 38.857, "v2");
    StreetVertex v3 = new IntersectionVertex(graph, "v3", -77.0492, 38.858, "v3");
    @SuppressWarnings("unused") Edge walk = new StreetEdge(v1, v2, GeometryUtils.makeLineString(-77.0492, 38.856, -77.0492, 38.857), "S. Crystal Dr", 87, StreetTraversalPermission.PEDESTRIAN, false);
    @SuppressWarnings("unused") Edge mustBike = new StreetEdge(v2, v3, GeometryUtils.makeLineString(-77.0492, 38.857, -77.0492, 38.858), "S. Crystal Dr", 87, StreetTraversalPermission.BICYCLE, false);
    AStar aStar = new AStar();
    // it is impossible to get from v1 to v3 by walking
    RoutingRequest options = new RoutingRequest(new TraverseModeSet("WALK,TRANSIT"));
    options.setRoutingContext(graph, v1, v3);
    ShortestPathTree tree = aStar.getShortestPathTree(options);
    GraphPath path = tree.getPath(v3, false);
    assertNull(path);
    // or biking + walking (assuming walking bikes is disallowed)
    options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
    options.freezeTraverseMode();
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    assertNull(path);
    // so we add a bike share
    BikeRentalStation station = new BikeRentalStation();
    station.id = "id";
    station.name = new NonLocalizedString("station");
    station.x = -77.049;
    station.y = 36.856;
    station.bikesAvailable = 5;
    station.spacesAvailable = 5;
    BikeRentalStationVertex stationVertex = new BikeRentalStationVertex(graph, station);
    new StreetBikeRentalLink(stationVertex, v2);
    new StreetBikeRentalLink(v2, stationVertex);
    Set<String> networks = new HashSet<String>(Arrays.asList("default"));
    new RentABikeOnEdge(stationVertex, stationVertex, networks);
    new RentABikeOffEdge(stationVertex, stationVertex, networks);
    // but we can't get off the bike at v3, so we still fail
    options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
    options.freezeTraverseMode();
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    // null is returned because the only state at the target is not final
    assertNull(path);
    BikeRentalStation station2 = new BikeRentalStation();
    station2.id = "id2";
    station2.name = new NonLocalizedString("station2");
    station2.x = -77.049;
    station2.y = 36.857;
    station2.bikesAvailable = 5;
    station2.spacesAvailable = 5;
    BikeRentalStationVertex stationVertex2 = new BikeRentalStationVertex(graph, station2);
    new StreetBikeRentalLink(stationVertex2, v3);
    new StreetBikeRentalLink(v3, stationVertex2);
    new RentABikeOnEdge(stationVertex2, stationVertex2, networks);
    new RentABikeOffEdge(stationVertex2, stationVertex2, networks);
    // now we succeed!
    options = new RoutingRequest();
    new QualifiedModeSet("BICYCLE_RENT,TRANSIT").applyToRoutingRequest(options);
    options.setRoutingContext(graph, v1, v3);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(v3, false);
    assertNotNull(path);
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) BikeRentalStation(org.opentripplanner.routing.bike_rental.BikeRentalStation) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) BikeRentalStationVertex(org.opentripplanner.routing.vertextype.BikeRentalStationVertex) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 42 with GraphPath

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

the class WalkableAreaBuilder method pruneAreaEdges.

/**
 * Do an all-pairs shortest path search from a list of vertices over a specified set of edges,
 * and retain only those edges which are actually used in some shortest path.
 *
 * @param startingVertices
 * @param edges
 */
private void pruneAreaEdges(Collection<Vertex> startingVertices, Set<Edge> edges) {
    if (edges.size() == 0)
        return;
    TraverseMode mode;
    StreetEdge firstEdge = (StreetEdge) edges.iterator().next();
    if (firstEdge.getPermission().allows(StreetTraversalPermission.PEDESTRIAN)) {
        mode = TraverseMode.WALK;
    } else if (firstEdge.getPermission().allows(StreetTraversalPermission.BICYCLE)) {
        mode = TraverseMode.BICYCLE;
    } else {
        mode = TraverseMode.CAR;
    }
    RoutingRequest options = new RoutingRequest(mode);
    options.setDummyRoutingContext(graph);
    options.dominanceFunction = new DominanceFunction.EarliestArrival();
    GenericDijkstra search = new GenericDijkstra(options);
    search.setSkipEdgeStrategy(new ListedEdgesOnly(edges));
    Set<Edge> usedEdges = new HashSet<Edge>();
    for (Vertex vertex : startingVertices) {
        State state = new State(vertex, options);
        ShortestPathTree spt = search.getShortestPathTree(state);
        for (Vertex endVertex : startingVertices) {
            GraphPath path = spt.getPath(endVertex, false);
            if (path != null) {
                for (Edge edge : path.edges) {
                    usedEdges.add(edge);
                }
            }
        }
    }
    for (Edge edge : edges) {
        if (!usedEdges.contains(edge)) {
            graph.removeEdge(edge);
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GenericDijkstra(org.opentripplanner.routing.algorithm.GenericDijkstra) GraphPath(org.opentripplanner.routing.spt.GraphPath) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) TraverseMode(org.opentripplanner.routing.core.TraverseMode) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) EarliestArrival(org.opentripplanner.routing.spt.DominanceFunction.EarliestArrival) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 43 with GraphPath

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

the class GraphVisualizer method verticesSelected.

public void verticesSelected(final List<Vertex> selected) {
    // sort vertices by name
    Collections.sort(selected, new Comparator<Vertex>() {

        @Override
        public int compare(Vertex arg0, Vertex arg1) {
            return arg0.getLabel().compareTo(arg1.getLabel());
        }
    });
    ListModel<DisplayVertex> data = new VertexList(selected);
    nearbyVertices.setModel(data);
    // pick out an intersection vertex and find the path
    // if the spt is already available
    Vertex target = null;
    for (Vertex vv : selected) {
        if (vv instanceof IntersectionVertex) {
            target = vv;
            break;
        }
    }
    if (target != null && spt != null) {
        List<GraphPath> paths = spt.getPaths(target, true);
        showPathsInPanel(paths);
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GraphPath(org.opentripplanner.routing.spt.GraphPath)

Example 44 with GraphPath

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

the class GraphVisualizer method showPathsInPanel.

private void showPathsInPanel(List<GraphPath> paths) {
    // show paths in a list panel
    DefaultListModel<PathPrinter> data = new DefaultListModel<PathPrinter>();
    for (GraphPath gp : paths) {
        data.addElement(new PathPrinter(gp));
    }
    pathsList.setModel(data);
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath)

Example 45 with GraphPath

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

the class GraphPathToTripPlanConverterTest method testEmptyGraphPath.

/**
 * Test that empty graph paths throw a TrivialPathException
 */
@Test(expected = TrivialPathException.class)
public void testEmptyGraphPath() {
    RoutingRequest options = new RoutingRequest();
    Graph graph = new Graph();
    ExitVertex vertex = new ExitVertex(graph, "Vertex", 0, 0, 0);
    options.rctx = new RoutingContext(options, graph, vertex, vertex);
    GraphPath graphPath = new GraphPath(new State(options), false);
    GraphPathToTripPlanConverter.generateItinerary(graphPath, false, false, locale);
}
Also used : ExitVertex(org.opentripplanner.routing.vertextype.ExitVertex) RoutingContext(org.opentripplanner.routing.core.RoutingContext) Graph(org.opentripplanner.routing.graph.Graph) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

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