use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class CHTurnCostTest method testFindPath_highlyConnectedGraph_compareWithDijkstra.
@RepeatedTest(10)
public void testFindPath_highlyConnectedGraph_compareWithDijkstra() {
// In this test we use a random contraction order and run many random routing queries. The results are checked
// by comparing them to the results of a standard dijkstra search.
// If a test fails use the debug output to generate the graph creation code for further debugging!
// 0 - 1 - 2 example for size=3
// | x | x |
// 3 - 4 - 5
// | x | x |
// 6 - 7 - 8
// for large sizes contraction takes very long because there are so many edges
final int size = 4;
final int maxDist = 4;
final int numQueries = 1000;
long seed = System.nanoTime();
LOGGER.info("Seed used to generate graph: {}", seed);
final Random rnd = new Random(seed);
int edgeCounter = 0;
// horizontal edges
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size - 1; ++j) {
final int from = i * size + j;
final int to = from + 1;
final double dist = nextDist(maxDist, rnd);
GHUtility.setSpeed(60, true, true, encoder, graph.edge(from, to).setDistance(dist));
LOGGER.trace("final EdgeIteratorState edge{} = graph.edge({},{},{},true);", edgeCounter++, from, to, dist);
}
}
// vertical edges
for (int i = 0; i < size - 1; ++i) {
for (int j = 0; j < size; ++j) {
final int from = i * size + j;
final int to = from + size;
double dist = nextDist(maxDist, rnd);
GHUtility.setSpeed(60, true, true, encoder, graph.edge(from, to).setDistance(dist));
LOGGER.trace("final EdgeIteratorState edge{} = graph.edge({},{},{},true);", edgeCounter++, from, to, dist);
}
}
// diagonal edges
for (int i = 0; i < size - 1; ++i) {
for (int j = 0; j < size; ++j) {
final int from = i * size + j;
if (j < size - 1) {
final double dist = nextDist(maxDist, rnd);
final int to = from + size + 1;
GHUtility.setSpeed(60, true, true, encoder, graph.edge(from, to).setDistance(dist));
LOGGER.trace("final EdgeIteratorState edge{} = graph.edge({},{},{},true);", edgeCounter++, from, to, dist);
}
if (j > 0) {
final double dist = nextDist(maxDist, rnd);
final int to = from + size - 1;
GHUtility.setSpeed(60, true, true, encoder, graph.edge(from, to).setDistance(dist));
LOGGER.trace("final EdgeIteratorState edge{} = graph.edge({},{},{},true);", edgeCounter++, from, to, dist);
}
}
}
graph.freeze();
EdgeExplorer inExplorer = graph.createEdgeExplorer(AccessFilter.inEdges(encoder.getAccessEnc()));
EdgeExplorer outExplorer = graph.createEdgeExplorer(AccessFilter.outEdges(encoder.getAccessEnc()));
// add turn costs or restrictions
for (int node = 0; node < size * size; ++node) {
EdgeIterator inIter = inExplorer.setBaseNode(node);
while (inIter.next()) {
EdgeIterator outIter = outExplorer.setBaseNode(node);
while (outIter.next()) {
// do not modify u-turn costs
if (inIter.getEdge() == outIter.getEdge()) {
continue;
}
int cost = nextCost(rnd);
setCostOrRestriction(inIter, outIter, node, cost);
}
}
}
IntArrayList contractionOrder = getRandomIntegerSequence(graph.getNodes(), rnd);
checkStrict = false;
compareCHWithDijkstra(numQueries, contractionOrder.toArray());
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class CHTurnCostTest method testFindPath_compareWithDijkstra_zeroWeightLoops.
@Test
public void testFindPath_compareWithDijkstra_zeroWeightLoops() {
// /|
// 0 -> 1 -> 2 -> 3 --
// | \|
// 4
GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 1).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(1, 2).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(2, 3).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 3).setDistance(0));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 3).setDistance(0));
GHUtility.setSpeed(60, true, false, encoder, graph.edge(3, 4).setDistance(1));
graph.freeze();
IntArrayList expectedPath = IntArrayList.from(0, 1, 2, 3, 4);
checkPath(expectedPath, 4, 0, 0, 4, new int[] { 2, 0, 4, 1, 3 });
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class Path method calcNodes.
/**
* @return the uncached node indices of the tower nodes in this path.
*/
public IntIndexedContainer calcNodes() {
final IntArrayList nodes = new IntArrayList(edgeIds.size() + 1);
if (edgeIds.isEmpty()) {
if (isFound()) {
nodes.add(endNode);
}
return nodes;
}
int tmpNode = getFromNode();
nodes.add(tmpNode);
forEveryEdge(new EdgeVisitor() {
@Override
public void next(EdgeIteratorState eb, int index, int prevEdgeId) {
nodes.add(eb.getAdjNode());
}
@Override
public void finish() {
}
});
return nodes;
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class RealtimeFeed method collectWithPadding.
private static int[] collectWithPadding(Stream<PtGraph.PtEdge> boardEdges) {
IntArrayList result = new IntArrayList();
boardEdges.forEach(boardEdge -> {
while (result.size() < boardEdge.getAttrs().stop_sequence) {
// Padding, so that index == stop_sequence
result.add(-1);
}
result.add(boardEdge.getId());
});
return result.toArray();
}
use of com.carrotsearch.hppc.IntArrayList in project graphhopper by graphhopper.
the class BinaryHeapTestInterface method update.
@Test
default void update() {
create(10);
push(9, 3.6f);
push(5, 2.1f);
push(3, 2.3f);
update(3, 0.1f);
assertEquals(3, peekId());
update(3, 10.f);
assertEquals(5, peekId());
update(9, -1.3f);
assertEquals(9, peekId());
assertEquals(-1.3f, peekVal(), 1.e-6);
IntArrayList polled = new IntArrayList();
while (!isEmpty()) {
polled.add(poll());
}
assertEquals(IntArrayList.from(9, 5, 3), polled);
}
Aggregations