Re: Graph cycles in Mathematica 8
- To: mathgroup at smc.vnet.net
- Subject: [mg115952] Re: Graph cycles in Mathematica 8
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Thu, 27 Jan 2011 03:40:32 -0500 (EST)
- References: <ihorn7$hkj$1@smc.vnet.net>
Hi Guillermo,
There are two cycle functions in Mathematica 8:
FindEulerianCycle: find a cycle that traverses every edge exactly once
FindHamiltonianCycle: find a cycle that traverses every vertex exactly
once
but these are probably not the ones you were refering to.
A workaround would indeed be to convert the graph to a Combinatorica
graph:
<< Combinatorica`
myM8Graph = System`Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge]
3,
3 \[UndirectedEdge] 1, 3 \[UndirectedEdge] 4,
4 \[UndirectedEdge] 4}]
(* I add the system context as the M8 Graph is shadowed by the
Combinatorica function of the same name *)
myCombinatoricaGraph =
FromAdjacencyMatrix[Normal[AdjacencyMatrix[myM8Graph]]];
(* FromAdjacencyMatrix is from Combinatorica whereas AdjacencyMatrix
is from M8; Normal is used because FromAdjacencyMatrix doesn't seem to
dig SparseArrays *)
ShowGraph[myCombinatoricaGraph]
FindCycle[myCombinatoricaGraph]
==> {4, 4}
Hope this helps.
Cheers -- Sjoerd
On Jan 26, 11:06 am, abramson <g.abram... at gmail.com> wrote:
> Hi. The functions FindCycle, ExtractCycle, etc, from the Combinatorica
> package, do not work with the new Graphs implemented in Mathematica 8.
> Is anybody aware of similar functions to find cycles of the new Graph
> objects, or else a way to convert them to objects that FindCycle could
> use? Thanks in advance.
> Guillermo