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));
}
}
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());
}
}
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"));
}
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());
}
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);
}
Aggregations