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 *)
Answer
I don't think it's a bug. Directed radioactive decay graphs shouldn't have cycles by definition and AcyclicGraphQ
doesn't see them either:
AcyclicGraphQ@g
True
You don't seem to have heeded your own warning to start with a fresh kernel, as playing around with the code for a while gave me False
too.
The output of ExtractCycles
and FindCycle
is therefore correct.
Girth
doesn't seem to take directionality into account when determining cycles:
Cyclic directed graph:
Girth@ ToCombinatoricaGraph@
System`Graph[{1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3, 3 \[DirectedEdge] 1}]
3
Acyclic directed graph (note the reversed direction of the last edge):
Girth@ToCombinatoricaGraph@
System`Graph[{1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3, 1 \[DirectedEdge] 3}]
3
Comments
Post a Comment