Search in sources :

Example 71 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.

the class LocationIndexTreeTest method testBoundingBoxQuery1.

@Test
public void testBoundingBoxQuery1() {
    Graph graph = createTestGraph2();
    LocationIndexTree index = (LocationIndexTree) createIndexNoPrepare(graph, 500).prepareIndex();
    final IntArrayList edges = new IntArrayList();
    BBox bbox = new BBox(11.57114, 11.57814, 49.94553, 49.94853);
    index.query(bbox, edges::add);
    // Also all edges (see testgraph2.jpg)
    assertEquals(edges.size(), graph.getEdges());
}
Also used : BBox(com.graphhopper.util.shapes.BBox) IntArrayList(com.carrotsearch.hppc.IntArrayList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 72 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.

the class ArrayUtilTest method testPermutation.

@Test
public void testPermutation() {
    IntArrayList list = ArrayUtil.permutation(15, new Random());
    assertEquals(15, list.buffer.length);
    assertEquals(15, list.elementsCount);
    assertEquals(14 / 2.0 * (14 + 1), Arrays.stream(list.buffer).sum());
    assertTrue(ArrayUtil.isPermutation(list));
}
Also used : Random(java.util.Random) IntArrayList(com.carrotsearch.hppc.IntArrayList) Test(org.junit.jupiter.api.Test)

Example 73 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.

the class ArrayUtilTest method testConstant.

@Test
public void testConstant() {
    IntArrayList list = ArrayUtil.constant(10, 3);
    assertEquals(10, list.size());
    assertEquals(3, list.get(5));
    assertEquals(3, list.get(9));
    assertEquals(10, list.buffer.length);
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) Test(org.junit.jupiter.api.Test)

Example 74 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworks method setSubnetworks.

private int setSubnetworks(Weighting weighting, BooleanEncodedValue subnetworkEnc) {
    // partition graph into strongly connected components using Tarjan's algorithm
    StopWatch sw = new StopWatch().start();
    EdgeBasedTarjanSCC.ConnectedComponents ccs = EdgeBasedTarjanSCC.findComponents(ghStorage, (prev, edge) -> Double.isFinite(GHUtility.calcWeightWithTurnWeightWithAccess(weighting, edge, false, prev)), false);
    List<IntArrayList> components = ccs.getComponents();
    BitSet singleEdgeComponents = ccs.getSingleEdgeComponents();
    long numSingleEdgeComponents = singleEdgeComponents.cardinality();
    logger.info(subnetworkEnc.getName().replaceAll("_subnetwork", "") + " - Found " + ccs.getTotalComponents() + " subnetworks (" + numSingleEdgeComponents + " single edges and " + components.size() + " components with more than one edge, total nodes: " + ccs.getEdgeKeys() + "), took: " + sw.stop().getSeconds() + "s");
    final int minNetworkSizeEdgeKeys = 2 * minNetworkSize;
    // make all small components subnetworks, but keep the biggest (even when its smaller than the given min_network_size)
    sw = new StopWatch().start();
    int subnetworks = 0;
    int markedEdges = 0;
    int smallestNonSubnetwork = ccs.getBiggestComponent().size();
    int biggestSubnetwork = 0;
    for (IntArrayList component : components) {
        if (component == ccs.getBiggestComponent())
            continue;
        if (component.size() < minNetworkSizeEdgeKeys) {
            for (IntCursor cursor : component) markedEdges += setSubnetworkEdge(cursor.value, weighting, subnetworkEnc);
            subnetworks++;
            biggestSubnetwork = Math.max(biggestSubnetwork, component.size());
        } else {
            smallestNonSubnetwork = Math.min(smallestNonSubnetwork, component.size());
        }
    }
    if (minNetworkSizeEdgeKeys > 0) {
        BitSetIterator iter = singleEdgeComponents.iterator();
        for (int edgeKey = iter.nextSetBit(); edgeKey >= 0; edgeKey = iter.nextSetBit()) {
            markedEdges += setSubnetworkEdge(edgeKey, weighting, subnetworkEnc);
            subnetworks++;
            biggestSubnetwork = Math.max(biggestSubnetwork, 1);
        }
    } else if (numSingleEdgeComponents > 0) {
        smallestNonSubnetwork = Math.min(smallestNonSubnetwork, 1);
    }
    int allowedMarked = ghStorage.getEdges() / 2;
    if (markedEdges / 2 > allowedMarked)
        throw new IllegalStateException("Too many total (directed) edges were marked as subnetwork edges: " + markedEdges + " out of " + (2 * ghStorage.getEdges()) + "\n" + "The maximum number of subnetwork edges is: " + (2 * allowedMarked));
    logger.info(subnetworkEnc.getName().replaceAll("_subnetwork", "") + " - Marked " + subnetworks + " subnetworks (biggest: " + biggestSubnetwork + " edges) -> " + (ccs.getTotalComponents() - subnetworks) + " components(s) remain (smallest: " + smallestNonSubnetwork + ", biggest: " + ccs.getBiggestComponent().size() + " edges)" + ", total marked edges: " + markedEdges + ", took: " + sw.stop().getSeconds() + "s");
    return markedEdges;
}
Also used : BitSetIterator(com.carrotsearch.hppc.BitSetIterator) IntCursor(com.carrotsearch.hppc.cursors.IntCursor) BitSet(com.carrotsearch.hppc.BitSet) IntArrayList(com.carrotsearch.hppc.IntArrayList) StopWatch(com.graphhopper.util.StopWatch)

Example 75 with IntArrayList

use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.

the class TarjanSCC method buildComponent.

private void buildComponent(int v) {
    if (nodeLowLink[v] == nodeIndex[v]) {
        if (tarjanStack.getLast() == v) {
            tarjanStack.removeLast();
            nodeOnStack.clear(v);
            components.numComponents++;
            components.numNodes++;
            if (!excludeSingleNodeComponents)
                components.singleNodeComponents.set(v);
        } else {
            IntArrayList component = new IntArrayList();
            while (true) {
                int w = tarjanStack.removeLast();
                component.add(w);
                nodeOnStack.clear(w);
                if (w == v)
                    break;
            }
            component.trimToSize();
            assert component.size() > 1;
            components.numComponents++;
            components.numNodes += component.size();
            components.components.add(component);
            if (component.size() > components.biggestComponent.size())
                components.biggestComponent = component;
        }
    }
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList)

Aggregations

IntArrayList (com.carrotsearch.hppc.IntArrayList)94 Test (org.junit.jupiter.api.Test)16 RepeatedTest (org.junit.jupiter.api.RepeatedTest)13 GHPoint (com.graphhopper.util.shapes.GHPoint)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)7 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)5 HashMap (java.util.HashMap)5 UUID (java.util.UUID)5 GHIntArrayList (com.graphhopper.coll.GHIntArrayList)4 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)4 RelationName (io.crate.metadata.RelationName)4 IOException (java.io.IOException)4 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)3 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)3 PrepEdgeFilter (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3