1

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 !

user3890394
  • 99
  • 1
  • 7

1 Answers1

1

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

Karussell
  • 17,085
  • 16
  • 97
  • 197
  • Ok I see, could you explain a little more the virtual edges ? What are they and why do you need that ? Are they important or can I skip them ? How can I know what is the original edge ? Thanks ! – user3890394 Jun 24 '15 at 08:23
  • 1
    They are introduced between existing junctions and the query points so that the algorithms do not need special handling for these points. The QueryResult of every point (returned from locationIndex.findClosest) will contain the EdgeIteratorState pointing to the original edge. – Karussell Jun 24 '15 at 13:36