3
$\begingroup$

Can someone provide an example of a Combinatorica-based graph which uses ShowGraph and Graph and takes in an explicitly defined list of edges (not some auto-generated graph). I have not been able to find any documentation which describes the expected input format.

$\endgroup$
  • 2
    $\begingroup$ You can find the input format for the edges and vertices for Combinatorica`Graph under More Information on the page Combinatorica/ref/Graph in the documentation center $\endgroup$ – Heike May 6 '12 at 22:26
  • 1
    $\begingroup$ Just in case someone wants Heike's link on the web: reference.wolfram.com/mathematica/Combinatorica/ref/Graph.html $\endgroup$ – Dr. belisarius May 7 '12 at 1:20
5
$\begingroup$

Two examples:

   Needs["Combinatorica`"]
   GraphicsRow[
    {ShowGraph[ 
       g1 = Graph[{{{1, 2}}, {{2, 3}}, {{3, 1}}}, {{{1, 1}}, {{2, 1}}, {{3, 3}}}], 
        VertexNumber -> True], 
     ShowGraph[
      g2 = Graph[
            {{{1, 2}, EdgeLabel -> "lbl1"}, {{2, 3}, EdgeColor -> Green}, 
             {{3, 1}, EdgeLabel -> "(3,1)", EdgeDirection -> True, EdgeLabel -> True, 
                EdgeLabelPosition -> UpperLeft}}, 
           {{{1, 1}, VertexLabel -> True, VertexLabelColor -> Blue, 
   VertexLabelPosition -> LowerRight}, 
             {{2, 1}, VertexNumber -> True, VertexNumberColor -> Orange}, 
             {{3, 3}}}]
    ]}]

to get

enter image description here

EDIT: Before loading Combinatorica you can transform the data using:

   toCombGrphData[gr_] :=  gr // 
       Sequence @@ {EdgeList[#] /. UndirectedEdge[x__] :> {List[x]}, 
                    List /@ (AbsoluteOptions[#, VertexCoordinates][[2]])} &

Update: For Version 9, we need to change the part specification above from [[2]] to [[1,2]] (thanks: @sam84).

Example:

  combgrpg = toCombGrphData[CompleteGraph[3]]

gives the edge list and vertex coordinates needed as input for Combinatorica ``Graph`:

  (*  Sequence[{{{1, 2}}, {{1, 3}}, {{2, 3}}}, {{{0.866025, -0.5}}, {{-0.866025, -0.5}}, {{-2.44929*10^-16, 1.}}}] *)

Then,

  Needs["Combinatorica`"]

  ShowGraph[Graph[combgrph]]

gives

enter image description here

$\endgroup$
  • $\begingroup$ I tried your example in Mathematica 9, but I obtain the following error: Part::partw: Part 2 of {VertexCoordinates->{{-0.866025,-0.5},{0.866025,-0.5},{1.83697*10^-16,1.}}} does not exist. >> $\endgroup$ – sam84 Apr 18 '14 at 17:19
  • $\begingroup$ @sam84, thank you. I will check if i can fix it. $\endgroup$ – kglr Apr 18 '14 at 17:47
  • $\begingroup$ I fixed it. This function works: toCombGrphData[gr_] := gr // Sequence @@ {EdgeList[#] /. UndirectedEdge[x__] :> {List[x]}, List /@ (AbsoluteOptions[#, VertexCoordinates][[1, 2]])} & $\endgroup$ – sam84 Apr 19 '14 at 9:32
  • $\begingroup$ It is possible to extend the function toCombGrphData so to inclue also edge weights? Thanks $\endgroup$ – sam84 Apr 19 '14 at 9:33
  • $\begingroup$ @sam84, can't recall the Combinatorica syntax for using edge weights. If you have simple example handy, perhaps you can post a new question. (Thanks for the fix; I will update the post with the fix.) $\endgroup$ – kglr Apr 19 '14 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.