use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class LandmarkStorage method estimateMaxWeight.
/**
* This method returns the maximum weight for the graph starting from the landmarks
*/
private double estimateMaxWeight(List<IntArrayList> graphComponents, EdgeFilter accessFilter) {
double maxWeight = 0;
int searchedSubnetworks = 0;
Random random = new Random(0);
// the maximum weight can only be an approximation so there is only a tiny improvement when we would do this for
// all landmarks. See #2027 (1st commit) where only 1 landmark was sufficient when multiplied with 1.01 at the end
// TODO instead of calculating the landmarks again here we could store them in landmarkIDs and do this for all here
int[] tmpLandmarkNodeIds = new int[3];
for (IntArrayList subnetworkIds : graphComponents) {
if (subnetworkIds.size() < minimumNodes)
continue;
searchedSubnetworks++;
int maxRetries = Math.max(subnetworkIds.size(), 100);
for (int retry = 0; retry < maxRetries; retry++) {
int index = random.nextInt(subnetworkIds.size());
int nextStartNode = subnetworkIds.get(index);
LandmarkExplorer explorer = findLandmarks(tmpLandmarkNodeIds, nextStartNode, accessFilter, "estimate " + index);
if (explorer.getFromCount() < minimumNodes) {
LOGGER.error("method findLandmarks for " + createPoint(graph, nextStartNode) + " (" + nextStartNode + ")" + " resulted in too few visited nodes: " + explorer.getFromCount() + " vs expected minimum " + minimumNodes + ", see #2256");
continue;
}
// starting
for (int lmIdx = 0; lmIdx < tmpLandmarkNodeIds.length; lmIdx++) {
int lmNodeId = tmpLandmarkNodeIds[lmIdx];
explorer = new LandmarkExplorer(graph, this, weighting, traversalMode, accessFilter, false);
explorer.setStartNode(lmNodeId);
explorer.runAlgo();
maxWeight = Math.max(maxWeight, explorer.getLastEntry().weight);
}
break;
}
}
if (maxWeight <= 0 && searchedSubnetworks > 0)
throw new IllegalStateException("max weight wasn't set although " + searchedSubnetworks + " subnetworks were searched (total " + graphComponents.size() + "), minimumNodes:" + minimumNodes);
// especially when external landmarks are provided, but also because we do not traverse all landmarks
return maxWeight * 1.008;
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class EdgeBasedTarjanSCCTest method withStartEdges_comparison.
@RepeatedTest(20)
public void withStartEdges_comparison() {
// we test the case where we specify all start edges (in this case the behavior should be the same for both methods)
GraphHopperStorage g = new GraphBuilder(em).create();
long seed = System.nanoTime();
Random rnd = new Random(seed);
GHUtility.buildRandomGraph(g, rnd, 500, 2, true, true, encoder.getAccessEnc(), encoder.getAverageSpeedEnc(), 60d, 0.8, 0.7, 0);
ConnectedComponents components = EdgeBasedTarjanSCC.findComponents(g, fwdAccessFilter, true);
IntArrayList edges = new IntArrayList();
AllEdgesIterator iter = g.getAllEdges();
while (iter.next()) edges.add(iter.getEdge());
ConnectedComponents componentsForStartEdges = EdgeBasedTarjanSCC.findComponentsForStartEdges(g, fwdAccessFilter, edges);
compareResults(g, seed, components, componentsForStartEdges);
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworksTest method getSubnetworkEdges.
private static IntArrayList getSubnetworkEdges(GraphHopperStorage graph, FlagEncoder encoder) {
BooleanEncodedValue subnetworkEnc = graph.getEncodingManager().getBooleanEncodedValue(Subnetwork.key(encoder.toString()));
IntArrayList result = new IntArrayList();
AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
if (iter.get(subnetworkEnc)) {
result.add(iter.getEdge());
}
}
return result;
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class TarjanSCCTest method buildComponentSet.
/**
* Takes a list of arrays like [[0,1,3],[2,4],[6]] and turns it into a Set like
* {[0:[0,1,3], 1:[0,1,3], 2:[2,4], 3:[0,1,3], 4:[2,4], 6:[6]}
*/
public static Set<IntWithArray> buildComponentSet(List<IntArrayList> arrays) {
Set<IntWithArray> result = new HashSet<>();
for (IntArrayList c : arrays) {
c.trimToSize();
Arrays.sort(c.buffer);
for (IntCursor cursor : c) {
result.add(new IntWithArray(cursor.value, c));
}
}
return result;
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class TarjanSCCTest method testFindComponents.
@Test
public void testFindComponents() {
GraphHopperStorage graph = new GraphBuilder(em).create();
// big network (has two components actually, because 9->12 is a one-way)
// ---
// / \
// 4 < 1 - 2
// | |
// <-- 8 - 11 - 12 < 9 - 15
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 4).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 8).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 4).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(8, 4).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 11).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(12, 11).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(9, 12).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(9, 15).setDistance(1));
// large network
// 5 --------
// | |
// 3 - 0 - 13
// \ |
// 7
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 13).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 3).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 7).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 7).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 5).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(13, 5).setDistance(1));
// small network
// 6 - 14 - 10
GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 14).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(10, 14).setDistance(1));
TarjanSCC.ConnectedComponents scc = TarjanSCC.findComponentsRecursive(graph, edgeFilter, false);
List<IntArrayList> components = scc.getComponents();
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));
assertEquals(16, scc.getNodes());
assertEquals(0, scc.getSingleNodeComponents().cardinality());
assertEquals(components.get(1), scc.getBiggestComponent());
}
Aggregations