use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class TestGraphPath method testGraphPathOptimize.
public void testGraphPathOptimize() throws Exception {
String feedId = graph.getFeedIds().iterator().next();
Vertex stop_a = graph.getVertex(feedId + ":A");
Vertex stop_c = graph.getVertex(feedId + ":C");
Vertex stop_e = graph.getVertex(feedId + ":E");
ShortestPathTree spt;
GraphPath path;
RoutingRequest options = new RoutingRequest();
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
options.setRoutingContext(graph, stop_a.getLabel(), stop_e.getLabel());
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_e, false);
/* do not optimize yet, since we are testing optimization */
assertNotNull(path);
// Check that the resulting path visits the stops in the right order.
List<Vertex> stopvs = Lists.newArrayList();
for (State state : path.states) {
if (state.getVertex() instanceof TransitStop) {
stopvs.add(state.getVertex());
}
}
assertTrue(stopvs.get(0) == stop_a);
assertTrue(stopvs.get(1) == stop_c);
assertTrue(stopvs.get(2) == stop_e);
long bestStart = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 20, 0);
assertNotSame(bestStart, path.getStartTime());
path = spt.getPath(stop_e, true);
/* optimize */
assertEquals(bestStart, path.getStartTime());
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class TestGraph method testAddVertex.
public void testAddVertex() throws Exception {
Graph g = new Graph();
Vertex a = new IntersectionVertex(g, "A", 5, 5);
assertEquals(a.getLabel(), "A");
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class TestGraph method testGetVertex.
public void testGetVertex() throws Exception {
Graph g = new Graph();
Vertex a = new IntersectionVertex(g, "A", 5, 5);
Vertex b = g.getVertex("A");
assertEquals(a, b);
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class TestGraph method testGetEdgesAndVerticesById.
public void testGetEdgesAndVerticesById() {
Graph g = new Graph();
StreetVertex a = new IntersectionVertex(g, "A", 5, 5);
StreetVertex b = new IntersectionVertex(g, "B", 6, 6);
StreetVertex c = new IntersectionVertex(g, "C", 3, 2);
Set<Edge> allEdges = new HashSet<Edge>(4);
allEdges.add(edge(a, b, 1.0));
allEdges.add(edge(b, c, 1.0));
allEdges.add(edge(c, b, 1.0));
allEdges.add(edge(c, a, 1.0));
// Before rebuilding the indices, they are empty.
for (Edge e : allEdges) {
assertNull(g.getEdgeById(e.getId()));
}
for (Vertex v : g.getVertices()) {
assertNull(g.getVertexById(v.getIndex()));
}
g.rebuildVertexAndEdgeIndices();
for (Edge e : allEdges) {
assertEquals(e, g.getEdgeById(e.getId()));
}
for (Vertex v : g.getVertices()) {
assertEquals(v, g.getVertexById(v.getIndex()));
}
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class TestGraph method testGetEdgesOneEdge.
public void testGetEdgesOneEdge() {
Graph g = new Graph();
Vertex a = new IntersectionVertex(g, "A", 5, 5);
Vertex b = new IntersectionVertex(g, "B", 6, 6);
FreeEdge ee = new FreeEdge(a, b);
List<Edge> edges = new ArrayList<Edge>(g.getEdges());
assertEquals(1, edges.size());
assertEquals(ee, edges.get(0));
}
Aggregations