Search in sources :

Example 11 with GHBitSet

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);
}
Also used : GHBitSetImpl(com.graphhopper.coll.GHBitSetImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GHBitSet(com.graphhopper.coll.GHBitSet) GHIntArrayList(com.graphhopper.coll.GHIntArrayList)

Example 12 with GHBitSet

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;
}
Also used : GHBitSetImpl(com.graphhopper.coll.GHBitSetImpl) GHBitSet(com.graphhopper.coll.GHBitSet)

Example 13 with GHBitSet

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;
}
Also used : GHBitSet(com.graphhopper.coll.GHBitSet) GHPoint(com.graphhopper.util.shapes.GHPoint) StopWatch(com.graphhopper.util.StopWatch)

Example 14 with GHBitSet

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;
}
Also used : GHIntHashSet(com.graphhopper.coll.GHIntHashSet) IntPredicate(com.carrotsearch.hppc.predicates.IntPredicate) GHBitSet(com.graphhopper.coll.GHBitSet) GHPoint(com.graphhopper.util.shapes.GHPoint) GHTBitSet(com.graphhopper.coll.GHTBitSet)

Aggregations

GHBitSet (com.graphhopper.coll.GHBitSet)14 GHBitSetImpl (com.graphhopper.coll.GHBitSetImpl)7 GHPoint (com.graphhopper.util.shapes.GHPoint)6 GHTBitSet (com.graphhopper.coll.GHTBitSet)3 IntArrayList (com.carrotsearch.hppc.IntArrayList)2 IntPredicate (com.carrotsearch.hppc.predicates.IntPredicate)2 GHIntArrayList (com.graphhopper.coll.GHIntArrayList)2 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)2 ArrayList (java.util.ArrayList)2 IntArrayDeque (com.carrotsearch.hppc.IntArrayDeque)1 GraphHopper (com.graphhopper.GraphHopper)1 SparseIntIntArray (com.graphhopper.coll.SparseIntIntArray)1 DataReader (com.graphhopper.reader.DataReader)1 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)1 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)1 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)1 Weighting (com.graphhopper.routing.weighting.Weighting)1 CHGraph (com.graphhopper.storage.CHGraph)1 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)1 BreadthFirstSearch (com.graphhopper.util.BreadthFirstSearch)1