Cycles are reported incorrectly #2198
Labels
Bug
The observed behaviour is incorrect or unexpected.
S-Nice to have
The bug fix or feature would be nice but doesn't currently have much negative impact.
Describe the bug
I just noticed that
Swarm.Util.Graph.getGraphCycles
does not actually find directed cycles, and thusfailOnCyclicGraph
could output an error message indicating a cycle that does not exist. Note that whether an error is generated is correct ---failOnCyclicGraph
indeed fails precisely when the graph has directed cycles. However, when there are directed cycles, it may print something which is not a directed cycle.To Reproduce
The smallest example I could come up with is the following scenario description:
Trying to load this with e.g.
scripts/play.sh -i data/scenarios/bad.yaml
results in an error message:It is correct to reject this scenario, but the reported cycle
a -> b -> c -> d
is bogus:b
does not depend onc
. In fact, there are two cycles,a -> b
anda -> c -> d
.Expected behavior
The error message should report a true cycle, i.e. a sequence of nodes where each depends on the next, and the last depends on the first.
Additional context
stronglyConnComp
computes a topologically sorted list of strongly connected components (SCCs). It is true that every component will be a singleton vertex (AcyclicSCC
) if and only if the graph has no directed cycles. However, in the case that there are nontrivial SCCs, the list of vertices reported in a (confusingly named)CyclicSCC
(orNECyclicSCC
) is in no particular order and need not represent a cycle. The above example constructs a graph with four vertices, where a and b are mutually reachable and there is a directed cycle a -> c -> d -> a. In this case all four vertices are part of the same SCC (since any vertex can be reached from any other) but they obviously do not form a cycle. Even in the case where an SCC does actually consist of a cycle and nothing else, I am not even sure it is guaranteed that the vertices will be returned in order around the cycle. It seems a reasonable assumption, but the documentation does not specify.I plan to fix this shortly but wanted to file an issue for discussion/posterity.
The text was updated successfully, but these errors were encountered: