use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class TestOpenStreetMapGraphBuilder method testBuildGraphDetailed.
/**
* Detailed testing of OSM graph building using a very small chunk of NYC (SOHO-ish).
* @throws Exception
*/
@Test
public void testBuildGraphDetailed() 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("NYC_small.osm.gz").getFile(), "UTF-8"));
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(gg, extra);
// These vertices are labeled in the OSM file as having traffic lights.
IntersectionVertex iv1 = (IntersectionVertex) gg.getVertex("osm:node:1919595918");
IntersectionVertex iv2 = (IntersectionVertex) gg.getVertex("osm:node:42442273");
IntersectionVertex iv3 = (IntersectionVertex) gg.getVertex("osm:node:1919595927");
IntersectionVertex iv4 = (IntersectionVertex) gg.getVertex("osm:node:42452026");
assertTrue(iv1.trafficLight);
assertTrue(iv2.trafficLight);
assertTrue(iv3.trafficLight);
assertTrue(iv4.trafficLight);
// These are not.
IntersectionVertex iv5 = (IntersectionVertex) gg.getVertex("osm:node:42435485");
IntersectionVertex iv6 = (IntersectionVertex) gg.getVertex("osm:node:42439335");
IntersectionVertex iv7 = (IntersectionVertex) gg.getVertex("osm:node:42436761");
IntersectionVertex iv8 = (IntersectionVertex) gg.getVertex("osm:node:42442291");
assertFalse(iv5.trafficLight);
assertFalse(iv6.trafficLight);
assertFalse(iv7.trafficLight);
assertFalse(iv8.trafficLight);
Set<P2<Integer>> edgeEndpoints = new HashSet<P2<Integer>>();
for (StreetEdge se : gg.getStreetEdges()) {
P2<Integer> endpoints = new P2<Integer>(se.getFromVertex().getIndex(), se.getToVertex().getIndex());
// Check that we don't get any duplicate edges on this small graph.
if (edgeEndpoints.contains(endpoints)) {
assertFalse(true);
}
edgeEndpoints.add(endpoints);
}
}
use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class TestUnconnectedAreas method testUnconnectedParkAndRide.
/**
* The P+R.osm.gz file contains 2 park and ride, one a single way area and the other a
* multipolygon with a hole. Both are not linked to any street, apart from three roads that
* crosses the P+R with w/o common nodes.
*
* This test just make sure we correctly link those P+R with the street network by creating
* virtual nodes at the place where the street intersects the P+R areas. See ticket #1562.
*/
@Test
public void testUnconnectedParkAndRide() throws Exception {
Graph gg = new Graph();
OpenStreetMapModule loader = new OpenStreetMapModule();
loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
File file = new File(getClass().getResource("P+R.osm.gz").getFile());
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(gg, new HashMap<Class<?>, Object>());
assertEquals(1, gg.getBuilderAnnotations().size());
int nParkAndRide = 0;
int nParkAndRideLink = 0;
for (Vertex v : gg.getVertices()) {
if (v instanceof ParkAndRideVertex) {
nParkAndRide++;
}
}
for (Edge e : gg.getEdges()) {
if (e instanceof ParkAndRideLinkEdge) {
nParkAndRideLink++;
}
}
assertEquals(2, nParkAndRide);
assertEquals(10, nParkAndRideLink);
}
use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class TestUnconnectedAreas method testGeometricGraphWithClasspathFile.
/**
* We've written several OSM files that exhibit different situations but should show the same results. Test with this code.
*/
public List<String> testGeometricGraphWithClasspathFile(String fn, int prCount, int prlCount) {
Graph g = new Graph();
OpenStreetMapModule loader = new OpenStreetMapModule();
loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
File file = new File(getClass().getResource(fn).getFile());
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(g, new HashMap<Class<?>, Object>());
Vertex pr = null;
int nParkAndRide = 0;
int nParkAndRideLink = 0;
for (Vertex v : g.getVertices()) {
if (v instanceof ParkAndRideVertex) {
nParkAndRide++;
pr = v;
}
}
for (Edge e : g.getEdges()) {
if (e instanceof ParkAndRideLinkEdge) {
nParkAndRideLink++;
}
}
assertEquals(prCount, nParkAndRide);
assertEquals(prlCount, nParkAndRideLink);
assertNotNull(pr);
// make sure it is connected
List<String> connections = new ArrayList<String>();
for (Edge e : pr.getOutgoing()) {
if (e instanceof ParkAndRideEdge)
continue;
assertTrue(e instanceof ParkAndRideLinkEdge);
connections.add(e.getToVertex().getLabel());
}
// symmetry
for (Edge e : pr.getIncoming()) {
if (e instanceof ParkAndRideEdge)
continue;
assertTrue(e instanceof ParkAndRideLinkEdge);
assertTrue(connections.contains(e.getFromVertex().getLabel()));
}
return connections;
}
use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class TestUnconnectedAreas method testCoincidentNodeUnconnectedParkAndRide.
/**
* This test ensures that if a Park and Ride has a node that is exactly atop a node on a way, the graph
* builder will not loop forever trying to split it. The hackett-pr.osm.gz file contains a park-and-ride lot in
* Hackettstown, NJ, which demonstrates this behavior. See discussion in ticket 1605.
*/
@Test
public void testCoincidentNodeUnconnectedParkAndRide() throws Exception {
Graph g = new Graph();
OpenStreetMapModule loader = new OpenStreetMapModule();
loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
FileBasedOpenStreetMapProviderImpl provider = new FileBasedOpenStreetMapProviderImpl();
File file = new File(getClass().getResource("hackett_pr.osm.gz").getFile());
provider.setPath(file);
loader.setProvider(provider);
loader.buildGraph(g, new HashMap<Class<?>, Object>());
Vertex washTwp = null;
int nParkAndRide = 0;
int nParkAndRideLink = 0;
for (Vertex v : g.getVertices()) {
if (v instanceof ParkAndRideVertex) {
nParkAndRide++;
washTwp = v;
}
}
for (Edge e : g.getEdges()) {
if (e instanceof ParkAndRideLinkEdge) {
nParkAndRideLink++;
}
}
assertEquals(1, nParkAndRide);
// the P+R should get four connections, since the entrance road is duplicated as well, and crosses twice
// since there are in and out edges, that brings the total to 8 per P+R.
// Even though the park and rides get merged, duplicate edges remain from when they were separate.
// FIXME: we shouldn't have duplicate edges.
assertEquals(16, nParkAndRideLink);
assertNotNull(washTwp);
List<String> connections = new ArrayList<String>();
for (Edge e : washTwp.getOutgoing()) {
if (e instanceof ParkAndRideEdge)
continue;
assertTrue(e instanceof ParkAndRideLinkEdge);
connections.add(e.getToVertex().getLabel());
}
// symmetry
for (Edge e : washTwp.getIncoming()) {
if (e instanceof ParkAndRideEdge)
continue;
assertTrue(e instanceof ParkAndRideLinkEdge);
assertTrue(connections.contains(e.getFromVertex().getLabel()));
}
assertTrue(connections.contains("osm:node:3096570222"));
assertTrue(connections.contains("osm:node:3094264704"));
assertTrue(connections.contains("osm:node:3094264709"));
assertTrue(connections.contains("osm:node:3096570227"));
}
use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class AddTripPatternTest method testStopLinking.
/**
* Make sure that stops are properly linked into the graph
*/
@Test
public void testStopLinking() throws Exception {
AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
atp.timetables.add(getTimetable(true));
// get a graph
Graph g = buildGraphNoTransit();
link(g);
g.index(new DefaultStreetVertexIndexFactory());
// materialize the trip pattern
atp.materialize(g);
// there should be five stops because one point is not a stop
assertEquals(5, atp.temporaryStops.length);
// they should all be linked into the graph
for (int i = 0; i < atp.temporaryStops.length; i++) {
assertNotNull(atp.temporaryStops[i].sample);
assertNotNull(atp.temporaryStops[i].sample.v0);
assertNotNull(atp.temporaryStops[i].sample.v1);
}
// no services running: not needed for trips added on the fly.
TimeWindow window = new TimeWindow(7 * 3600, 9 * 3600, new BitSet(), DayOfWeek.WEDNESDAY);
Scenario scenario = new Scenario(0);
scenario.modifications = Lists.newArrayList(atp);
ProfileRequest req = new ProfileRequest();
req.scenario = scenario;
req.boardingAssumption = RaptorWorkerTimetable.BoardingAssumption.WORST_CASE;
RaptorWorkerData data = new RaptorWorkerData(g, window, req);
assertEquals(5, data.nStops);
// make sure we can find the stops
AStar aStar = new AStar();
RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
rr.from = new GenericLocation(39.963417, -82.980799);
rr.batch = true;
rr.setRoutingContext(g);
rr.batch = true;
ShortestPathTree spt = aStar.getShortestPathTree(rr);
TIntIntMap stops = data.findStopsNear(spt, g, false, 1.3f);
// we should have found stops
assertFalse(stops.isEmpty());
// ensure that the times made it into the data
// This assumes worst-case departure, and the first worst departure is 10:30 after the service
// starts running (dwell + headway)
assertEquals(4 * 3600 + 600 + 30, data.timetablesForPattern.get(0).getFrequencyDeparture(0, 0, 39 * 360, -1, null));
}
Aggregations