use of org.opentripplanner.routing.graph.Vertex 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.Vertex 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.Vertex 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);
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class TestShapefileStreetGraphBuilderImpl method testBasic.
@Test
public void testBasic() throws Exception {
Graph gg = new Graph();
URL resource = getClass().getResource("nyc_streets/streets.shp");
File file = null;
if (resource != null) {
file = new File(resource.getFile());
}
if (file == null || !file.exists()) {
System.out.println("No New York City basemap; skipping; see comment here for details");
/*
* This test requires the New York City base map. Place it among the source
* resources and Eclipse should automatically copy it over to the target directory.
* Once you have prepared these files, you may need to 'refresh' in Eclipse's package
* explorer to force Eclipse to notice the new resources.
*
* Recent versions of this map are available only in Arcview Geodatabase format.
* For conversion to a Shapefile, you will need the archived MapInfo version at:
* http://www.nyc.gov/html/dcp/html/bytes/bytesarchive.shtml#lion
* Download the MapInfo file of Lion version 10B.
*
* This must then be converted to a ShapeFile as follows:
* cd opentripplanner-graph-builder/src/test/resources/org/opentripplanner/graph_builder/module/shapefile
* mkdir nyc_streets (this is where we will store the shapefile)
* unzip nyc_lion10ami.zip (this should place zipfile contents in a ./lion directory)
* ogr2ogr -f 'ESRI Shapefile' nyc_streets/streets.shp lion/MNLION1.tab
* ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/SILION1.tab -nln streets
* ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/QNLION1.tab -nln streets
* ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/BKLION1.tab -nln streets
* ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/BXLION1.tab -nln streets
*
* Testing also requires NYC Subway data in GTFS in the same location:
* wget http://data.topplabs.org/data/mta_nyct_subway/subway.zip
*/
return;
}
ShapefileFeatureSourceFactoryImpl factory = new ShapefileFeatureSourceFactoryImpl(file);
ShapefileStreetSchema schema = new ShapefileStreetSchema();
schema.setIdAttribute("SegmentID");
schema.setNameAttribute("Street");
/* only featuretyp=0 are streets */
CaseBasedBooleanConverter selector = new CaseBasedBooleanConverter("FeatureTyp", false);
HashMap<String, Boolean> streets = new HashMap<String, Boolean>();
streets.put("0", true);
selector.setValues(streets);
schema.setFeatureSelector(selector);
/* street directions */
CaseBasedTraversalPermissionConverter perms = new CaseBasedTraversalPermissionConverter("TrafDir", StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
perms.addPermission("W", StreetTraversalPermission.ALL, StreetTraversalPermission.PEDESTRIAN);
perms.addPermission("A", StreetTraversalPermission.PEDESTRIAN, StreetTraversalPermission.ALL);
perms.addPermission("T", StreetTraversalPermission.ALL, StreetTraversalPermission.ALL);
schema.setPermissionConverter(perms);
ShapefileStreetModule loader = new ShapefileStreetModule();
loader.setFeatureSourceFactory(factory);
loader.setSchema(schema);
loader.buildGraph(gg, new HashMap<Class<?>, Object>());
// find start and end vertices
Vertex start = null;
Vertex end = null;
Vertex carlton = null;
Coordinate vanderbiltAtPark = new Coordinate(-73.969178, 40.676785);
Coordinate grandAtLafayette = new Coordinate(-73.999095, 40.720005);
Coordinate carltonAtPark = new Coordinate(-73.972347, 40.677447);
for (Vertex v : gg.getVertices()) {
if (v.getCoordinate().distance(vanderbiltAtPark) < 0.00005) {
/* we need the correct vanderbilt at park. In this case,
* that's the one facing west on vanderbilt.
*/
int numParks = 0;
int numCarltons = 0;
for (Edge e : v.getOutgoing()) {
if (e.getToVertex().getName().contains("PARK")) {
numParks++;
}
if (e.getToVertex().getName().contains("CARLTON")) {
numCarltons++;
}
}
if (numCarltons != 2 || numParks != 1) {
continue;
}
start = v;
} else if (v.getCoordinate().distance(grandAtLafayette) < 0.0001) {
end = v;
} else if (v.getCoordinate().distance(carltonAtPark) < 0.00005) {
/* we need the correct carlton at park. In this case,
* that's the one facing west.
*/
int numFlatbushes = 0;
int numParks = 0;
for (Edge e : v.getOutgoing()) {
if (e.getToVertex().getName().contains("FLATBUSH")) {
numFlatbushes++;
}
if (e.getToVertex().getName().contains("PARK")) {
numParks++;
}
}
if (numFlatbushes != 2 || numParks != 1) {
continue;
}
carlton = v;
}
}
assertNotNull(start);
assertNotNull(end);
assertNotNull(carlton);
assertEquals(3, start.getDegreeOut());
assertEquals(3, start.getDegreeIn());
AStar aStar = new AStar();
RoutingRequest opt = new RoutingRequest();
opt.setRoutingContext(gg, start, end);
ShortestPathTree spt = aStar.getShortestPathTree(opt);
assertNotNull(spt);
// test that the option to walk bikes on the first or last segment works
opt = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
// Real live cyclists tell me that they would prefer to ride around the long way than to
// walk their bikes the short way. If we slow down the default biking speed, that will
// force a change in preferences.
opt.bikeSpeed = 2;
opt.setRoutingContext(gg, start, carlton);
spt = aStar.getShortestPathTree(opt);
assertNotNull(spt);
/* commented out as bike walking is not supported */
/*
GraphPath path = spt.getPath(carlton.vertex);
assertNotNull(path);
assertTrue(path.edges.size() <= 3);
wo.setArriveBy(true);
spt = AStar.getShortestPathTreeBack(gg, start.vertex, carlton.vertex, new State(0), wo);
assertNotNull(spt);
path = spt.getPath(carlton.vertex);
assertTrue(path.edges.size() <= 3);
*/
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class AlertPatchTest method testStopAlertPatch.
public void testStopAlertPatch() {
AlertPatch snp1 = new AlertPatch();
snp1.setFeedId(feedId);
snp1.setTimePeriods(Collections.singletonList(new TimePeriod(0, // until ~1/1/2011
1000L * 60 * 60 * 24 * 365 * 40)));
Alert note1 = Alert.createSimpleAlerts("The first note");
snp1.setAlert(note1);
snp1.setId("id1");
snp1.setStop(new AgencyAndId(feedId, "A"));
snp1.apply(graph);
Vertex stop_a = graph.getVertex(feedId + ":A");
Vertex stop_e = graph.getVertex(feedId + ":E_arrive");
ShortestPathTree spt;
GraphPath optimizedPath, unoptimizedPath;
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
options.setRoutingContext(graph, stop_a, stop_e);
spt = aStar.getShortestPathTree(options);
optimizedPath = spt.getPath(stop_e, true);
unoptimizedPath = spt.getPath(stop_e, false);
assertNotNull(optimizedPath);
HashSet<Alert> expectedAlerts = new HashSet<Alert>();
expectedAlerts.add(note1);
Edge optimizedEdge = optimizedPath.states.get(1).getBackEdge();
HashSet<Alert> optimizedAlerts = new HashSet<Alert>();
for (AlertPatch alertPatch : graph.getAlertPatches(optimizedEdge)) {
optimizedAlerts.add(alertPatch.getAlert());
}
assertEquals(expectedAlerts, optimizedAlerts);
Edge unoptimizedEdge = unoptimizedPath.states.get(1).getBackEdge();
HashSet<Alert> unoptimizedAlerts = new HashSet<Alert>();
for (AlertPatch alertPatch : graph.getAlertPatches(unoptimizedEdge)) {
unoptimizedAlerts.add(alertPatch.getAlert());
}
assertEquals(expectedAlerts, unoptimizedAlerts);
}
Aggregations