Repository navigation
Add parameter for FW negative cycle detection - #1097
kennyballou wants to merge 1 commit into
Conversation
| for (int k = minDegreeTwo; k < n; k++) { | ||
| for (int i = minDegreeOne; i < n; i++) { | ||
| if (i == k) { | ||
| if (!detectNegativeCycles && i == k) { |
There was a problem hiding this comment.
With this change, the distance matrix, for your example graph, will become
[[-1, -1]
[-2, -2]]
Could you explain how is this correct?
There was a problem hiding this comment.
Normally, when a graph does not contain a strictly negative cycle, no path through the graph will be "closer" than a self-loop on a node. This is the basis of the heuristic of skipping specific iterations. However, when a negative cycle is possible or a negative cycle does appear in the graph, there is a path that is not the self-loop that is "closer" than the self loop. The Floyd-Warshall algorithm can detect these negative cycles (when performed without the optimizing heuristic) and they appear in the diagonal of the weighted adjacency matrix.
I'm going to amend the PR with another test case for non-negative cycle graphs.
In b1f9e1e ("Implemented heuristics for Floyd-Warshall", Sat Jul 14 12:16:16 2018 +0300), some heuristics were added to improve the performance of the Floyd-Warshall algorithm. However, as an unintended consequence, the FW algorithm could no longer be used to detect negative cycles. Add a parameter to the algorithm constructor, maintaining the existing behavior, which enables users to detect negative cycle detection. Furthermore, add a method to check for negative cycles. This resolves jgrapht#1096. Signed-off-by: Kenny Ballou <[email protected]>
fb191c3 to
4157eb2
Compare
|
I've blocked some time in my calendar on Friday to work on my backlog of reviews... |
In b1f9e1e ("Implemented heuristics for Floyd-Warshall", Sat Jul 14
12:16:16 2018 +0300), some heuristics were added to improve the
performance of the Floyd-Warshall algorithm. However, as an unintended
consequence, the FW algorithm could no longer be used to detect negative
cycles.
Add a parameter to the algorithm constructor, maintaining the existing
behavior, which enables users to detect negative cycle detection.
Furthermore, add a method to check for negative cycles.
This resolves #1096.
HISTORY.mdorCONTRIBUTORS.md