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());
}
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));
}
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);
}
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;
}
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;
}
}
}
Aggregations