How edge indexing works in graphhopper?

248 views Asked by At

I'm here with a new question.

I'm making a custom algorithm that need precomputed data for the graph edges. I use the AllEdgesIterator like this :

AllEdgesIterator it = graph.getAllEdges();
int nbEdges = it.getCount();
int count = 0;

int[] myData = new int[nbEdges];

while (it.next())
{
    count++;
    ...
}

The first weird thing is that nbEdges is equal to 15565 edges but count is only equal to 14417. How is it possible ?

The second weird thing is when I run my custom A* : I simply browse nodes using the outEdgeExplorer but I get an IndexOutOfBound at index 15569 on myData array. I thought that the edge indexes were included in [0 ; N-1] where N is the number of edges, is it really the case ?

What could be happening here ? By the way, I have disabled graph contraction hierarchies.

Thank you for answering so fast every time !

1

There are 1 answers

2
Karussell On BEST ANSWER

The first weird thing is that nbEdges is equal to 15565 edges but count is only equal to 14417. How is it possible ?

This is because of the 'compaction' where unreachable subnetworks are removed, but currently only nodes are removed from the graph the edges are just disconnected and stay in the edges-'array' marked as deleted. So iter.getCount is just an upper limit but the AllEdgeIterator excludes such unused edges correctly when iterating and has the correct count. But using iter.getCount to allocate your custom data array is the correct thing to do.

Regarding the second question: that is probably because the QueryGraph introduces new virtual edges with a bigger edgeId as iter.getCount. Depending on the exact scenario there are different solutions like just excluding or using the original edge instead etc