Search in sources :

Example 46 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class CheckGeometryModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    for (Vertex gv : graph.getVertices()) {
        if (Double.isNaN(gv.getCoordinate().x) || Double.isNaN(gv.getCoordinate().y)) {
            LOG.warn("Vertex " + gv + " has NaN location; this will cause doom.");
            LOG.warn(graph.addBuilderAnnotation(new BogusVertexGeometry(gv)));
        }
        // TODO: This was filtered to EdgeNarratives before EdgeNarrative removal
        for (Edge e : gv.getOutgoing()) {
            Geometry g = e.getGeometry();
            if (g == null) {
                continue;
            }
            for (Coordinate c : g.getCoordinates()) {
                if (Double.isNaN(c.x) || Double.isNaN(c.y)) {
                    LOG.warn(graph.addBuilderAnnotation(new BogusEdgeGeometry(e)));
                }
            }
            if (e instanceof HopEdge) {
                Coordinate edgeStartCoord = e.getFromVertex().getCoordinate();
                Coordinate edgeEndCoord = e.getToVertex().getCoordinate();
                Coordinate[] geometryCoordinates = g.getCoordinates();
                if (geometryCoordinates.length < 2) {
                    LOG.warn(graph.addBuilderAnnotation(new BogusEdgeGeometry(e)));
                    continue;
                }
                Coordinate geometryStartCoord = geometryCoordinates[0];
                Coordinate geometryEndCoord = geometryCoordinates[geometryCoordinates.length - 1];
                if (SphericalDistanceLibrary.distance(edgeStartCoord, geometryStartCoord) > MAX_VERTEX_SHAPE_ERROR) {
                    LOG.warn(graph.addBuilderAnnotation(new VertexShapeError(e)));
                } else if (SphericalDistanceLibrary.distance(edgeEndCoord, geometryEndCoord) > MAX_VERTEX_SHAPE_ERROR) {
                    LOG.warn(graph.addBuilderAnnotation(new VertexShapeError(e)));
                }
            }
        }
    }
}
Also used : BogusEdgeGeometry(org.opentripplanner.graph_builder.annotation.BogusEdgeGeometry) BogusVertexGeometry(org.opentripplanner.graph_builder.annotation.BogusVertexGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) Vertex(org.opentripplanner.routing.graph.Vertex) HopEdge(org.opentripplanner.routing.edgetype.HopEdge) Coordinate(com.vividsolutions.jts.geom.Coordinate) BogusEdgeGeometry(org.opentripplanner.graph_builder.annotation.BogusEdgeGeometry) VertexShapeError(org.opentripplanner.graph_builder.annotation.VertexShapeError) HopEdge(org.opentripplanner.routing.edgetype.HopEdge) Edge(org.opentripplanner.routing.graph.Edge) BogusVertexGeometry(org.opentripplanner.graph_builder.annotation.BogusVertexGeometry)

Example 47 with Vertex

use of org.opentripplanner.routing.graph.Vertex 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)

Example 48 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class TriangleInequalityTest method checkTriangleInequality.

private void checkTriangleInequality(TraverseModeSet traverseModes) {
    assertNotNull(start);
    assertNotNull(end);
    RoutingRequest prototypeOptions = new RoutingRequest();
    // All reluctance terms are 1.0 so that duration is monotonically increasing in weight.
    prototypeOptions.stairsReluctance = (1.0);
    prototypeOptions.setWalkReluctance(1.0);
    prototypeOptions.turnReluctance = (1.0);
    prototypeOptions.carSpeed = 1.0;
    prototypeOptions.walkSpeed = 1.0;
    prototypeOptions.bikeSpeed = 1.0;
    prototypeOptions.traversalCostModel = (new ConstantIntersectionTraversalCostModel(10.0));
    prototypeOptions.dominanceFunction = new DominanceFunction.EarliestArrival();
    if (traverseModes != null) {
        prototypeOptions.setModes(traverseModes);
    }
    RoutingRequest options = prototypeOptions.clone();
    options.setRoutingContext(_graph, start, end);
    AStar aStar = new AStar();
    ShortestPathTree tree = aStar.getShortestPathTree(options);
    GraphPath path = tree.getPath(end, false);
    options.cleanup();
    assertNotNull(path);
    double startEndWeight = path.getWeight();
    int startEndDuration = path.getDuration();
    assertTrue(startEndWeight > 0);
    assertEquals(startEndWeight, (double) startEndDuration, 1.0 * path.edges.size());
    // Try every vertex in the graph as an intermediate.
    boolean violated = false;
    for (Vertex intermediate : _graph.getVertices()) {
        if (intermediate == start || intermediate == end) {
            continue;
        }
        GraphPath startIntermediatePath = getPath(aStar, prototypeOptions, null, start, intermediate);
        if (startIntermediatePath == null) {
            continue;
        }
        Edge back = startIntermediatePath.states.getLast().getBackEdge();
        GraphPath intermediateEndPath = getPath(aStar, prototypeOptions, back, intermediate, end);
        if (intermediateEndPath == null) {
            continue;
        }
        double startIntermediateWeight = startIntermediatePath.getWeight();
        int startIntermediateDuration = startIntermediatePath.getDuration();
        double intermediateEndWeight = intermediateEndPath.getWeight();
        int intermediateEndDuration = intermediateEndPath.getDuration();
        // TODO(flamholz): fix traversal so that there's no rounding at the second resolution.
        assertEquals(startIntermediateWeight, (double) startIntermediateDuration, 1.0 * startIntermediatePath.edges.size());
        assertEquals(intermediateEndWeight, (double) intermediateEndDuration, 1.0 * intermediateEndPath.edges.size());
        double diff = startIntermediateWeight + intermediateEndWeight - startEndWeight;
        if (diff < -0.01) {
            System.out.println("Triangle inequality violated - diff = " + diff);
            violated = true;
        }
    // assertTrue(startIntermediateDuration + intermediateEndDuration >=
    // startEndDuration);
    }
    assertFalse(violated);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) AStar(org.opentripplanner.routing.algorithm.AStar) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) ConstantIntersectionTraversalCostModel(org.opentripplanner.routing.core.ConstantIntersectionTraversalCostModel) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction) Edge(org.opentripplanner.routing.graph.Edge)

