use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestHalfEdges method testRouteToSameEdge.
@Test
public void testRouteToSameEdge() {
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);
TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end", new NonLocalizedString("end"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.8).getCoordinate(left.getGeometry()), true);
assertEquals(start.getX(), end.getX(), 0.0001);
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, start, end);
options.setMaxWalkDistance(Double.MAX_VALUE);
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(end, false);
assertNotNull("There must be a path from start to end", path);
assertEquals(1, path.edges.size());
options.cleanup();
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class TestHalfEdges method testRouteToSameEdgeBackwards.
@Test
public void testRouteToSameEdgeBackwards() {
RoutingRequest options = new RoutingRequest();
// Sits only on the leftmost edge, not on its reverse.
HashSet<Edge> turns = new HashSet<Edge>();
turns.add(left);
TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.8).getCoordinate(left.getGeometry()), false);
TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end", new NonLocalizedString("end"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), true);
assertEquals(start.getX(), end.getX(), 0.001);
assertTrue(start.getY() > end.getY());
Collection<Edge> edges = end.getIncoming();
assertEquals(1, edges.size());
long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
options.dateTime = startTime;
options.setRoutingContext(graph, start, end);
options.setMaxWalkDistance(Double.MAX_VALUE);
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(end, false);
assertNotNull("There must be a path from start to end", path);
assertTrue(path.edges.size() > 1);
options.cleanup();
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class AStarTest method testBack.
@Test
public void testBack() {
RoutingRequest options = new RoutingRequest();
options.walkSpeed = 1.0;
options.setArriveBy(true);
options.setRoutingContext(_graph, _graph.getVertex("56th_24th"), _graph.getVertex("leary_20th"));
ShortestPathTree tree = new AStar().getShortestPathTree(options);
GraphPath path = tree.getPath(_graph.getVertex("56th_24th"), false);
List<State> states = path.states;
assertTrue(states.size() == 6 || states.size() == 7);
assertEquals("56th_24th", states.get(0).getVertex().getLabel());
int n;
// we could go either way around the block formed by 56th, 22nd, market, and 24th.
if (states.size() == 7) {
assertEquals("market_24th", states.get(1).getVertex().getLabel());
assertEquals("market_ballard", states.get(2).getVertex().getLabel());
n = 0;
} else {
assertEquals("56th_22nd", states.get(1).getVertex().getLabel());
n = -1;
}
assertEquals("market_22nd", states.get(n + 3).getVertex().getLabel());
assertEquals("market_leary", states.get(n + 4).getVertex().getLabel());
assertEquals("leary_vernon", states.get(n + 5).getVertex().getLabel());
assertEquals("leary_20th", states.get(n + 6).getVertex().getLabel());
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class AStarTest method testForwardExtraEdges.
@Test
public void testForwardExtraEdges() {
RoutingRequest options = new RoutingRequest();
options.walkSpeed = 1.0;
TemporaryStreetLocation from = new TemporaryStreetLocation("near_shilshole_22nd", new Coordinate(-122.385050, 47.666620), new NonLocalizedString("near_shilshole_22nd"), false);
new TemporaryConcreteEdge(from, _graph.getVertex("shilshole_22nd"));
TemporaryStreetLocation to = new TemporaryStreetLocation("near_56th_20th", new Coordinate(-122.382347, 47.669518), new NonLocalizedString("near_56th_20th"), true);
new TemporaryConcreteEdge(_graph.getVertex("56th_20th"), to);
options.setRoutingContext(_graph, from, to);
ShortestPathTree tree = new AStar().getShortestPathTree(options);
options.cleanup();
GraphPath path = tree.getPath(to, false);
List<State> states = path.states;
assertEquals(9, states.size());
assertEquals("near_shilshole_22nd", states.get(0).getVertex().getLabel());
assertEquals("shilshole_22nd", states.get(1).getVertex().getLabel());
assertEquals("ballard_22nd", states.get(2).getVertex().getLabel());
assertEquals("market_22nd", states.get(3).getVertex().getLabel());
assertEquals("market_leary", states.get(4).getVertex().getLabel());
assertEquals("market_russell", states.get(5).getVertex().getLabel());
assertEquals("market_20th", states.get(6).getVertex().getLabel());
assertEquals("56th_20th", states.get(7).getVertex().getLabel());
assertEquals("near_56th_20th", states.get(8).getVertex().getLabel());
}
use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.
the class AStarTest method testMultipleTargets.
@Test
public void testMultipleTargets() {
RoutingRequest options = new RoutingRequest();
options.walkSpeed = 1.0;
options.batch = true;
options.setRoutingContext(_graph, _graph.getVertex("56th_24th"), _graph.getVertex("leary_20th"));
Set<Vertex> targets = new HashSet<Vertex>();
targets.add(_graph.getVertex("shilshole_22nd"));
targets.add(_graph.getVertex("market_russell"));
targets.add(_graph.getVertex("56th_20th"));
targets.add(_graph.getVertex("leary_20th"));
SearchTerminationStrategy strategy = new MultiTargetTerminationStrategy(targets);
ShortestPathTree tree = new AStar().getShortestPathTree(options, -1, strategy);
for (Vertex v : targets) {
GraphPath path = tree.getPath(v, false);
assertNotNull("No path found for target " + v.getLabel(), path);
}
}
Aggregations