Search in sources :

Example 66 with Graph

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

the class GraphPathToTripPlanConverterTest method testLegSwitchOnlyGraphPath.

/**
 * Test that graph paths with only null and LEG_SWITCH modes throw a TrivialPathException
 */
@Test(expected = TrivialPathException.class)
public void testLegSwitchOnlyGraphPath() {
    RoutingRequest options = new RoutingRequest();
    Graph graph = new Graph();
    ExitVertex start = new ExitVertex(graph, "Start", 0, -90, 0);
    ExitVertex middle = new ExitVertex(graph, "Middle", 0, 0, 0);
    ExitVertex end = new ExitVertex(graph, "End", 0, 90, 0);
    FreeEdge depart = new FreeEdge(start, middle);
    LegSwitchingEdge arrive = new LegSwitchingEdge(middle, end);
    options.rctx = new RoutingContext(options, graph, start, end);
    State intermediate = depart.traverse(new State(options));
    GraphPath graphPath = new GraphPath(arrive.traverse(intermediate), false);
    GraphPathToTripPlanConverter.generateItinerary(graphPath, false, false, locale);
}
Also used : ExitVertex(org.opentripplanner.routing.vertextype.ExitVertex) LegSwitchingEdge(org.opentripplanner.routing.edgetype.LegSwitchingEdge) 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) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Test(org.junit.Test)

Example 67 with Graph

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

Example 68 with Graph

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

the class TriangleInequalityTest method onlyOnce.

@BeforeClass
public static void onlyOnce() throws Exception {
    extra = new HashMap<Class<?>, Object>();
    _graph = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
    File file = new File(URLDecoder.decode(TriangleInequalityTest.class.getResource("NYC_small.osm.gz").getFile(), "UTF-8"));
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(_graph, extra);
    // Need to set up the index because buildGraph doesn't do it.
    _graph.rebuildVertexAndEdgeIndices();
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) BeforeClass(org.junit.BeforeClass) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 69 with Graph

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

the class GtfsGraphBuilderModuleTest method testNoBikesByDefault.

@Test
public void testNoBikesByDefault() throws IOException {
    // We configure two trip: one with unknown bikes_allowed and the second with bikes
    // allowed.
    MockGtfs gtfs = getSimpleGtfs();
    gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,1");
    gtfs.putStopTimes("t0,t1", "s0,s1");
    List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
    bundleList.get(0).setDefaultBikesAllowed(false);
    _builder = new GtfsModule(bundleList);
    Graph graph = new Graph();
    _builder.buildGraph(graph, _extra);
    graph.index(new DefaultStreetVertexIndexFactory());
    // Feed id is used instead of the agency id for OBA entities.
    GtfsBundle gtfsBundle = bundleList.get(0);
    GtfsFeedId feedId = gtfsBundle.getFeedId();
    Trip trip = graph.index.tripForId.get(new AgencyAndId(feedId.getId(), "t0"));
    TripPattern pattern = graph.index.patternForTrip.get(trip);
    List<Trip> trips = pattern.getTrips();
    assertEquals(BikeAccess.UNKNOWN, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t0"))));
    assertEquals(BikeAccess.ALLOWED, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t1"))));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Test(org.junit.Test)

Example 70 with Graph

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

the class TestStreetMatcher method before.

@Before
public void before() {
    _graph = new Graph();
    vertex("56th_24th", 47.669457, -122.387577);
    vertex("56th_22nd", 47.669462, -122.384739);
    vertex("56th_20th", 47.669457, -122.382106);
    vertex("market_24th", 47.668690, -122.387577);
    vertex("market_ballard", 47.668683, -122.386096);
    vertex("market_22nd", 47.668686, -122.384749);
    vertex("market_leary", 47.668669, -122.384392);
    vertex("market_russell", 47.668655, -122.382997);
    vertex("market_20th", 47.668684, -122.382117);
    vertex("shilshole_24th", 47.668419, -122.387534);
    vertex("shilshole_22nd", 47.666519, -122.384744);
    vertex("shilshole_vernon", 47.665938, -122.384048);
    vertex("shilshole_20th", 47.664356, -122.382192);
    vertex("ballard_turn", 47.668509, -122.386069);
    vertex("ballard_22nd", 47.667624, -122.384744);
    vertex("ballard_vernon", 47.666422, -122.383158);
    vertex("ballard_20th", 47.665476, -122.382128);
    vertex("leary_vernon", 47.666863, -122.382353);
    vertex("leary_20th", 47.666682, -122.382160);
    vertex("russell_20th", 47.667846, -122.382128);
    edges("56th_24th", "56th_22nd", "56th_20th");
    edges("56th_24th", "market_24th");
    edges("56th_22nd", "market_22nd");
    edges("56th_20th", "market_20th");
    edges("market_24th", "market_ballard", "market_22nd", "market_leary", "market_russell", "market_20th");
    edges("market_24th", "shilshole_24th", "shilshole_22nd", "shilshole_vernon", "shilshole_20th");
    edges("market_ballard", "ballard_turn", "ballard_22nd", "ballard_vernon", "ballard_20th");
    edges("market_leary", "leary_vernon", "leary_20th");
    edges("market_russell", "russell_20th");
    edges("market_22nd", "ballard_22nd", "shilshole_22nd");
    edges("leary_vernon", "ballard_vernon", "shilshole_vernon");
    edges("market_20th", "russell_20th", "leary_20th", "ballard_20th", "shilshole_20th");
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) Before(org.junit.Before)

Aggregations

Graph (org.opentripplanner.routing.graph.Graph)105 Test (org.junit.Test)39 File (java.io.File)28 Vertex (org.opentripplanner.routing.graph.Vertex)27 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)24 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)20 Edge (org.opentripplanner.routing.graph.Edge)19 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)14 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)14 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)13 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)13 GTFSPatternHopFactory (org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory)13 GraphPath (org.opentripplanner.routing.spt.GraphPath)13 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)13 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)11 ArrayList (java.util.ArrayList)10 Before (org.junit.Before)10 Trip (org.onebusaway.gtfs.model.Trip)9