Search in sources :

Example 1 with StopTreeCache

use of org.opentripplanner.profile.StopTreeCache 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 (TransitStop ts : Iterables.filter(g1.getVertices(), TransitStop.class)) {
        Collection<Edge> stls = stls(ts.getOutgoing());
        assertTrue(stls.size() >= 1);
        StreetTransitLink exemplar = (StreetTransitLink) stls.iterator().next();
        TransitStop other = (TransitStop) g2.getVertex(ts.getLabel());
        Collection<Edge> ostls = stls(other.getOutgoing());
        assertEquals("Unequal number of links from stop " + ts, stls.size(), ostls.size());
        StreetTransitLink oe = (StreetTransitLink) ostls.iterator().next();
        assertEquals(exemplar.getToVertex().getLat(), oe.getToVertex().getLat(), 1e-10);
        assertEquals(exemplar.getToVertex().getLon(), oe.getToVertex().getLon(), 1e-10);
    }
    // compare the stop tree caches
    g1.index(new DefaultStreetVertexIndexFactory());
    g2.index(new DefaultStreetVertexIndexFactory());
    g1.rebuildVertexAndEdgeIndices();
    g2.rebuildVertexAndEdgeIndices();
    StopTreeCache s1 = g1.index.getStopTreeCache();
    StopTreeCache s2 = g2.index.getStopTreeCache();
    // convert the caches to be by stop label
    Map<String, int[]> l1 = cacheByLabel(s1);
    Map<String, int[]> l2 = cacheByLabel(s2);
    // do the comparison
    for (Entry<String, int[]> e : l1.entrySet()) {
        // graph 2 should contain all stops in graph 1 (and a few more)
        assertTrue(l2.containsKey(e.getKey()));
        TObjectIntMap<String> g1t = jaggedArrayToVertexMap(e.getValue(), g1);
        TObjectIntMap<String> g2t = jaggedArrayToVertexMap(l2.get(e.getKey()), g2);
        for (TObjectIntIterator<String> it = g1t.iterator(); it.hasNext(); ) {
            it.advance();
            assertTrue(g2t.containsKey(it.key()));
            int newv = g2t.get(it.key());
            assertTrue("At " + it.key() + " from stop " + g1.getVertex(e.getKey()) + ", difference in walk distances: " + it.value() + "m without extra stops," + newv + "m with", Math.abs(it.value() - newv) <= EPSILON);
        }
    }
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) LineString(com.vividsolutions.jts.geom.LineString) StopTreeCache(org.opentripplanner.profile.StopTreeCache) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Aggregations

LineString (com.vividsolutions.jts.geom.LineString)1 Test (org.junit.Test)1 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)1 StopTreeCache (org.opentripplanner.profile.StopTreeCache)1 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)1 StreetTransitLink (org.opentripplanner.routing.edgetype.StreetTransitLink)1 Edge (org.opentripplanner.routing.graph.Edge)1 Graph (org.opentripplanner.routing.graph.Graph)1 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)1 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)1