use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestUnroutable method testOnBoardRouting.
/**
* Search for a path across the Willamette river. This OSM data includes a bridge that is not yet built and is
* therefore tagged highway=construction.
* TODO also test unbuilt, proposed, raceways etc.
*/
public void testOnBoardRouting() throws Exception {
RoutingRequest options = new RoutingRequest();
Vertex from = graph.getVertex("osm:node:2003617278");
Vertex to = graph.getVertex("osm:node:40446276");
options.setRoutingContext(graph, from, to);
options.setMode(TraverseMode.BICYCLE);
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(to, false);
// is filtered out, thus the null check.
if (path != null) {
for (Edge edge : path.edges) {
assertFalse("Path should not use the as-yet unbuilt Tilikum Crossing bridge.", "Tilikum Crossing".equals(edge.getName()));
}
}
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TriangleInequalityTest method checkTriangleInequality.
private void checkTriangleInequality(TraverseModeSet traverseModes) {
assertNotNull(start);
assertNotNull(end);
RoutingRequest prototypeOptions = new RoutingRequest();
// All reluctance terms are 1.0 so that duration is monotonically increasing in weight.
prototypeOptions.stairsReluctance = (1.0);
prototypeOptions.setWalkReluctance(1.0);
prototypeOptions.turnReluctance = (1.0);
prototypeOptions.carSpeed = 1.0;
prototypeOptions.walkSpeed = 1.0;
prototypeOptions.bikeSpeed = 1.0;
prototypeOptions.traversalCostModel = (new ConstantIntersectionTraversalCostModel(10.0));
prototypeOptions.dominanceFunction = new DominanceFunction.EarliestArrival();
if (traverseModes != null) {
prototypeOptions.setModes(traverseModes);
}
RoutingRequest options = prototypeOptions.clone();
options.setRoutingContext(_graph, start, end);
AStar aStar = new AStar();
ShortestPathTree tree = aStar.getShortestPathTree(options);
GraphPath path = tree.getPath(end, false);
options.cleanup();
assertNotNull(path);
double startEndWeight = path.getWeight();
int startEndDuration = path.getDuration();
assertTrue(startEndWeight > 0);
assertEquals(startEndWeight, (double) startEndDuration, 1.0 * path.edges.size());
// Try every vertex in the graph as an intermediate.
boolean violated = false;
for (Vertex intermediate : _graph.getVertices()) {
if (intermediate == start || intermediate == end) {
continue;
}
GraphPath startIntermediatePath = getPath(aStar, prototypeOptions, null, start, intermediate);
if (startIntermediatePath == null) {
continue;
}
Edge back = startIntermediatePath.states.getLast().getBackEdge();
GraphPath intermediateEndPath = getPath(aStar, prototypeOptions, back, intermediate, end);
if (intermediateEndPath == null) {
continue;
}
double startIntermediateWeight = startIntermediatePath.getWeight();
int startIntermediateDuration = startIntermediatePath.getDuration();
double intermediateEndWeight = intermediateEndPath.getWeight();
int intermediateEndDuration = intermediateEndPath.getDuration();
// TODO(flamholz): fix traversal so that there's no rounding at the second resolution.
assertEquals(startIntermediateWeight, (double) startIntermediateDuration, 1.0 * startIntermediatePath.edges.size());
assertEquals(intermediateEndWeight, (double) intermediateEndDuration, 1.0 * intermediateEndPath.edges.size());
double diff = startIntermediateWeight + intermediateEndWeight - startEndWeight;
if (diff < -0.01) {
System.out.println("Triangle inequality violated - diff = " + diff);
violated = true;
}
// assertTrue(startIntermediateDuration + intermediateEndDuration >=
// startEndDuration);
}
assertFalse(violated);
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TriangleInequalityTest method getPath.
private GraphPath getPath(AStar aStar, RoutingRequest proto, Edge startBackEdge, Vertex u, Vertex v) {
RoutingRequest options = proto.clone();
options.setRoutingContext(_graph, startBackEdge, u, v);
ShortestPathTree tree = aStar.getShortestPathTree(options);
GraphPath path = tree.getPath(v, false);
options.cleanup();
return path;
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestHalfEdges method testHalfEdges.
@Test
public void testHalfEdges() {
// the shortest half-edge from the start vertex takes you down, but the shortest total path
// is up and over
int nVertices = graph.getVertices().size();
int nEdges = graph.getEdges().size();
RoutingRequest options = new RoutingRequest();
HashSet<Edge> turns = new HashSet<Edge>();
turns.add(left);
turns.add(leftBack);
TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
HashSet<Edge> endTurns = new HashSet<Edge>();
endTurns.add(right);
endTurns.add(rightBack);
TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end", new NonLocalizedString("end"), filter(endTurns, StreetEdge.class), new LinearLocation(0, 0.8).getCoordinate(right.getGeometry()), true);
assertTrue(start.getX() < end.getX());
assertTrue(start.getY() < end.getY());
Collection<Edge> edges = end.getIncoming();
assertEquals(2, edges.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 = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start1", new NonLocalizedString("start1"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.95).getCoordinate(top.getGeometry()), false);
end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end1", new NonLocalizedString("end1"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.95).getCoordinate(bottom.getGeometry()), true);
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 = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start2", new NonLocalizedString("start2"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.55).getCoordinate(top.getGeometry()), false);
end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end2", new NonLocalizedString("end2"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.55).getCoordinate(bottom.getGeometry()), true);
options.setRoutingContext(graph, start, end);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(start, false);
assertNotNull("There must be a path from top to bottom", path);
// the right edge is not part of the shortest path, e
for (State s : path.states) {
assertNotSame(s.getVertex(), graph.getVertex("right"));
assertNotSame(s.getVertex(), graph.getVertex("rightBack"));
}
// 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());
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestHalfEdges method testStreetLocationFinder.
@Test
public void testStreetLocationFinder() {
StreetVertexIndexServiceImpl finder = new StreetVertexIndexServiceImpl(graph);
// test that the local stop finder finds stops
GenericLocation loc = new GenericLocation(40.01, -74.005000001);
assertTrue(finder.getNearbyTransitStops(loc.getCoordinate(), 100).size() > 0);
// test that the closest vertex finder returns the closest vertex
TemporaryStreetLocation some = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.00, -74.00), null, true);
assertNotNull(some);
some.dispose();
// test that the closest vertex finder correctly splits streets
TemporaryStreetLocation start = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.004, -74.01), null, false);
assertNotNull(start);
assertTrue("wheelchair accessibility is correctly set (splitting)", start.isWheelchairAccessible());
Collection<Edge> edges = start.getOutgoing();
start.dispose();
assertEquals(2, edges.size());
RoutingRequest biking = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
TemporaryStreetLocation end = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.008, -74.0), biking, true);
assertNotNull(end);
edges = end.getIncoming();
end.dispose();
assertEquals(2, edges.size());
// test that it is possible to travel between two splits on the same street
RoutingRequest walking = new RoutingRequest(TraverseMode.WALK);
start = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.004, -74.0), walking, false);
exception.expect(TrivialPathException.class);
end = (TemporaryStreetLocation) finder.getVertexForLocation(new GenericLocation(40.008, -74.0), walking, true);
/*assertNotNull(end);
// The visibility for temp edges for start and end is set in the setRoutingContext call
walking.setRoutingContext(graph, start, end);
ShortestPathTree spt = aStar.getShortestPathTree(walking);
GraphPath path = spt.getPath(end, false);
for (State s : path.states) {
assertFalse(s.getBackEdge() == top);
}
walking.cleanup();*/
}
Aggregations