use of org.opentripplanner.routing.vertextype.ParkAndRideVertex in project OpenTripPlanner by opentripplanner.
the class TestParkAndRide method testCar.
public void testCar() throws Exception {
AStar aStar = new AStar();
// It is impossible to get from A to C in WALK mode,
RoutingRequest options = new RoutingRequest(new TraverseModeSet("WALK"));
options.setRoutingContext(graph, A, C);
ShortestPathTree tree = aStar.getShortestPathTree(options);
GraphPath path = tree.getPath(C, false);
assertNull(path);
// or CAR+WALK (no P+R).
options = new RoutingRequest("WALK,CAR");
options.freezeTraverseMode();
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNull(path);
// So we Add a P+R at B.
ParkAndRideVertex PRB = new ParkAndRideVertex(graph, "P+R", "P+R.B", 0.001, 45.00001, new NonLocalizedString("P+R B"));
new ParkAndRideEdge(PRB);
new ParkAndRideLinkEdge(PRB, B);
new ParkAndRideLinkEdge(B, PRB);
// But it is still impossible to get from A to C by WALK only
// (AB is CAR only).
options = new RoutingRequest("WALK");
options.freezeTraverseMode();
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNull(path);
// Or CAR only (BC is WALK only).
options = new RoutingRequest("CAR");
options.freezeTraverseMode();
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy false
options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
// options.arriveBy
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNotNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy true
options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
options.setArriveBy(true);
options.setRoutingContext(graph, A, C);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(A, false);
assertNotNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy true interleavedBidiHeuristic
options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
options.setArriveBy(true);
options.setRoutingContext(graph, A, C);
options.rctx.remainingWeightHeuristic = new InterleavedBidirectionalHeuristic();
tree = aStar.getShortestPathTree(options);
path = tree.getPath(A, false);
assertNotNull(path);
// But we can go from A to C with CAR+WALK mode using P+R. arriveBy false interleavedBidiHeuristic
options = new RoutingRequest("WALK,CAR_PARK,TRANSIT");
// options.arriveBy
options.setRoutingContext(graph, A, C);
options.rctx.remainingWeightHeuristic = new InterleavedBidirectionalHeuristic();
tree = aStar.getShortestPathTree(options);
path = tree.getPath(C, false);
assertNotNull(path);
}
use of org.opentripplanner.routing.vertextype.ParkAndRideVertex 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.vertextype.ParkAndRideVertex 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.vertextype.ParkAndRideVertex 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"));
}
Aggregations