Search in sources :

Example 41 with Graph

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

the class PlatformLinkerTest method testLinkEntriesToPlatforms.

/**
 * Test linking from stairs endpoint to to nodes in the ring defining the platform area.
 * OSM test data is from Skøyen station, Norway
 */
@Test
public void testLinkEntriesToPlatforms() throws Exception {
    String stairsEndpointLabel = "osm:node:1028861028";
    List<String> platformRingVertexLabels = Arrays.asList("osm:node:304045332", "osm:node:3238357455", "osm:node:1475363433", "osm:node:3238357491", "osm:node:1475363427", "osm:node:304045336", "osm:node:304045337", "osm:node:1475363437", "osm:node:3238357483", "osm:node:1475363443", "osm:node:1028860941", "osm:node:304045341", "osm:node:304045332");
    Graph gg = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.platformEntriesLinking = true;
    loader.skipVisibility = true;
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    AnyFileBasedOpenStreetMapProviderImpl provider = new AnyFileBasedOpenStreetMapProviderImpl();
    File file = new File(URLDecoder.decode(FakeGraph.class.getResource("osm/skoyen.osm.pbf").getFile(), "UTF-8"));
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(gg, new HashMap<>());
    Vertex stairsEndpoint = gg.getVertex(stairsEndpointLabel);
    // verify outgoing links
    List<String> linkedRingVertecies = stairsEndpoint.getOutgoing().stream().map(edge -> edge.getToVertex().getLabel()).collect(Collectors.toList());
    // the endpoint has links to two nodes in OSM
    assertEquals(linkedRingVertecies.size() - 2, platformRingVertexLabels.size());
    for (String label : platformRingVertexLabels) {
        assert (linkedRingVertecies.contains(label));
    }
    // verify incoming links
    List<String> linkedRingVerteciesInn = stairsEndpoint.getIncoming().stream().map(edge -> edge.getFromVertex().getLabel()).collect(Collectors.toList());
    // the endpoint has links to two nodes in OSM
    assertEquals(linkedRingVerteciesInn.size() - 2, platformRingVertexLabels.size());
    for (String label : platformRingVertexLabels) {
        assert (linkedRingVerteciesInn.contains(label));
    }
}
Also used : Arrays(java.util.Arrays) List(java.util.List) URLDecoder(java.net.URLDecoder) Graph(org.opentripplanner.routing.graph.Graph) Vertex(org.opentripplanner.routing.graph.Vertex) Test(org.junit.Test) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) File(java.io.File) Assert.assertEquals(org.junit.Assert.assertEquals) AnyFileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.AnyFileBasedOpenStreetMapProviderImpl) Vertex(org.opentripplanner.routing.graph.Vertex) Graph(org.opentripplanner.routing.graph.Graph) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) AnyFileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.AnyFileBasedOpenStreetMapProviderImpl) File(java.io.File) Test(org.junit.Test)

Example 42 with Graph

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

the class TestOpenStreetMapGraphBuilder method testBuildingAreas.

/**
 * This reads test file with area
 * and tests if it can be routed if visibility is used and if it isn't
 *
 * Routing needs to be successful in both options since without visibility calculation
 * area rings are used.
 * @param skipVisibility if true visibility calculations are skipped
 * @throws UnsupportedEncodingException
 */
private void testBuildingAreas(boolean skipVisibility) throws UnsupportedEncodingException {
    Graph gg = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.skipVisibility = skipVisibility;
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
    File file = new File(URLDecoder.decode(getClass().getResource("usf_area.osm.gz").getFile(), "UTF-8"));
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(gg, extra);
    new StreetVertexIndexServiceImpl(gg);
    OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
    otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("A", gg));
    Router a = otpServer.getGraphService().getRouter("A");
    RoutingRequest request = new RoutingRequest("WALK");
    // This are vertices that can be connected only over edges on area (with correct permissions)
    // It tests if it is possible to route over area without visibility calculations
    Vertex bottomV = gg.getVertex("osm:node:580290955");
    Vertex topV = gg.getVertex("osm:node:559271124");
    request.setRoutingContext(a.graph, bottomV, topV);
    GraphPathFinder graphPathFinder = new GraphPathFinder(a);
    List<GraphPath> pathList = graphPathFinder.graphPathFinderEntryPoint(request);
    assertNotNull(pathList);
    assertFalse(pathList.isEmpty());
    for (GraphPath path : pathList) {
        assertFalse(path.states.isEmpty());
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) GraphPath(org.opentripplanner.routing.spt.GraphPath) Router(org.opentripplanner.standalone.Router) GraphService(org.opentripplanner.routing.services.GraphService) Graph(org.opentripplanner.routing.graph.Graph) OTPServer(org.opentripplanner.standalone.OTPServer) MemoryGraphSource(org.opentripplanner.routing.impl.MemoryGraphSource) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) File(java.io.File) GraphPathFinder(org.opentripplanner.routing.impl.GraphPathFinder) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl)

Example 43 with Graph

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