Example 49 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testNetworkLinker.

@Test
public void testNetworkLinker() {
    int numVerticesBefore = graph.getVertices().size();
    StreetLinkerModule ttsnm = new StreetLinkerModule();
    ttsnm.buildGraph(graph, new HashMap<Class<?>, Object>());
    int numVerticesAfter = graph.getVertices().size();
    assertEquals(4, numVerticesAfter - numVerticesBefore);
    Collection<Edge> outgoing = station1.getOutgoing();
    assertTrue(outgoing.size() == 2);
    Edge edge = outgoing.iterator().next();
    Vertex midpoint = edge.getToVertex();
    assertTrue(Math.abs(midpoint.getCoordinate().y - 40.01) < 0.00000001);
    outgoing = station2.getOutgoing();
    assertTrue(outgoing.size() == 2);
    edge = outgoing.iterator().next();
    Vertex station2point = edge.getToVertex();
    assertTrue(Math.abs(station2point.getCoordinate().x - -74.002) < 0.00000001);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 50 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class TestBanning method testBannedRoutes.

public void testBannedRoutes() {
    Graph graph = ConstantsForTests.getInstance().getPortlandGraph();
    String feedId = graph.getFeedIds().iterator().next();
    RoutingRequest options = new RoutingRequest();
    Vertex start = graph.getVertex(feedId + ":8371");
    Vertex end = graph.getVertex(feedId + ":8374");
    options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 12, 34, 25);
    // must set routing context _after_ options is fully configured (time)
    options.setRoutingContext(graph, start, end);
    ShortestPathTree spt = null;
    /*
         * The MAX Red, Blue, and Green lines all run along the same trackage between the stops 8374 and 8371. Together, they form the white line. No,
         * wait, that's light. They make a pretty good test case for banned routes, since if one is banned, you can always take another.
         */
    String[][] maxLines = { { "MAX Red Line", null }, { "MAX Blue Line", null }, { "MAX Green Line", null }, { null, "90" }, { null, "100" }, { null, "200" } };
    for (int i = 0; i < maxLines.length; ++i) {
        String lineName = maxLines[i][0];
        String lineId = maxLines[i][1];
        String routeSpecStr = feedId + "_" + (lineName != null ? lineName : "") + (lineId != null ? "_" + lineId : "");
        options.setBannedRoutes(routeSpecStr);
        spt = aStar.getShortestPathTree(options);
        GraphPath path = spt.getPath(end, true);
        for (State s : path.states) {
            if (s.getBackEdge() instanceof PatternHop) {
                PatternHop e = (PatternHop) s.getBackEdge();
                Route route = e.getPattern().route;
                assertFalse(options.bannedRoutes.matches(route));
                boolean foundMaxLine = false;
                for (int j = 0; j < maxLines.length; ++j) {
                    if (j != i) {
                        if (e.getName().equals(maxLines[j][0])) {
                            foundMaxLine = true;
                        }
                    }
                }
                assertTrue(foundMaxLine);
            }
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route)

Aggregations

Vertex (org.opentripplanner.routing.graph.Vertex)143 Edge (org.opentripplanner.routing.graph.Edge)63 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)45 GraphPath (org.opentripplanner.routing.spt.GraphPath)39 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)35 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)34 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)32 Graph (org.opentripplanner.routing.graph.Graph)29 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)28 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)24 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 State (org.opentripplanner.routing.core.State)20 Stop (org.onebusaway.gtfs.model.Stop)18 LineString (com.vividsolutions.jts.geom.LineString)16 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 Trip (org.onebusaway.gtfs.model.Trip)12 Envelope (com.vividsolutions.jts.geom.Envelope)11