Adds deterministic version for boruvka and dijkstra algorithm. #398
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The dijkstra() a boruvka() algorithms of CXXGraph (and perhaps others, but we used these two) are non-deterministic; ie they return different results for the same input under some conditions; especially on different platforms (Windows vs Linux).
This is problematic:
1)It breaks unit tests.
2)It introduces non-determinism to the whole program, which is deadly when you want to reproduce some problem (it might just not happen again).
So I added deterministic versions of these two algorithms to CXXGraph:
boruvka_deterministic()
dijkstra_deterministic()
dijkstra_deterministic2()
They work as the original ones, but always return the same result for the same input, not matter the platform.
Well, almost:
dijkstra_deterministic() uses this method of ensuring determinism:
https://stackoverflow.com/questions/69649312/how-to-specify-tie-breaking-logic-in-boost-dijkstra-shortest-paths-dijkstra?noredirect=1&lq=1
But the method can still introduce non-determinism in some very special cases
(namely, two paths have the same length(weights sum) AND the same sum of vertex ids, which is improbable, but can happen).
So I added
dijkstra_deterministic2()
which lexicographically compares the whole paths. This assures 100% determinism; but it is a bit more spatially and temporaly intensive.
So I have kept both versions and let the user choose the version he prefers (99% determinism, or 100% determinism at a cost).