Search in sources :

Example 11 with TransitStopVertex

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

the class TestHalfEdges method setUp.

@Before
public void setUp() {
    graph = new Graph();
    // a 0.1 degree x 0.1 degree square
    tl = new IntersectionVertex(graph, "tl", -74.01, 40.01);
    tr = new IntersectionVertex(graph, "tr", -74.0, 40.01);
    bl = new IntersectionVertex(graph, "bl", -74.01, 40.0);
    br = new IntersectionVertex(graph, "br", -74.00, 40.0);
    top = new StreetEdge(tl, tr, GeometryUtils.makeLineString(-74.01, 40.01, -74.0, 40.01), "top", 1500, StreetTraversalPermission.ALL, false);
    bottom = new StreetEdge(br, bl, GeometryUtils.makeLineString(-74.01, 40.0, -74.0, 40.0), "bottom", 1500, StreetTraversalPermission.ALL, false);
    left = new StreetEdge(bl, tl, GeometryUtils.makeLineString(-74.01, 40.0, -74.01, 40.01), "left", 1500, StreetTraversalPermission.ALL, false);
    right = new StreetEdge(br, tr, GeometryUtils.makeLineString(-74.0, 40.0, -74.0, 40.01), "right", 1500, StreetTraversalPermission.PEDESTRIAN, false);
    @SuppressWarnings("unused") StreetEdge topBack = new StreetEdge(tr, tl, (LineString) top.getGeometry().reverse(), "topBack", 1500, StreetTraversalPermission.ALL, true);
    @SuppressWarnings("unused") StreetEdge bottomBack = new StreetEdge(br, bl, (LineString) bottom.getGeometry().reverse(), "bottomBack", 1500, StreetTraversalPermission.ALL, true);
    leftBack = new StreetEdge(tl, bl, (LineString) left.getGeometry().reverse(), "leftBack", 1500, StreetTraversalPermission.ALL, true);
    rightBack = new StreetEdge(tr, br, (LineString) right.getGeometry().reverse(), "rightBack", 1500, StreetTraversalPermission.ALL, true);
    Stop s1 = Stop.stopForTest("fleem station", 40.0099999, -74.005);
    Stop s2 = Stop.stopForTest("morx station", 40.0099999, -74.002);
    station1 = new TransitStopVertex(graph, s1, null);
    station2 = new TransitStopVertex(graph, s2, null);
    station1.addMode(TransitMode.RAIL);
    station2.addMode(TransitMode.RAIL);
    // Linkers aren't run otherwise in testNetworkLinker
    graph.hasStreets = true;
    graph.hasTransit = true;
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) LineString(org.locationtech.jts.geom.LineString) Stop(org.opentripplanner.model.Stop) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Before(org.junit.Before)

Example 12 with TransitStopVertex

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

the class TestGraphPath method testGraphPathOptimize.

public void testGraphPathOptimize() {
    String feedId = graph.getFeedIds().iterator().next();
    Vertex stop_a = graph.getVertex(feedId + ":A");
    Vertex stop_c = graph.getVertex(feedId + ":C");
    Vertex stop_e = graph.getVertex(feedId + ":E");
    ShortestPathTree spt;
    GraphPath path;
    RoutingRequest options = new RoutingRequest();
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
    options.setRoutingContext(graph, stop_a.getLabel(), stop_e.getLabel());
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(stop_e, false);
    /* do not optimize yet, since we are testing optimization */
    assertNotNull(path);
    // Check that the resulting path visits the stops in the right order.
    List<Vertex> stopvs = Lists.newArrayList();
    for (State state : path.states) {
        if (state.getVertex() instanceof TransitStopVertex) {
            stopvs.add(state.getVertex());
        }
    }
    assertTrue(stopvs.get(0) == stop_a);
    assertTrue(stopvs.get(1) == stop_c);
    assertTrue(stopvs.get(2) == stop_e);
    long bestStart = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 20, 0);
    assertNotSame(bestStart, path.getStartTime());
    path = spt.getPath(stop_e, true);
    /* optimize */
    assertEquals(bestStart, path.getStartTime());
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest)

Example 13 with TransitStopVertex

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

the class FakeGraph method addExtraStops.

/**
 * add some extra stops to the graph
 */
