Search in sources :

Example 36 with IntersectionVertex

use of org.opentripplanner.routing.vertextype.IntersectionVertex in project OpenTripPlanner by opentripplanner.

the class TestPatternHopFactory method setUp.

public void setUp() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    feedId = context.getFeedId().getId();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    String[] stops = { feedId + ":A", feedId + ":B", feedId + ":C", feedId + ":D", feedId + ":E", feedId + ":entrance_a", feedId + ":entrance_b" };
    for (int i = 0; i < stops.length; ++i) {
        TransitStop stop = (TransitStop) (graph.getVertex(stops[i]));
        IntersectionVertex front = new IntersectionVertex(graph, "near_1_" + stop.getStopId(), stop.getX() + 0.0001, stop.getY() + 0.0001);
        IntersectionVertex back = new IntersectionVertex(graph, "near_2_" + stop.getStopId(), stop.getX() - 0.0001, stop.getY() - 0.0001);
        StreetEdge street1 = new StreetEdge(front, back, GeometryUtils.makeLineString(stop.getX() + 0.0001, stop.getY() + 0.0001, stop.getX() - 0.0001, stop.getY() - 0.0001), "street", 100, StreetTraversalPermission.ALL, false);
        StreetEdge street2 = new StreetEdge(back, front, GeometryUtils.makeLineString(stop.getX() - 0.0001, stop.getY() - 0.0001, stop.getX() + 0.0001, stop.getY() + 0.0001), "street", 100, StreetTraversalPermission.ALL, true);
    }
    StreetLinkerModule ttsnm = new StreetLinkerModule();
    // Linkers aren't run otherwise
    graph.hasStreets = true;
    graph.hasTransit = true;
    ttsnm.buildGraph(graph, new HashMap<Class<?>, Object>());
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) File(java.io.File) StreetLinkerModule(org.opentripplanner.graph_builder.module.StreetLinkerModule)

Example 37 with IntersectionVertex

use of org.opentripplanner.routing.vertextype.IntersectionVertex in project OpenTripPlanner by opentripplanner.

the class GraphServiceTest method setUp.

@Override
protected void setUp() throws IOException {
    // Ensure a dummy disk location exists
    basePath = new File("test_graphs");
    if (!basePath.exists())
        basePath.mkdir();
    // Create an empty graph and it's serialized form
    emptyGraph = new Graph();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    emptyGraph.save(new ObjectOutputStream(baos));
    emptyGraphData = baos.toByteArray();
    // Create a small graph with 2 vertices and one edge and it's serialized form
    smallGraph = new Graph();
    StreetVertex v1 = new IntersectionVertex(smallGraph, "v1", 0, 0);
    StreetVertex v2 = new IntersectionVertex(smallGraph, "v2", 0, 0.1);
    new StreetEdge(v1, v2, null, "v1v2", 11000, StreetTraversalPermission.PEDESTRIAN, false);
    baos = new ByteArrayOutputStream();
    smallGraph.save(new ObjectOutputStream(baos));
    smallGraphData = baos.toByteArray();
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 38 with IntersectionVertex

use of org.opentripplanner.routing.vertextype.IntersectionVertex in project OpenTripPlanner by opentripplanner.

the class TestOverlayGraph method testBasic.

public void testBasic() throws Exception {
    Graph g = new Graph();
    Vertex a = new IntersectionVertex(g, "a", 5, 5);
    Vertex b = new IntersectionVertex(g, "b", 6, 5);
    Vertex c = new IntersectionVertex(g, "c", 7, 5);
    Vertex d = new IntersectionVertex(g, "d", 8, 5);
    // vary weights so edges are not considered equal
    Edge ab = new SimpleEdge(a, b, 1, 1);
    Edge bc1 = new SimpleEdge(b, c, 1, 1);
    Edge bc2 = new SimpleEdge(b, c, 2, 2);
    Edge bc3 = new SimpleEdge(b, c, 3, 3);
    Edge cd1 = new SimpleEdge(c, d, 1, 1);
    Edge cd2 = new SimpleEdge(c, d, 2, 2);
    Edge cd3 = new SimpleEdge(c, d, 3, 3);
    OverlayGraph og = new OverlayGraph(g);
    assertEquals(g.countVertices(), og.countVertices());
    assertEquals(g.countEdges(), og.countEdges());
    for (Vertex v : g.getVertices()) {
        for (Edge e : v.getOutgoing()) {
            assertTrue(og.getOutgoing(v).contains(e));
            assertTrue(og.getIncoming(e.getToVertex()).contains(e));
        }
        for (Edge e : v.getIncoming()) {
            assertTrue(og.getIncoming(v).contains(e));
            assertTrue(og.getOutgoing(e.getFromVertex()).contains(e));
        }
    }
    assertTrue(og.getIncoming(a).size() == 0);
    assertTrue(og.getOutgoing(d).size() == 0);
    // add an edge that is not in the overlay
    Edge ad = new FreeEdge(a, d);
    assertTrue(d.getIncoming().size() == 4);
    assertTrue(og.getIncoming(d).size() == 3);
    assertTrue(a.getOutgoing().size() == 2);
    assertTrue(og.getOutgoing(a).size() == 1);
    // remove edges from overlaygraph
    og.removeEdge(bc1);
    og.removeEdge(bc2);
    assertEquals(og.countEdges(), g.countEdges() - 3);
    assertTrue(og.getOutgoing(b).size() == 1);
    assertTrue(og.getIncoming(c).size() == 1);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) SimpleEdge(org.opentripplanner.routing.edgetype.SimpleEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) SimpleEdge(org.opentripplanner.routing.edgetype.SimpleEdge) Edge(org.opentripplanner.routing.graph.Edge)

Aggregations

IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)38 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)23 Graph (org.opentripplanner.routing.graph.Graph)17 Coordinate (com.vividsolutions.jts.geom.Coordinate)16 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)14 Vertex (org.opentripplanner.routing.graph.Vertex)12 LineString (com.vividsolutions.jts.geom.LineString)10 Test (org.junit.Test)10 Edge (org.opentripplanner.routing.graph.Edge)10 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)8 HashSet (java.util.HashSet)8 FreeEdge (org.opentripplanner.routing.edgetype.FreeEdge)8 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)5 ArrayList (java.util.ArrayList)5 Point (com.vividsolutions.jts.geom.Point)4 P2 (org.opentripplanner.common.model.P2)4 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)4 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)3 State (org.opentripplanner.routing.core.State)3 AreaEdge (org.opentripplanner.routing.edgetype.AreaEdge)3