Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have some code that builds a graph and some vertex coordinates, but when I evaluate it I get a message that the list of coordinates is not valid and the graph is not valid and it shows the output as an unevaluated GraphPlot. Then if I evaluate the unevaluated GraphPlot manually it works fine. I have tried using Evaluate manually, but no luck.

I evaluate this:

GraphPlot[edges, VertexCoordinateRules -> coords]

I get these:

GraphPlot::vpr: Value of option VertexCoordinateRules -> {{1,2,3,4,5,6,7,8,9,10,11}->{1.,1.79586*10^-10},{1,10,3,11,7,6,5,9,8,2,4}->{0.,2.6938*10^-10},{8,9,4,1,2,5,7,3,6,10,11}->{2.,0.}} is not a valid list of coordinate rules. >>

GraphPlot::grph: {{1,2,3,4,5,6,7,8,9,10,11}->{1,10,3,11,7,6,5,9,8,2,4},{1,2,3,4,5,6,7,8,9,10,11}->{8,9,4,1,2,5,7,3,6,10,11},{1,10,3,11,7,6,5,9,8,2,4}->{1,2,3,4,5,6,7,8,9,10,11},{1,10,3,11,7,6,5,9,8,2,4}->{9,8,11,1,10,7,5,3,6,2,4},{8,9,4,1,2,5,7,3,6,10,11}->{3,6,1,8,9,2,7,4,5,10,11},{8,9,4,1,2,5,7,3,6,10,11}->{8,10,4,11,7,5,2,6,3,9,1}} is not a valid graph. >>

GraphPlot[{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} -> {1, 10, 3, 11, 7, 6,
     5, 9, 8, 2, 4}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} -> {8, 9, 4, 
    1, 2, 5, 7, 3, 6, 10, 11}, {1, 10, 3, 11, 7, 6, 5, 9, 8, 2, 
    4} -> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, {1, 10, 3, 11, 7, 6, 5,
     9, 8, 2, 4} -> {9, 8, 11, 1, 10, 7, 5, 3, 6, 2, 4}, {8, 9, 4, 1, 
    2, 5, 7, 3, 6, 10, 11} -> {3, 6, 1, 8, 9, 2, 7, 4, 5, 10, 11}, {8,
     9, 4, 1, 2, 5, 7, 3, 6, 10, 11} -> {8, 10, 4, 11, 7, 5, 2, 6, 3, 
    9, 1}}, VertexCoordinateRules -> {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
     11} -> {1., 1.79586*10^-10}, {1, 10, 3, 11, 7, 6, 5, 9, 8, 2, 
     4} -> {0., 2.6938*10^-10}, {8, 9, 4, 1, 2, 5, 7, 3, 6, 10, 
     11} -> {2., 0.}}]

Then if I manually evaluate the output it works fine. Here is the full code. I haven't figured out a smallest repro yet.

