Say I have a simple multigraph like so:
edges = {DirectedEdge[a, b], DirectedEdge[b, c], DirectedEdge[c, a]};
g = Graph[Join[edges, edges]]
FindCycle
has no trouble discovering a length-3 cycle, however it unexpectedly fails to find the length-6 cycle that takes "two laps" around the vertices.
FindCycle[g, {3}]
FindCycle[g, {6}]
(* output:
{{a \[DirectedEdge] b, b \[DirectedEdge] c, c \[DirectedEdge] a}}
{}
*)
I initially just assumed Mathematica did not have the capability to fully support multigraphs like this, but FindEulerianCycle
happily identifies the length-6 cycle as expected:
FindEulerianCycle[g]
(* output:
{{a \[DirectedEdge] b, b \[DirectedEdge] c, c \[DirectedEdge] a,
a \[DirectedEdge] b, b \[DirectedEdge] c, c \[DirectedEdge] a}}
*)
It seems bizarre that FindEulerianCycle[g]
can find a length-n
cycle yet FindCycle[g, {n}]
returns nothing.
So my questions are: Is there a good way (using FindCycle
or otherwise) to properly handle "multi-cycles" (which are not Eulerian in general)? Is the observed behavior a bug or is there something convincing in the documentation that indicates it's by design?