Re: Convert directed graph to undirected graph

• To: mathgroup at smc.vnet.net
• Subject: [mg111228] Re: Convert directed graph to undirected graph
• From: Murray Eisenberg <murray at math.umass.edu>
• Date: Sat, 24 Jul 2010 05:07:24 -0400 (EDT)

```Of course the original graph-like object was a list of rules and not a
Combinatorica-type object with head Graph. To get back to the original
lit-of-rules object, one can use the following function (I believe this
was posted some time ago to MathGroup, but at the moment I forget its
author):

RuleListFromGraph[Graph[edges_, vertices_, ___]] :=
Module[{vrules},
vrules = DeleteCases[
Length[vertices]] -> (VertexLabel /.
vertices[[All, 2 ;;]])], _ -> VertexLabel];
Replace[
Transpose[{Rule @@@ (edges[[All, 1]] /. vrules),
EdgeLabel /. edges[[All, 2 ;;]]}], {a_, EdgeLabel} -> a, {1}]]

In the example in the post below, one obtains:

RuleListFromGraph[gr1u]
{1->2,1->3,1->4,2->3,2->4,4->4}

Comment: I really wish WRI would at very long last completely
rationalize the dichotomy between the newer kernel functions for dealing
with lists-of-rules as graphs, on the one hand, and Combinatorica
Graph-objects, on the other hand.

On 7/23/2010 7:09 AM, juan flores wrote:
> Needs["Combinatorica`"];
> Needs["GraphUtilities`"];
> gr1 =
>   ToCombinatoricaGraph[{1 ->  2, 2 ->  1, 3 ->  1, 3 ->  2, 4 ->  1, 4 ->  2,
>      4 ->  4}]
> ShowGraph[gr1]
> gr1u = MakeUndirected[gr1]
> ShowGraph[gr1u]

--
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

```

• Prev by Date: Re: A Question About Directive
• Next by Date: Re: surprising comparison of Mathematica 5.2 and 7.0
• Previous by thread: Re: Convert directed graph to undirected graph
• Next by thread: A ODE I need to solve