{op1, op2} = GroupGenerators@MathieuGroupM11[];
elems = {Range[11]};
edges = {};
coords = {};
frames = {};
frames = Reap@
  While[Length@elems < 10, 
   AppendTo[elems, Permute[#, op1]]; AppendTo[elems, Permute[#, op2]];
      AppendTo[edges, # -> Permute[#, op1]]; 
     AppendTo[edges, # -> Permute[#, op2]]; & /@ elems; 
   elems = Union[elems]; edges = Union[edges]; 
   Sow[g = GraphPlot[edges, 
      VertexCoordinateRules -> 
       If[Length@coords > 0, coords, Automatic]]];
   coords = 
    Union[coords, 
     Rule @@@ 
      Transpose@{Cases[g, Tooltip[_, a_] -> a, Infinity], 
        Cases[g, (VertexCoordinateRules -> a_) -> a, 
          Infinity][[1]]}];]
share|improve this question
    
Related (we should migrate it) stackoverflow.com/questions/5649379/… –  belisarius Jan 25 '13 at 20:19
    
It might be hard to tell from the code, but I'm trying to animate the generation of the Mathieu 11 group. I want to save the calculated vertex coordinates at each iteration so the viewer can better keep track of the vertices while watching the animation. I'll clean the code up once I get it working. –  Michael Hale Jan 25 '13 at 20:30
    
Well I haven't been able to find a minimal repro, but I did find a workaround. I just added ToExpression@ToBoxes@ before the GraphPlot. I still get the messages, but it is giving me the expected output. –  Michael Hale Jan 25 '13 at 21:09
    
@belisarius Please post it here then. –  Szabolcs Feb 26 '13 at 16:05

3 Answers 3

A work-around is transforming vertices to strings:

  {op1, op2} = GroupGenerators@  MathieuGroupM11[]; 
  elems = {Range[11]};
  edges = {}; 
  coords = {};
   frames = {};

  frames = Reap[While[Length@elems < 10,
  (AppendTo[elems, Permute[#, op1]];
    AppendTo[elems, Permute[#, op2]];
    AppendTo[edges, # -> Permute[#, op1]];
    AppendTo[edges, # -> Permute[#, op2]]) & /@ elems;
  elems = Union[elems];
  edges =  Union[edges] /. (a_ -> b_) :> (ToString[a] -> ToString[b]);
  Sow[g = GraphPlot[edges,   VertexCoordinateRules -> 
     If[Length@coords > 0, coords, Automatic]]]; 
  coords =   Union[coords, Rule @@@ Transpose@{Cases[g, Tooltip[_, a_] -> a, Infinity],          
      Cases[g, (VertexCoordinateRules -> a_) -> a, 
        Infinity][[1]]}];]][[2, 1]];
 ListAnimate[frames, Alignment -> Center]

enter image description here

share|improve this answer

GraphPlot (or VertexCoordinateRules) seems to misinterpret a vertex when it is a List. Start with a different head, such as vertex, and it will be propagated by Permute. You can format vertex to show like a List (in the Tooltip for instance).

Format[vertex[l___]] ^:= {l};
{op1, op2} = GroupGenerators@MathieuGroupM11[];
elems = {vertex @@ Range[11]};
edges = {};
coords = {};
frames = {};
frames = Reap@
  While[Length@elems < 10, 
   AppendTo[elems, Permute[#, op1]]; 
     AppendTo[elems, Permute[#, op2]];
     AppendTo[edges, # -> Permute[#, op1]];
     AppendTo[edges, # -> Permute[#, op2]]; & /@ elems;
   elems = Union[elems]; edges = Union[edges];
   Sow[g = 
     GraphPlot[edges, 
      VertexCoordinateRules -> 
       If[Length@coords > 0, coords, Automatic]]];
   coords = 
    Union[coords, 
     Rule @@@ 
      Transpose@{Cases[g, Tooltip[_, a_] -> a, Infinity], 
        Cases[g, (VertexCoordinateRules -> a_) -> a, 
          Infinity][[1]]}];]

Output

share|improve this answer

JUst another way to implement same conceot as kguler (using Map at level 2: elems = {Range[11]};

edges = {};
coords = {};
frames = {};
frames = Reap@
  While[Length@elems < 10, 
   AppendTo[elems, Permute[#, op1]]; AppendTo[elems, Permute[#, op2]];
     AppendTo[edges, # -> Permute[#, op1]];
     AppendTo[edges, # -> Permute[#, op2]]; & /@ elems;
   elems = Union[elems]; edges = Map[ToString, Union[edges], {2}];
   Sow[g = 
     GraphPlot[edges, 
      VertexCoordinateRules -> 
       If[Length@coords > 0, coords, Automatic]]];
   coords = 
    Union[coords, 
     Rule @@@ 
      Transpose@{Cases[g, Tooltip[_, a_] -> a, Infinity], 
        Cases[g, (VertexCoordinateRules -> a_) -> a, 
          Infinity][[1]]}];]

yields:

enter image description here

(presuming Reap or reason for Sow) is intended.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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