use of com.graphhopper.coll.GHBitSet in project graphhopper by graphhopper.
the class GHUtility method sortDFS.
/**
* Sorts the graph according to depth-first search traversal. Other traversals have either no
* significant difference (bfs) for querying or are worse (z-curve).
*/
public static Graph sortDFS(Graph g, Graph sortedGraph) {
int nodes = g.getNodes();
final GHIntArrayList list = new GHIntArrayList(nodes);
list.fill(nodes, -1);
final GHBitSetImpl bitset = new GHBitSetImpl(nodes);
final AtomicInteger ref = new AtomicInteger(-1);
EdgeExplorer explorer = g.createEdgeExplorer();
for (int startNode = 0; startNode >= 0 && startNode < nodes; startNode = bitset.nextClear(startNode + 1)) {
new DepthFirstSearch() {
@Override
protected GHBitSet createBitSet() {
return bitset;
}
@Override
protected boolean goFurther(int nodeId) {
list.set(nodeId, ref.incrementAndGet());
return super.goFurther(nodeId);
}
}.start(explorer, startNode);
}
return createSortedGraph(g, sortedGraph, list);
}
use of com.graphhopper.coll.GHBitSet in project graphhopper by graphhopper.
the class Measurement method printGraphDetails.
private GHBitSet printGraphDetails(GraphHopperStorage g, String vehicleStr) {
// graph size (edge, node and storage size)
put("graph.nodes", g.getNodes());
put("graph.edges", g.getAllEdges().getMaxId());
put("graph.size_in_MB", g.getCapacity() / MB);
put("graph.encoder", vehicleStr);
AllEdgesIterator iter = g.getAllEdges();
final int maxEdgesId = g.getAllEdges().getMaxId();
final GHBitSet allowedEdges = new GHBitSetImpl(maxEdgesId);
fillAllowedEdges(iter, allowedEdges);
put("graph.valid_edges", allowedEdges.getCardinality());
return allowedEdges;
}
use of com.graphhopper.coll.GHBitSet in project graphhopper by graphhopper.
the class Location2IDQuadtree method prepareIndex.
/**
* Fill quadtree which will span a raster over the entire specified graph g. But do this in a
* pre-defined resolution which is controlled via capacity. This data structure then uses approx.
* capacity * 4 bytes. So maximum capacity is 2^30 where the quadtree would cover the world
* boundaries every 1.3km - IMO enough for EU or US networks.
*/
@Override
public LocationIndex prepareIndex() {
initBuffer();
initAlgo(latSize, lonSize);
StopWatch sw = new StopWatch().start();
GHBitSet filledIndices = fillQuadtree(latSize * lonSize);
int fillQT = filledIndices.getCardinality();
float res1 = sw.stop().getSeconds();
sw = new StopWatch().start();
int counter = fillEmptyIndices(filledIndices);
float fillEmpty = sw.stop().getSeconds();
logger.info("filled quadtree index array in " + res1 + "s. size is " + getCapacity() + " (" + fillQT + "). filled empty " + counter + " in " + fillEmpty + "s");
flush();
return this;
}
use of com.graphhopper.coll.GHBitSet in project graphhopper by graphhopper.
the class LocationIndexTree method findClosest.
@Override
public QueryResult findClosest(final double queryLat, final double queryLon, final EdgeFilter edgeFilter) {
if (isClosed())
throw new IllegalStateException("You need to create a new LocationIndex instance as it is already closed");
GHIntHashSet allCollectedEntryIds = new GHIntHashSet();
final QueryResult closestMatch = new QueryResult(queryLat, queryLon);
for (int iteration = 0; iteration < maxRegionSearch; iteration++) {
GHIntHashSet storedNetworkEntryIds = new GHIntHashSet();
boolean earlyFinish = findNetworkEntries(queryLat, queryLon, storedNetworkEntryIds, iteration);
storedNetworkEntryIds.removeAll(allCollectedEntryIds);
allCollectedEntryIds.addAll(storedNetworkEntryIds);
// clone storedIds to avoid interference with forEach
final GHBitSet checkBitset = new GHTBitSet(new GHIntHashSet(storedNetworkEntryIds));
// find nodes from the network entries which are close to 'point'
final EdgeExplorer explorer = graph.createEdgeExplorer();
storedNetworkEntryIds.forEach(new IntPredicate() {
@Override
public boolean apply(int networkEntryNodeId) {
new XFirstSearchCheck(queryLat, queryLon, checkBitset, edgeFilter) {
@Override
protected double getQueryDistance() {
return closestMatch.getQueryDistance();
}
@Override
protected boolean check(int node, double normedDist, int wayIndex, EdgeIteratorState edge, QueryResult.Position pos) {
if (normedDist < closestMatch.getQueryDistance()) {
closestMatch.setQueryDistance(normedDist);
closestMatch.setClosestNode(node);
closestMatch.setClosestEdge(edge.detach(false));
closestMatch.setWayIndex(wayIndex);
closestMatch.setSnappedPosition(pos);
return true;
}
return false;
}
}.start(explorer, networkEntryNodeId);
return true;
}
});
// do early finish only if something was found (#318)
if (earlyFinish && closestMatch.isValid())
break;
}
// denormalize distance and calculate snapping point only if closed match was found
if (closestMatch.isValid()) {
closestMatch.setQueryDistance(distCalc.calcDenormalizedDist(closestMatch.getQueryDistance()));
closestMatch.calcSnappedPoint(distCalc);
}
return closestMatch;
}
Aggregations