Search in sources :

Example 46 with IntArrayList

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

the class IndexStructureInfo method create.

public static IndexStructureInfo create(BBox bounds, int minResolutionInMeter) {
    // is zero.
    if (!bounds.isValid())
        bounds = new BBox(-10.0, 10.0, -10.0, 10.0);
    double lat = Math.min(Math.abs(bounds.maxLat), Math.abs(bounds.minLat));
    double maxDistInMeter = Math.max((bounds.maxLat - bounds.minLat) / 360 * C, (bounds.maxLon - bounds.minLon) / 360 * DIST_EARTH.calcCircumference(lat));
    double tmp = maxDistInMeter / minResolutionInMeter;
    tmp = tmp * tmp;
    IntArrayList tmpEntries = new IntArrayList();
    // the last one is always 4 to reduce costs if only a single entry
    tmp /= 4;
    while (tmp > 1) {
        int tmpNo;
        if (tmp >= 16) {
            tmpNo = 16;
        } else if (tmp >= 4) {
            tmpNo = 4;
        } else {
            break;
        }
        tmpEntries.add(tmpNo);
        tmp /= tmpNo;
    }
    tmpEntries.add(4);
    int[] entries = tmpEntries.toArray();
    if (entries.length < 1) {
        // at least one depth should have been specified
        throw new IllegalStateException("depth needs to be at least 1");
    }
    int depth = entries.length;
    byte[] shifts = new byte[depth];
    int lastEntry = entries[0];
    for (int i1 = 0; i1 < depth; i1++) {
        if (lastEntry < entries[i1]) {
            throw new IllegalStateException("entries should decrease or stay but was:" + Arrays.toString(entries));
        }
        lastEntry = entries[i1];
        shifts[i1] = getShift(entries[i1]);
    }
    int shiftSum = 0;
    long parts = 1;
    for (int i = 0; i < shifts.length; i++) {
        shiftSum += shifts[i];
        parts *= entries[i];
    }
    if (shiftSum > 64)
        throw new IllegalStateException("sum of all shifts does not fit into a long variable");
    parts = (int) Math.round(Math.sqrt(parts));
    return new IndexStructureInfo(entries, shifts, new PixelGridTraversal((int) parts, bounds), new SpatialKeyAlgo(shiftSum, bounds), bounds, (int) parts);
}
Also used : SpatialKeyAlgo(com.graphhopper.geohash.SpatialKeyAlgo) BBox(com.graphhopper.util.shapes.BBox) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 47 with IntArrayList

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

the class ArrayUtilTest method testTransform.

@Test
public void testTransform() {
    IntArrayList arr = from(7, 6, 2);
    ArrayUtil.transform(arr, ArrayUtil.constant(8, 4));
    assertEquals(IntArrayList.from(4, 4, 4), arr);
    IntArrayList brr = from(3, 0, 1);
    ArrayUtil.transform(brr, IntArrayList.from(6, 2, 1, 5));
    assertEquals(IntArrayList.from(5, 6, 2), brr);
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) Test(org.junit.jupiter.api.Test)

Example 48 with IntArrayList

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

the class ArrayUtilTest method testIota.

@Test
public void testIota() {
    IntArrayList list = ArrayUtil.iota(15);
    assertEquals(15, list.buffer.length);
    assertEquals(15, list.elementsCount);
    assertEquals(14 / 2.0 * (14 + 1), Arrays.stream(list.buffer).sum());
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) Test(org.junit.jupiter.api.Test)

Example 49 with IntArrayList

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

the class PrepareRoutingSubnetworksTest method testKeepLargestNetworks.

@Test
public void testKeepLargestNetworks() {
    GraphHopperStorage g = createSubnetworkTestStorage();
    PrepEdgeFilter filter = new PrepEdgeFilter(carFlagEncoder);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder));
    List<IntArrayList> components = instance.findSubnetworks(filter);
    assertEquals(3, components.size());
    int removedEdges = instance.keepLargeNetworks(filter, components);
    assertEquals(8, removedEdges);
    instance.markNodesRemovedIfUnreachable();
    g.optimize();
    assertEquals(8, g.getNodes());
    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(g));
    components = instance.findSubnetworks(filter);
    assertEquals(1, components.size());
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 50 with IntArrayList

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

the class PrepareRoutingSubnetworksTest method testTarjan.

@Test
public void testTarjan() {
    GraphHopperStorage g = createSubnetworkTestStorage();
    // Requires a single vehicle type, otherwise we throw.
    final EdgeFilter filter = new DefaultEdgeFilter(carFlagEncoder, false, true);
    TarjansSCCAlgorithm tarjan = new TarjansSCCAlgorithm(g, filter, false);
    List<IntArrayList> components = tarjan.findComponents();
    assertEquals(4, components.size());
    assertEquals(IntArrayList.from(13, 5, 3, 7, 0), components.get(0));
    assertEquals(IntArrayList.from(2, 4, 12, 11, 8, 1), components.get(1));
    assertEquals(IntArrayList.from(10, 14, 6), components.get(2));
    assertEquals(IntArrayList.from(15, 9), components.get(3));
}
Also used : PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) IntArrayList(com.carrotsearch.hppc.IntArrayList) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

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