use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class Measurement method compareRouting.
private void compareRouting(final GraphHopper hopper, String vehicle, int count) {
logger.info("Comparing " + count + " routes. Differences will be printed to stderr.");
String algo = Algorithms.ASTAR_BI;
final Random rand = new Random(seed);
final Graph g = hopper.getGraphHopperStorage();
final NodeAccess na = g.getNodeAccess();
for (int i = 0; i < count; i++) {
int from = rand.nextInt(maxNode);
int to = rand.nextInt(maxNode);
double fromLat = na.getLatitude(from);
double fromLon = na.getLongitude(from);
double toLat = na.getLatitude(to);
double toLon = na.getLongitude(to);
GHRequest req = new GHRequest(fromLat, fromLon, toLat, toLon).setWeighting("fastest").setVehicle(vehicle).setAlgorithm(algo);
GHResponse lmRsp = hopper.route(req);
req.getHints().put(Landmark.DISABLE, true);
GHResponse originalRsp = hopper.route(req);
String locStr = " iteration " + i + ". " + fromLat + "," + fromLon + " -> " + toLat + "," + toLon;
if (lmRsp.hasErrors()) {
if (originalRsp.hasErrors())
continue;
logger.error("Error for LM but not for original response " + locStr);
}
String infoStr = " weight:" + lmRsp.getBest().getRouteWeight() + ", original: " + originalRsp.getBest().getRouteWeight() + " distance:" + lmRsp.getBest().getDistance() + ", original: " + originalRsp.getBest().getDistance() + " time:" + round2(lmRsp.getBest().getTime() / 1000) + ", original: " + round2(originalRsp.getBest().getTime() / 1000) + " points:" + lmRsp.getBest().getPoints().size() + ", original: " + originalRsp.getBest().getPoints().size();
if (Math.abs(1 - lmRsp.getBest().getRouteWeight() / originalRsp.getBest().getRouteWeight()) > 0.000001)
logger.error("Too big weight difference for LM. " + locStr + infoStr);
}
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class Measurement method compareCHWithAndWithoutSOD.
private void compareCHWithAndWithoutSOD(final GraphHopper hopper, String vehicle, int count) {
logger.info("Comparing " + count + " routes for CH with and without stall on demand." + " Differences will be printed to stderr.");
final Random rand = new Random(seed);
final Graph g = hopper.getGraphHopperStorage();
final NodeAccess na = g.getNodeAccess();
for (int i = 0; i < count; i++) {
int from = rand.nextInt(maxNode);
int to = rand.nextInt(maxNode);
double fromLat = na.getLatitude(from);
double fromLon = na.getLongitude(from);
double toLat = na.getLatitude(to);
double toLon = na.getLongitude(to);
GHRequest sodReq = new GHRequest(fromLat, fromLon, toLat, toLon).setWeighting("fastest").setVehicle(vehicle).setAlgorithm(DIJKSTRA_BI);
GHRequest noSodReq = new GHRequest(fromLat, fromLon, toLat, toLon).setWeighting("fastest").setVehicle(vehicle).setAlgorithm(DIJKSTRA_BI);
noSodReq.getHints().put("stall_on_demand", false);
GHResponse sodRsp = hopper.route(sodReq);
GHResponse noSodRsp = hopper.route(noSodReq);
String locStr = " iteration " + i + ". " + fromLat + "," + fromLon + " -> " + toLat + "," + toLon;
if (sodRsp.hasErrors()) {
if (noSodRsp.hasErrors()) {
logger.info("Error with and without SOD");
continue;
} else {
logger.error("Error with SOD but not without SOD" + locStr);
continue;
}
}
String infoStr = " weight:" + noSodRsp.getBest().getRouteWeight() + ", original: " + sodRsp.getBest().getRouteWeight() + " distance:" + noSodRsp.getBest().getDistance() + ", original: " + sodRsp.getBest().getDistance() + " time:" + round2(noSodRsp.getBest().getTime() / 1000) + ", original: " + round2(sodRsp.getBest().getTime() / 1000) + " points:" + noSodRsp.getBest().getPoints().size() + ", original: " + sodRsp.getBest().getPoints().size();
if (Math.abs(1 - noSodRsp.getBest().getRouteWeight() / sodRsp.getBest().getRouteWeight()) > 0.000001)
logger.error("Too big weight difference for SOD. " + locStr + infoStr);
}
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class LocationIndexTreeTest method createTestGraphWithWayGeometry.
// -1 0 1 1.5
// --------------------
// 1| --A
// | -0--/ \
// 0| / | B-\ \
// | / 1/ 3--4
// | |/------/ /
// -1| 2---------/
// |
private Graph createTestGraphWithWayGeometry() {
Graph graph = createGHStorage(encodingManager);
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 0.5, -0.5);
na.setNode(1, -0.5, -0.5);
na.setNode(2, -1, -1);
na.setNode(3, -0.4, 0.9);
na.setNode(4, -0.6, 1.6);
graph.edge(0, 1, 1, true);
graph.edge(0, 2, 1, true);
// insert A and B, without this we would get 0 for 0,0
graph.edge(0, 4, 1, true).setWayGeometry(Helper.createPointList(1, 1));
graph.edge(1, 3, 1, true).setWayGeometry(Helper.createPointList(0, 0));
graph.edge(2, 3, 1, true);
graph.edge(2, 4, 1, true);
graph.edge(3, 4, 1, true);
return graph;
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class LocationIndexTreeTest method createTestGraph.
// 0------\
// /| \
// |1----3-\|
// |____/ 4
// 2-------/
Graph createTestGraph(EncodingManager em) {
Graph graph = createGHStorage(new RAMDirectory(), em, false);
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 0.5, -0.5);
na.setNode(1, -0.5, -0.5);
na.setNode(2, -1, -1);
na.setNode(3, -0.4, 0.9);
na.setNode(4, -0.6, 1.6);
graph.edge(0, 1, 1, true);
graph.edge(0, 2, 1, true);
graph.edge(0, 4, 1, true);
graph.edge(1, 3, 1, true);
graph.edge(2, 3, 1, true);
graph.edge(2, 4, 1, true);
graph.edge(3, 4, 1, true);
return graph;
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class InstructionListTest method testNoInstructionIfSameStreet.
// TODO is this problem fixed with the new instructions?
// problem: we normally don't want instructions if streetname stays but here it is suboptimal:
@Test
public void testNoInstructionIfSameStreet() {
Graph g = new GraphBuilder(carManager).create();
// 2
// \. 5
// \/
// 4
// /
// 3
NodeAccess na = g.getNodeAccess();
na.setNode(2, 10.3, 10.15);
na.setNode(3, 10.0, 10.05);
na.setNode(4, 10.1, 10.10);
na.setNode(5, 10.2, 10.15);
g.edge(3, 4, 100, true).setName("street");
g.edge(4, 5, 100, true).setName("4-5");
EdgeIteratorState iter = g.edge(2, 4, 100, true);
iter.setName("street");
PointList list = new PointList();
list.add(10.20, 10.05);
iter.setWayGeometry(list);
Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(2, 3);
InstructionList wayList = p.calcInstructions(usTR);
List<String> tmpList = pick("text", wayList.createJson());
assertEquals(Arrays.asList("Continue onto street", "Turn right onto street", "Arrive at destination"), tmpList);
}
Aggregations