use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class Measurement method printTimeOfRouteQuery.
private void printTimeOfRouteQuery(final GraphHopper hopper, final boolean ch, final boolean lm, int count, String prefix, final String vehicle, final boolean withInstructions, final int activeLandmarks, final boolean sod) {
final Graph g = hopper.getGraphHopperStorage();
final AtomicLong maxDistance = new AtomicLong(0);
final AtomicLong minDistance = new AtomicLong(Long.MAX_VALUE);
final AtomicLong distSum = new AtomicLong(0);
final AtomicLong airDistSum = new AtomicLong(0);
final AtomicInteger failedCount = new AtomicInteger(0);
final DistanceCalc distCalc = new DistanceCalcEarth();
final AtomicLong visitedNodesSum = new AtomicLong(0);
// final AtomicLong extractTimeSum = new AtomicLong(0);
// final AtomicLong calcPointsTimeSum = new AtomicLong(0);
// final AtomicLong calcDistTimeSum = new AtomicLong(0);
// final AtomicLong tmpDist = new AtomicLong(0);
final Random rand = new Random(seed);
final NodeAccess na = g.getNodeAccess();
MiniPerfTest miniPerf = new MiniPerfTest() {
@Override
public int doCalc(boolean warmup, int run) {
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);
req.getHints().put(CH.DISABLE, !ch).put("stall_on_demand", sod).put(Landmark.DISABLE, !lm).put(Landmark.ACTIVE_COUNT, activeLandmarks).put("instructions", withInstructions);
if (withInstructions)
req.setPathDetails(Arrays.asList(Parameters.DETAILS.AVERAGE_SPEED));
// put(algo + ".approximation", "BeelineSimplification").
// put(algo + ".epsilon", 2);
GHResponse rsp;
try {
rsp = hopper.route(req);
} catch (Exception ex) {
// 'not found' can happen if import creates more than one subnetwork
throw new RuntimeException("Error while calculating route! " + "nodes:" + from + " -> " + to + ", request:" + req, ex);
}
if (rsp.hasErrors()) {
if (!warmup)
failedCount.incrementAndGet();
if (rsp.getErrors().get(0).getMessage() == null)
rsp.getErrors().get(0).printStackTrace();
else if (!toLowerCase(rsp.getErrors().get(0).getMessage()).contains("not found"))
logger.error("errors should NOT happen in Measurement! " + req + " => " + rsp.getErrors());
return 0;
}
PathWrapper arsp = rsp.getBest();
if (!warmup) {
visitedNodesSum.addAndGet(rsp.getHints().getLong("visited_nodes.sum", 0));
long dist = (long) arsp.getDistance();
distSum.addAndGet(dist);
airDistSum.addAndGet((long) distCalc.calcDist(fromLat, fromLon, toLat, toLon));
if (dist > maxDistance.get())
maxDistance.set(dist);
if (dist < minDistance.get())
minDistance.set(dist);
// extractTimeSum.addAndGet(p.getExtractTime());
// long start = System.nanoTime();
// size = p.calcPoints().getSize();
// calcPointsTimeSum.addAndGet(System.nanoTime() - start);
}
return arsp.getPoints().getSize();
}
}.setIterations(count).start();
count -= failedCount.get();
// if using non-bidirectional algorithm make sure you exclude CH routing
String algoStr = ch ? Algorithms.DIJKSTRA_BI : Algorithms.ASTAR_BI;
if (ch && !sod) {
algoStr += "_no_sod";
}
put(prefix + ".guessed_algorithm", algoStr);
put(prefix + ".failed_count", failedCount.get());
put(prefix + ".distance_min", minDistance.get());
put(prefix + ".distance_mean", (float) distSum.get() / count);
put(prefix + ".air_distance_mean", (float) airDistSum.get() / count);
put(prefix + ".distance_max", maxDistance.get());
put(prefix + ".visited_nodes_mean", (float) visitedNodesSum.get() / count);
// put(prefix + ".extractTime", (float) extractTimeSum.get() / count / 1000000f);
// put(prefix + ".calcPointsTime", (float) calcPointsTimeSum.get() / count / 1000000f);
// put(prefix + ".calcDistTime", (float) calcDistTimeSum.get() / count / 1000000f);
print(prefix, miniPerf);
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class LocationIndexTreeTest method testSearchWithFilter_issue318.
@Test
public void testSearchWithFilter_issue318() {
CarFlagEncoder carEncoder = new CarFlagEncoder();
BikeFlagEncoder bikeEncoder = new BikeFlagEncoder();
EncodingManager tmpEM = new EncodingManager(carEncoder, bikeEncoder);
Graph graph = createGHStorage(new RAMDirectory(), tmpEM, false);
NodeAccess na = graph.getNodeAccess();
// distance from point to point is roughly 1 km
int MAX = 5;
for (int latIdx = 0; latIdx < MAX; latIdx++) {
for (int lonIdx = 0; lonIdx < MAX; lonIdx++) {
int index = lonIdx * 10 + latIdx;
na.setNode(index, 0.01 * latIdx, 0.01 * lonIdx);
if (latIdx < MAX - 1)
graph.edge(index, index + 1, 1000, true);
if (lonIdx < MAX - 1)
graph.edge(index, index + 10, 1000, true);
}
}
// reduce access for bike to two edges only
AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
iter.setFlags(bikeEncoder.setAccess(iter.getFlags(), false, false));
}
for (EdgeIteratorState edge : Arrays.asList(GHUtility.getEdge(graph, 0, 1), GHUtility.getEdge(graph, 1, 2))) {
edge.setFlags(bikeEncoder.setAccess(edge.getFlags(), true, true));
}
LocationIndexTree index = createIndexNoPrepare(graph, 500);
index.prepareIndex();
index.setMaxRegionSearch(8);
EdgeFilter carFilter = new DefaultEdgeFilter(carEncoder, true, true);
QueryResult qr = index.findClosest(0.03, 0.03, carFilter);
assertTrue(qr.isValid());
assertEquals(33, qr.getClosestNode());
EdgeFilter bikeFilter = new DefaultEdgeFilter(bikeEncoder, true, true);
qr = index.findClosest(0.03, 0.03, bikeFilter);
assertTrue(qr.isValid());
assertEquals(2, qr.getClosestNode());
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class LocationIndexTreeTest method testMoreReal.
@Test
public void testMoreReal() {
Graph graph = createGHStorage(new EncodingManager("car"));
NodeAccess na = graph.getNodeAccess();
na.setNode(1, 51.2492152, 9.4317166);
na.setNode(0, 52, 9);
na.setNode(2, 51.2, 9.4);
na.setNode(3, 49, 10);
graph.edge(1, 0, 1000, true);
graph.edge(0, 2, 1000, true);
graph.edge(0, 3, 1000, true).setWayGeometry(Helper.createPointList(51.21, 9.43));
LocationIndex index = createIndex(graph, -1);
assertEquals(2, findID(index, 51.2, 9.4));
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class BridgeElevationInterpolatorTest method interpolatesElevationOfPillarNodes.
@Test
public void interpolatesElevationOfPillarNodes() {
// @formatter:off
/*
* Graph structure:
* 0-----1-----2-----3-----4
* \ | /
* \ | /
* T T T
* \ | /
* \|/
* 5-----6--T--7--T--8-----9
*/
// @formatter:on
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 0, 0, 0);
na.setNode(1, 10, 0, 10);
na.setNode(2, 20, 0, 20);
na.setNode(3, 30, 0, 30);
na.setNode(4, 40, 0, 40);
na.setNode(5, 0, 10, 40);
na.setNode(6, 10, 10, 30);
na.setNode(7, 20, 10, 1000);
na.setNode(8, 30, 10, 10);
na.setNode(9, 40, 10, 0);
EdgeIteratorState edge01 = graph.edge(0, 1, 10, true);
EdgeIteratorState edge12 = graph.edge(1, 2, 10, true);
EdgeIteratorState edge23 = graph.edge(2, 3, 10, true);
EdgeIteratorState edge34 = graph.edge(3, 4, 10, true);
EdgeIteratorState edge56 = graph.edge(5, 6, 10, true);
EdgeIteratorState edge67 = graph.edge(6, 7, 10, true);
EdgeIteratorState edge78 = graph.edge(7, 8, 10, true);
EdgeIteratorState edge89 = graph.edge(8, 9, 10, true);
EdgeIteratorState edge17 = graph.edge(1, 7, 10, true);
EdgeIteratorState edge27 = graph.edge(2, 7, 10, true);
EdgeIteratorState edge37 = graph.edge(3, 7, 10, true);
edge17.setWayGeometry(Helper.createPointList3D(12, 2, 200, 14, 4, 400, 16, 6, 600, 18, 8, 800));
edge01.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
edge12.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
edge23.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
edge34.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
edge56.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
edge67.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
edge78.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
edge89.setFlags(dataFlagEncoder.handleWayTags(normalWay, 1, 0));
edge17.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
edge27.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
edge37.setFlags(dataFlagEncoder.handleWayTags(interpolatableWay, 1, 0));
final GHIntHashSet outerNodeIds = new GHIntHashSet();
final GHIntHashSet innerNodeIds = new GHIntHashSet();
gatherOuterAndInnerNodeIdsOfStructure(edge27, outerNodeIds, innerNodeIds);
assertEquals(GHIntHashSet.from(1, 2, 3, 6, 8), outerNodeIds);
assertEquals(GHIntHashSet.from(7), innerNodeIds);
edgeElevationInterpolator.execute();
assertEquals(0, na.getElevation(0), PRECISION);
assertEquals(10, na.getElevation(1), PRECISION);
assertEquals(20, na.getElevation(2), PRECISION);
assertEquals(30, na.getElevation(3), PRECISION);
assertEquals(40, na.getElevation(4), PRECISION);
assertEquals(40, na.getElevation(5), PRECISION);
assertEquals(30, na.getElevation(6), PRECISION);
assertEquals(20, na.getElevation(7), PRECISION);
assertEquals(10, na.getElevation(8), PRECISION);
assertEquals(0, na.getElevation(9), PRECISION);
final PointList edge17PointList = edge17.fetchWayGeometry(3);
assertEquals(6, edge17PointList.size());
assertEquals(10, edge17PointList.getEle(0), PRECISION);
assertEquals(12, edge17PointList.getEle(1), PRECISION);
assertEquals(14, edge17PointList.getEle(2), PRECISION);
assertEquals(16, edge17PointList.getEle(3), PRECISION);
assertEquals(18, edge17PointList.getEle(4), PRECISION);
assertEquals(20, edge17PointList.getEle(5), PRECISION);
}
use of com.graphhopper.storage.NodeAccess in project graphhopper by graphhopper.
the class GraphHopperAPITest method testLoad.
@Test
public void testLoad() {
GraphHopperStorage graph = new GraphBuilder(encodingManager).create();
initGraph(graph);
// do further changes:
NodeAccess na = graph.getNodeAccess();
na.setNode(4, 41.9, 10.2);
graph.edge(1, 2, 10, false);
graph.edge(0, 4, 40, true);
graph.edge(4, 3, 40, true);
GraphHopper instance = new GraphHopper().setStoreOnFlush(false).setEncodingManager(encodingManager).setCHEnabled(false).loadGraph(graph);
// 3 -> 0
GHResponse rsp = instance.route(new GHRequest(42, 10.4, 42, 10));
assertFalse(rsp.hasErrors());
PathWrapper arsp = rsp.getBest();
assertEquals(80, arsp.getDistance(), 1e-6);
PointList points = arsp.getPoints();
assertEquals(42, points.getLatitude(0), 1e-5);
assertEquals(10.4, points.getLongitude(0), 1e-5);
assertEquals(41.9, points.getLatitude(1), 1e-5);
assertEquals(10.2, points.getLongitude(1), 1e-5);
assertEquals(3, points.getSize());
instance.close();
}
Aggregations