use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class ViaRoutingTemplate method lookup.
@Override
public List<QueryResult> lookup(List<GHPoint> points, FlagEncoder encoder) {
if (points.size() < 2)
throw new IllegalArgumentException("At least 2 points have to be specified, but was:" + points.size());
EdgeFilter edgeFilter = new DefaultEdgeFilter(encoder);
queryResults = new ArrayList<>(points.size());
for (int placeIndex = 0; placeIndex < points.size(); placeIndex++) {
GHPoint point = points.get(placeIndex);
QueryResult res;
if (ghRequest.hasPointHints()) {
res = locationIndex.findClosest(point.lat, point.lon, new NameSimilarityEdgeFilter(edgeFilter, ghRequest.getPointHints().get(placeIndex)));
if (!res.isValid()) {
res = locationIndex.findClosest(point.lat, point.lon, edgeFilter);
}
} else {
res = locationIndex.findClosest(point.lat, point.lon, edgeFilter);
}
if (!res.isValid())
ghResponse.addError(new PointNotFoundException("Cannot find point " + placeIndex + ": " + point, placeIndex));
queryResults.add(res);
}
return queryResults;
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class TestAlgoCollector method queryIndex.
void queryIndex(Graph g, LocationIndex idx, double lat, double lon, double expectedDist) {
QueryResult res = idx.findClosest(lat, lon, EdgeFilter.ALL_EDGES);
if (!res.isValid()) {
errors.add("node not found for " + lat + "," + lon);
return;
}
GHPoint found = res.getSnappedPoint();
double dist = distCalc.calcDist(lat, lon, found.lat, found.lon);
if (Math.abs(dist - expectedDist) > .1) {
errors.add("queried lat,lon=" + (float) lat + "," + (float) lon + " (found: " + (float) found.lat + "," + (float) found.lon + ")" + "\n expected distance:" + expectedDist + ", but was:" + dist);
}
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class AbstractRoutingAlgorithmTester method calcPath.
Path calcPath(GraphHopperStorage ghStorage, int fromNode1, int fromNode2, int toNode1, int toNode2) {
// lookup two edges: fromNode1-fromNode2 and toNode1-toNode2
QueryResult from = newQR(ghStorage, fromNode1, fromNode2);
QueryResult to = newQR(ghStorage, toNode1, toNode2);
RoutingAlgorithmFactory factory = createFactory(ghStorage, defaultOpts);
QueryGraph qGraph = new QueryGraph(getGraph(ghStorage, defaultOpts.getWeighting())).lookup(from, to);
return factory.createAlgo(qGraph, defaultOpts).calcPath(from.getClosestNode(), to.getClosestNode());
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class AbstractRoutingAlgorithmTester method testTwoWeightsPerEdge2.
@Test
public void testTwoWeightsPerEdge2() {
// other direction should be different!
Weighting fakeWeighting = new Weighting() {
@Override
public FlagEncoder getFlagEncoder() {
return carEncoder;
}
@Override
public double getMinWeight(double distance) {
return 0.8 * distance;
}
@Override
public double calcWeight(EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) {
int adj = edgeState.getAdjNode();
int base = edgeState.getBaseNode();
if (reverse) {
int tmp = base;
base = adj;
adj = tmp;
}
// a 'hill' at node 6
if (adj == 6)
return 3 * edgeState.getDistance();
else if (base == 6)
return edgeState.getDistance() * 0.9;
else if (adj == 4)
return 2 * edgeState.getDistance();
return edgeState.getDistance() * 0.8;
}
private final Weighting tmpW = new FastestWeighting(carEncoder);
@Override
public long calcMillis(EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) {
return tmpW.calcMillis(edgeState, reverse, prevOrNextEdgeId);
}
@Override
public boolean matches(HintsMap map) {
throw new UnsupportedOperationException("Not supported");
}
@Override
public String getName() {
return "custom";
}
};
AlgorithmOptions opts = AlgorithmOptions.start().weighting(defaultOpts.getWeighting()).build();
GraphHopperStorage graph = createGHStorage(encodingManager, Arrays.asList(opts.getWeighting()), true);
initEleGraph(graph);
Path p = createAlgo(graph, opts).calcPath(0, 10);
// GHUtility.printEdgeInfo(graph, carEncoder);
assertEquals(Helper.createTList(0, 4, 6, 10), p.calcNodes());
AlgorithmOptions fakeOpts = AlgorithmOptions.start().weighting(fakeWeighting).build();
graph = createGHStorage(encodingManager, Arrays.asList(fakeOpts.getWeighting()), true);
initEleGraph(graph);
QueryResult from = newQR(graph, 3, 0);
QueryResult to = newQR(graph, 10, 9);
RoutingAlgorithmFactory factory = createFactory(graph, fakeOpts);
QueryGraph qGraph = new QueryGraph(getGraph(graph, fakeWeighting)).lookup(from, to);
p = factory.createAlgo(qGraph, fakeOpts).calcPath(from.getClosestNode(), to.getClosestNode());
assertEquals(Helper.createTList(12, 0, 1, 2, 11, 7, 10, 13), p.calcNodes());
assertEquals(37009621, p.getTime());
assertEquals(616827, p.getDistance(), 1);
assertEquals(493462, p.getWeight(), 1);
}
use of com.graphhopper.storage.index.QueryResult in project graphhopper by graphhopper.
the class QueryGraphTest method testEdgesShareOneNode.
@Test
public void testEdgesShareOneNode() {
initGraph(g);
EdgeIteratorState iter = GHUtility.getEdge(g, 0, 2);
QueryResult res1 = createLocationResult(0.5, 0, iter, 0, EDGE);
iter = GHUtility.getEdge(g, 1, 0);
QueryResult res2 = createLocationResult(1.5, 2, iter, 0, EDGE);
QueryGraph queryGraph = new QueryGraph(g);
queryGraph.lookup(Arrays.asList(res1, res2));
assertEquals(new GHPoint(0.5, 0), res1.getSnappedPoint());
assertEquals(new GHPoint(1.300019, 1.899962), res2.getSnappedPoint());
assertNotNull(GHUtility.getEdge(queryGraph, 0, 4));
assertNotNull(GHUtility.getEdge(queryGraph, 0, 3));
}
Aggregations