the class TestOpenStreetMapGraphBuilder method testGraphBuilder.

@Test
public void testGraphBuilder() throws Exception {
    Graph gg = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
    File file = new File(URLDecoder.decode(getClass().getResource("map.osm.gz").getFile(), "UTF-8"));
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(gg, extra);
    // Kamiennogorska at south end of segment
    Vertex v1 = gg.getVertex("osm:node:280592578");
    // Kamiennogorska at Mariana Smoluchowskiego
    Vertex v2 = gg.getVertex("osm:node:288969929");
    // Mariana Smoluchowskiego, north end
    Vertex v3 = gg.getVertex("osm:node:280107802");
    // Mariana Smoluchowskiego, south end (of segment connected to v2)
    Vertex v4 = gg.getVertex("osm:node:288970952");
    assertNotNull(v1);
    assertNotNull(v2);
    assertNotNull(v3);
    assertNotNull(v4);
    Edge e1 = null, e2 = null, e3 = null;
    for (Edge e : v2.getOutgoing()) {
        if (e.getToVertex() == v1) {
            e1 = e;
        } else if (e.getToVertex() == v3) {
            e2 = e;
        } else if (e.getToVertex() == v4) {
            e3 = e;
        }
    }
    assertNotNull(e1);
    assertNotNull(e2);
    assertNotNull(e3);
    assertTrue("name of e1 must be like \"Kamiennog\u00F3rska\"; was " + e1.getName(), e1.getName().contains("Kamiennog\u00F3rska"));
    assertTrue("name of e2 must be like \"Mariana Smoluchowskiego\"; was " + e2.getName(), e2.getName().contains("Mariana Smoluchowskiego"));
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Graph(org.opentripplanner.routing.graph.Graph) FileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.FileBasedOpenStreetMapProviderImpl) File(java.io.File) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 44 with Graph

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

the class StateEditorTest method testSetNonTransitOptionsFromState.

/**
 * Test update of non transit options.
 */
@Test
public final void testSetNonTransitOptionsFromState() {
    RoutingRequest request = new RoutingRequest();
    request.setMode(TraverseMode.CAR);
    request.parkAndRide = true;
    Graph graph = new Graph();
    graph.streetIndex = new StreetVertexIndexServiceImpl(graph);
    request.rctx = new RoutingContext(request, graph);
    State state = new State(request);
    state.stateData.carParked = true;
    state.stateData.bikeParked = true;
    state.stateData.usingRentedBike = false;
    state.stateData.nonTransitMode = TraverseMode.WALK;
    StateEditor se = new StateEditor(request, null);
    se.setNonTransitOptionsFromState(state);
    State updatedState = se.makeState();
    assertEquals(TraverseMode.WALK, updatedState.getNonTransitMode());
    assertEquals(true, updatedState.isCarParked());
    assertEquals(true, updatedState.isBikeParked());
    assertEquals(false, updatedState.isBikeRenting());
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) StreetVertexIndexServiceImpl(org.opentripplanner.routing.impl.StreetVertexIndexServiceImpl) Test(org.junit.Test)

Example 45 with Graph

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

the class TestIgnoreRealtimeUpdates method testIgnoreRealtimeUpdates.

public void testIgnoreRealtimeUpdates() throws Exception {
    // Create routing request
    RoutingRequest options = new RoutingRequest();
    // Check that realtime updates are not ignored
    assertFalse(options.ignoreRealtimeUpdates);
    // Create (very simple) new graph
    Graph graph = new Graph();
    Stop stop1 = new Stop();
    stop1.setId(new AgencyAndId("agency", "stop1"));
    Stop stop2 = new Stop();
    stop2.setId(new AgencyAndId("agency", "stop2"));
    Vertex from = new TransitStop(graph, stop1);
    Vertex to = new TransitStop(graph, stop2);
    // Create dummy TimetableSnapshot
    TimetableSnapshot snapshot = new TimetableSnapshot();
    // Mock TimetableSnapshotSource to return dummy TimetableSnapshot
    TimetableSnapshotSource source = mock(TimetableSnapshotSource.class);
    when(source.getTimetableSnapshot()).thenReturn(snapshot);
    graph.timetableSnapshotSource = (source);
    // Create routing context
    RoutingContext rctx = new RoutingContext(options, graph, from, to);
    // Check that the resolver is set as timetable snapshot
    assertNotNull(rctx.timetableSnapshot);
    // Now set routing request to ignore realtime updates
    options.ignoreRealtimeUpdates = (true);
    // Check that realtime updates are ignored
    assertTrue(options.ignoreRealtimeUpdates);
    // Create new routing context
    rctx = new RoutingContext(options, graph, from, to);
    // Check that the timetable snapshot is null in the new routing context
    assertNull(rctx.timetableSnapshot);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TimetableSnapshot(org.opentripplanner.routing.edgetype.TimetableSnapshot) TimetableSnapshotSource(org.opentripplanner.updater.stoptime.TimetableSnapshotSource)

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