Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: new Graph function + combinatorica: various problems
Replies: 8   Last Post: May 5, 2012 4:12 AM

 Messages: [ Previous | Next ]
 Murray Eisenberg Posts: 2,105 Registered: 12/6/04
Re: new Graph function + combinatorica: various problems
Posted: May 3, 2012 10:23 PM

This was discussed in MathGroup about three years ago. Here are some
functions towards a solution that were provided in responses there.

(* Convert Combinatorica type Graph object to the list of rules expected
by GraphPlot *)

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}]]

(* Preserve original coordinates of vertices lost by the above *)
GetVertexCoordinates[Graph[edges_, vertices_, ___]] :=
vertices[[All, 1]]

(* Example *)
g = SetEdgeLabels[
SetVertexLabels[Wheel[4], Range[4]],
Characters["defabc"]];
GraphPlot[RuleListFromGraph[g], VertexLabeling -> True,
VertexCoordinateRules -> GetVertexCoordinates[g]]

On 5/3/12 4:35 AM, another.schmidt@googlemail.com wrote:
> nice. Can anybody tell me a convenient way to convert an explicit Combinatorica graph g to a System Graph g2 without using wrappers?
> Thanks a lot.
> Jesch
>

--
Murray Eisenberg murray@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