Warning: run the following code in a fresh Mma session, as some symbols could be shadowed (depending on your Mma version)
While trying to answer this question, I fell into the following:
(* Let's load a large Directed Graph and convert it to Combinatorica *)
g = Graph@Union@Flatten[
Thread[DirectedEdge @@ ##] & /@ Select[{#, IsotopeData[#, "DaughterNuclides"]} & /@
IsotopeData[], #[[2]] != {} &]];
Needs["GraphUtilities`"]
<< Combinatorica`
cg = ToCombinatoricaGraph[g];
Girth[cg] gives the length of a shortest cycle in a simple graph g.
So, let's check if cg
is Simple and calculate its Girth:
{SimpleQ@cg, Girth@cg}
(*
-> {True, 3}
*)
So there is at least one Cycle in cg
of length 3.
But look what happens when we try to find it by the two available methods in Combinatorica
:
{ExtractCycles@cg, FindCycle@cg}
(*
-> {{},{}}
*)
So, two questions:
- Is this a bug?
- What is the easiest way to find all cycles in
g
without using Combinatorica?
Edit
BTW, the (now) standard Graph functionality also detects cycles:
AcyclicGraphQ[g]
(* -> False *)
g1 = FromOrderedPairs[ EdgeList@g /. Thread[Rule[VertexList[g], Range@VertexCount@g]] /. DirectedEdge -> List, Type -> Directed]; Print@{Girth@g1,FindCycle@g1};
and the result is the same. Thanks for the pointer! $\endgroup$