use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class CheckGeometryModule method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
for (Vertex gv : graph.getVertices()) {
if (Double.isNaN(gv.getCoordinate().x) || Double.isNaN(gv.getCoordinate().y)) {
LOG.warn("Vertex " + gv + " has NaN location; this will cause doom.");
LOG.warn(graph.addBuilderAnnotation(new BogusVertexGeometry(gv)));
}
// TODO: This was filtered to EdgeNarratives before EdgeNarrative removal
for (Edge e : gv.getOutgoing()) {
Geometry g = e.getGeometry();
if (g == null) {
continue;
}
for (Coordinate c : g.getCoordinates()) {
if (Double.isNaN(c.x) || Double.isNaN(c.y)) {
LOG.warn(graph.addBuilderAnnotation(new BogusEdgeGeometry(e)));
}
}
if (e instanceof HopEdge) {
Coordinate edgeStartCoord = e.getFromVertex().getCoordinate();
Coordinate edgeEndCoord = e.getToVertex().getCoordinate();
Coordinate[] geometryCoordinates = g.getCoordinates();
if (geometryCoordinates.length < 2) {
LOG.warn(graph.addBuilderAnnotation(new BogusEdgeGeometry(e)));
continue;
}
Coordinate geometryStartCoord = geometryCoordinates[0];
Coordinate geometryEndCoord = geometryCoordinates[geometryCoordinates.length - 1];
if (SphericalDistanceLibrary.distance(edgeStartCoord, geometryStartCoord) > MAX_VERTEX_SHAPE_ERROR) {
LOG.warn(graph.addBuilderAnnotation(new VertexShapeError(e)));
} else if (SphericalDistanceLibrary.distance(edgeEndCoord, geometryEndCoord) > MAX_VERTEX_SHAPE_ERROR) {
LOG.warn(graph.addBuilderAnnotation(new VertexShapeError(e)));
}
}
}
}
}
use of org.opentripplanner.routing.graph.Vertex 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.graph.Vertex 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.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class TestHalfEdges method testNetworkLinker.
@Test
public void testNetworkLinker() {
int numVerticesBefore = graph.getVertices().size();
StreetLinkerModule ttsnm = new StreetLinkerModule();
ttsnm.buildGraph(graph, new HashMap<Class<?>, Object>());
int numVerticesAfter = graph.getVertices().size();
assertEquals(4, numVerticesAfter - numVerticesBefore);
Collection<Edge> outgoing = station1.getOutgoing();
assertTrue(outgoing.size() == 2);
Edge edge = outgoing.iterator().next();
Vertex midpoint = edge.getToVertex();
assertTrue(Math.abs(midpoint.getCoordinate().y - 40.01) < 0.00000001);
outgoing = station2.getOutgoing();
assertTrue(outgoing.size() == 2);
edge = outgoing.iterator().next();
Vertex station2point = edge.getToVertex();
assertTrue(Math.abs(station2point.getCoordinate().x - -74.002) < 0.00000001);
}
use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.
the class TestBanning method testBannedRoutes.
public void testBannedRoutes() {
Graph graph = ConstantsForTests.getInstance().getPortlandGraph();
String feedId = graph.getFeedIds().iterator().next();
RoutingRequest options = new RoutingRequest();
Vertex start = graph.getVertex(feedId + ":8371");
Vertex end = graph.getVertex(feedId + ":8374");
options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 11, 1, 12, 34, 25);
// must set routing context _after_ options is fully configured (time)
options.setRoutingContext(graph, start, end);
ShortestPathTree spt = null;
/*
* The MAX Red, Blue, and Green lines all run along the same trackage between the stops 8374 and 8371. Together, they form the white line. No,
* wait, that's light. They make a pretty good test case for banned routes, since if one is banned, you can always take another.
*/
String[][] maxLines = { { "MAX Red Line", null }, { "MAX Blue Line", null }, { "MAX Green Line", null }, { null, "90" }, { null, "100" }, { null, "200" } };
for (int i = 0; i < maxLines.length; ++i) {
String lineName = maxLines[i][0];
String lineId = maxLines[i][1];
String routeSpecStr = feedId + "_" + (lineName != null ? lineName : "") + (lineId != null ? "_" + lineId : "");
options.setBannedRoutes(routeSpecStr);
spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(end, true);
for (State s : path.states) {
if (s.getBackEdge() instanceof PatternHop) {
PatternHop e = (PatternHop) s.getBackEdge();
Route route = e.getPattern().route;
assertFalse(options.bannedRoutes.matches(route));
boolean foundMaxLine = false;
for (int j = 0; j < maxLines.length; ++j) {
if (j != i) {
if (e.getName().equals(maxLines[j][0])) {
foundMaxLine = true;
}
}
}
assertTrue(foundMaxLine);
}
}
}
}
Aggregations