turns.add(left);
turns.add(leftBack);
StreetLocation start = StreetLocation.createStreetLocation(graph, "start", "start",
filter(turns, StreetEdge.class),
new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()));
HashSet<Edge> endTurns = new HashSet<Edge>();
endTurns.add(right);
endTurns.add(rightBack);
StreetLocation end = StreetLocation.createStreetLocation(graph, "end", "end",
filter(endTurns, StreetEdge.class),
new LinearLocation(0, 0.8).getCoordinate(right.getGeometry()));
assertTrue(start.getX() < end.getX());
assertTrue(start.getY() < end.getY());
List<Edge> extra = end.getExtra();
assertEquals(4, extra.size());
long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
options.dateTime = startTime;
options.setRoutingContext(graph, br, end);
options.setMaxWalkDistance(Double.MAX_VALUE);
ShortestPathTree spt1 = aStar.getShortestPathTree(options);
GraphPath pathBr = spt1.getPath(end, false);
assertNotNull("There must be a path from br to end", pathBr);
options.setRoutingContext(graph, tr, end);
ShortestPathTree spt2 = aStar.getShortestPathTree(options);
GraphPath pathTr = spt2.getPath(end, false);
assertNotNull("There must be a path from tr to end", pathTr);
assertTrue("path from bottom to end must be longer than path from top to end",
pathBr.getWeight() > pathTr.getWeight());
options.setRoutingContext(graph, start, end);
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(end, false);
assertNotNull("There must be a path from start to end", path);
// the bottom is not part of the shortest path
for (State s : path.states) {
assertNotSame(s.getVertex(), graph.getVertex("bottom"));
assertNotSame(s.getVertex(), graph.getVertex("bottomBack"));
}
options.setArriveBy(true);
options.setRoutingContext(graph, start, end);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(start, false);
assertNotNull("There must be a path from start to end (looking back)", path);
// the bottom edge is not part of the shortest path
for (State s : path.states) {
assertNotSame(s.getVertex(), graph.getVertex("bottom"));
assertNotSame(s.getVertex(), graph.getVertex("bottomBack"));
}
// Number of vertices and edges should be the same as before after a cleanup.
options.cleanup();
assertEquals(nVertices, graph.getVertices().size());
assertEquals(nEdges, graph.getEdges().size());
/*
* Now, the right edge is not bikeable. But the user can walk their bike. So here are some tests that prove (a) that walking bikes works, but
* that (b) it is not preferred to riding a tiny bit longer.
*/
options = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
start = StreetLocation.createStreetLocation(graph, "start1", "start1",
filter(turns, StreetEdge.class),
new LinearLocation(0, 0.95).getCoordinate(top.getGeometry()));
end = StreetLocation.createStreetLocation(graph, "end1", "end1",
filter(turns, StreetEdge.class),
new LinearLocation(0, 0.95).getCoordinate(bottom.getGeometry()));
options.setRoutingContext(graph, start, end);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(start, false);
assertNotNull("There must be a path from top to bottom along the right", path);
// the left edge is not part of the shortest path (even though the bike must be walked along the right)
for (State s : path.states) {
assertNotSame(s.getVertex(), graph.getVertex("left"));
assertNotSame(s.getVertex(), graph.getVertex("leftBack"));
}
// Number of vertices and edges should be the same as before after a cleanup.
options.cleanup();
assertEquals(nVertices, graph.getVertices().size());
assertEquals(nEdges, graph.getEdges().size());
start = StreetLocation.createStreetLocation(graph, "start2", "start2",
filter(turns, StreetEdge.class),
new LinearLocation(0, 0.55).getCoordinate(top.getGeometry()));
end = StreetLocation.createStreetLocation(graph, "end2", "end2",
filter(turns, StreetEdge.class),
new LinearLocation(0, 0.55).getCoordinate(bottom.getGeometry()));
options.setRoutingContext(graph, start, end);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(start, false);