graph icon indicating copy to clipboard operation
graph copied to clipboard

dijkstra_shortest_paths_no_init supports pruning on distances

Open wygos opened this issue 11 years ago • 8 comments

When the distance map is given and the newly discovered distance
is worse than the distance stored in the distance map,
the vertex is not even added to the priority queue.

wygos avatar Jul 23 '14 10:07 wygos

I'm not sure about this. It seems to me that if the distance decreases, line 145 of dijkstra_shortest_path.hpp, then there's a call to dijkstra_queue_update() which certainly appears to update the queue (m_Q). Perhaps I'm not clear on what you're trying to achieve but the priority queue does seem to be updated when the distance decreases. Can you check this again and give more details if you still believe it's broken?

Belcourt avatar Nov 02 '14 21:11 Belcourt

The main issue is to make dijkstra_shortest_paths_no_init support more efficient. This is done by pruning the vertices, that are never going to be improved.

Example:

Assume my graph is as follows:

1 --- 2 --- 3 --- 4 --- 5 --- 6

Assume that weights of all edges equals 1, also assume that we run dijkstra_shortest_paths_no_init, starting from vertex number 1 and we provide the following distance map:

1 -> 0 2 -> infinity 3 -> infinity 4 -> 1 5 -> 1 6 -> 1

Vertices 1,2,3 are initialized in the standard way, but vertices are initialized with smaller values. In this case dijkstra_shortest_paths_no_init supports should never visit vertex number 4 since the corresponding shortest path weight equals 2 > 1. The vertices 5 and 6 shouldn't be even discovered.

If one'd like to see a natural use case, please see this algorithm: http://paal.mimuw.edu.pl/do_vv_2kminus1.html (now, in order to gain performance, the nasty workaround is used in this code)

The second motivation for this change is that dijkstra is NOT BFS. It was impemented this way using not very intuitive vistor patern usage. Maybe BFS could be seen as special case of dijkstra with appropriate queue, but not the other way around (current version).

wygos avatar Nov 12 '14 12:11 wygos

I'm helping out with the PR backlog. Looks like you have a code change, no test, and no new examples will be needed. This is very old and I do not know if it is still relevant. Could I get @wygos to chime in? This is to let you know and help me prioritize PR's.

anadon avatar Aug 31 '18 18:08 anadon

Hi, I'm happy to hear that your working on it! It is still relevant. In some special cases, the algorithm is inefficient. There was a discussion in the boost mailing list:

https://lists.boost.org/Archives/boost/2015/10/226337.php

and the consensus was, that the patch should be accepted.

Regards,

Piotr

wygos avatar Aug 31 '18 19:08 wygos

Since this looks more like a feature, I'll try to include it in the second batch of merges. Thanks!

anadon avatar Aug 31 '18 19:08 anadon

@wygos Can you rebase your PR on devel?

anadon avatar Oct 15 '18 19:10 anadon

@wygos Can you rebase your PR on devel?

DONE. Note that github shows incorrect diffs but after fetching changes everything is OK.

wygos avatar Oct 22 '18 08:10 wygos

@wygos Upstream devel has TravisCI tests which your is missing. Your tests are also failing. Please rebase.

anadon avatar Nov 01 '18 14:11 anadon