public static void addExtraStops(Graph g) {
    int count = 0;
    double lon = -83;
    for (double lat = 40; lat < 40.01; lat += 0.005) {
        String id = "EXTRA_" + count++;
        Stop stop = Stop.stopForTest(id, lat, lon);
        new TransitStopVertex(g, stop, null);
    }
    // add some duplicate stops, identical to the regular stop grid
    lon = -83.1341 + 0.1;
    for (double lat = 39.9058; lat < 40.0281; lat += 0.005) {
        String id = "DUPE_" + count++;
        Stop stop = Stop.stopForTest(id, lat, lon);
        new TransitStopVertex(g, stop, null);
    }
    // add some almost duplicate stops
    lon = -83.1341 + 0.15;
    for (double lat = 39.9059; lat < 40.0281; lat += 0.005) {
        String id = "ALMOST_" + count++;
        Stop stop = Stop.stopForTest(id, lat, lon);
        new TransitStopVertex(g, stop, null);
    }
}
Also used : Stop(org.opentripplanner.model.Stop) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex)

Example 14 with TransitStopVertex

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

the class FakeGraph method addRegularStopGrid.

/**
 * Add a regular grid of stops to the graph
 */
public static void addRegularStopGrid(Graph g) {
    int count = 0;
    for (double lat = 39.9058; lat < 40.0281; lat += 0.005) {
        for (double lon = -83.1341; lon < -82.8646; lon += 0.005) {
            String id = Integer.toString(count++);
            Stop stop = Stop.stopForTest(id, lat, lon);
            new TransitStopVertex(g, stop, null);
        }
    }
}
Also used : Stop(org.opentripplanner.model.Stop) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex)

Example 15 with TransitStopVertex

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

the class LinkingTest method testStopsLinkedIdentically.

/**
 * Test that all the stops are linked identically
 * to the street network on two builds of similar graphs
 * with additional stops in one.
 *
 * We do this by building the graphs and then comparing the stop tree caches.
 */
@Test
public void testStopsLinkedIdentically() throws UnsupportedEncodingException {
    // build the graph without the added stops
    Graph g1 = buildGraphNoTransit();
    addRegularStopGrid(g1);
    link(g1);
    Graph g2 = buildGraphNoTransit();
    addExtraStops(g2);
    addRegularStopGrid(g2);
    link(g2);
    // compare the linkages
    for (TransitStopVertex ts : Iterables.filter(g1.getVertices(), TransitStopVertex.class)) {
        List<StreetTransitLink> stls1 = outgoingStls(ts);
        assertTrue(stls1.size() >= 1);
        TransitStopVertex other = (TransitStopVertex) g2.getVertex(ts.getLabel());
        List<StreetTransitLink> stls2 = outgoingStls(other);
        assertEquals("Unequal number of links from stop " + ts, stls1.size(), stls2.size());
        for (int i = 0; i < stls1.size(); i++) {
            Vertex v1 = stls1.get(i).getToVertex();
            Vertex v2 = stls2.get(i).getToVertex();
            assertEquals(v1.getLat(), v2.getLat(), 1e-10);
            assertEquals(v1.getLon(), v2.getLon(), 1e-10);
        }
    }
}
Also used : TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) SplitterVertex(org.opentripplanner.routing.vertextype.SplitterVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Test(org.junit.Test)

Aggregations

TransitStopVertex (org.opentripplanner.routing.vertextype.TransitStopVertex)28 Stop (org.opentripplanner.model.Stop)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)8 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)8 ArrayList (java.util.ArrayList)7 Coordinate (org.locationtech.jts.geom.Coordinate)7 Envelope (org.locationtech.jts.geom.Envelope)7 Graph (org.opentripplanner.routing.graph.Graph)7 LineString (org.locationtech.jts.geom.LineString)6 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)5 StreetTransitLink (org.opentripplanner.routing.edgetype.StreetTransitLink)5 Iterables (com.google.common.collect.Iterables)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)4 BikeRentalStationVertex (org.opentripplanner.routing.vertextype.BikeRentalStationVertex)4 SplitterVertex (org.opentripplanner.routing.vertextype.SplitterVertex)4 LinearLocation (org.locationtech.jts.linearref.LinearLocation)3 LocationIndexedLine (org.locationtech.jts.linearref.LocationIndexedLine)3