* @throws Exception
*/
@Test
public void testBuildGraphDetailed() throws Exception {
Graph gg = new Graph();
OpenStreetMapGraphBuilderImpl loader = new OpenStreetMapGraphBuilderImpl();
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);
StreetTraversalPermission perm = se.getPermission();
// CAR and CUSTOM_MOTOR_VEHICLE should always have the same permissions.
assertEquals(perm.allows(StreetTraversalPermission.CAR),
perm.allows(StreetTraversalPermission.CUSTOM_MOTOR_VEHICLE));
// Check turn restriction consistency.
// NOTE(flamholz): currently there don't appear to be any turn restrictions
// in the OSM file we are loading.
for (TurnRestriction tr : gg.getTurnRestrictions(se)) {
// All turn restrictions should apply equally to
// CAR and CUSTOM_MOTOR_VEHICLE.
TraverseModeSet modes = tr.modes;
assertEquals(modes.getCar(), modes.getCustomMotorVehicle());
}