Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: HighlightedEdgeColors with Combinatoric`ShowGraph and AnimateGraph

  • To: mathgroup at
  • Subject: [mg88154] Re: HighlightedEdgeColors with Combinatoric`ShowGraph and AnimateGraph
  • From: Szabolcs Horvát <szhorvat at>
  • Date: Sat, 26 Apr 2008 03:45:39 -0400 (EDT)
  • Organization: University of Bergen
  • References: <fus8db$82n$>

Dear Murray,

First I would like to say that I am not familiar with Combinatorica and 
its graph plotting functions, so what I write here might not be entirely 

Murray Eisenberg wrote:
> The following works as expected to highlight two of the edges of a graph 
> with a different color each:
>    <<Combinatorica`
>    g=Cycle[3];
>    ShowGraph[
>      Highlight[g,{{{1,2}},{{2,3}}},HighlightedEdgeColors->{Red,Blue}]]
> And the docs say that AnimateGraph takes the same options as Highlight. 
> But the following does NOT work -- it uses just the first color, Red, 
> when animating the highlighting of the two edges:
>    AnimateGraph[g, {{1, 2}, {2, 3}},
>      HighlightedEdgeColors -> {Red, Blue}]
> What's wrong?

> (I do know that I used different syntax in the 2nd argument of 
> Highlight, on the one hand, and in the 2nd argument of AnimateGraph, on 
> the other hand.  For Highlight to work within ShowGraph so as to animate 
> edges, it is necessary to put the extra level of nesting in each edge 
> specification.  But such extra nesting in the case of AnimateGraph would 
> not work: it gives no animation of edges.)

I think that what you wrote is correct: the documentation for 
AnimateGraph says:  "Here l is a list containing vertices and edges of 
g."  So no extra nesting should be necessary.

In contrast to this, the doc page for Highlight says:  "The second 
argument p has the form {Subscript[s, 1],Subscript[s, 2],\[Ellipsis]}, 
where the Subscript[s, i] are disjoint subsets of vertices and edges of 
g."  So the second argument of highlight should be a list of lists, 
where the elements of each sublist will have a common style.

This is the source code of AnimateGraph:

AnimateGraph[g_Graph, l_List, flag_Symbol: All, opts___?OptionQ] :=
    If[flag === One,
      Highlight[g, {{l[[i]]}},
       Sequence @@
        FilterRules[{opts}, Except[Options[ListAnimate]]]], {i,
     Table[Highlight[g, { l[[Range[i]]] },
       Sequence @@
        FilterRules[{opts}, Except[Options[ListAnimate]]]], {i,
    ], Sequence @@ FilterRules[{opts}, Options[ListAnimate]]

If you look at the second Table function, especially the
{ l[[ Range[i] ]]  } part, you'll see that AnimateGraph will only use a 
single sublist in Highlight, so all edges/vertices will be highlighted 
with the same style.  As I said, I am not familiar with Combinatorica, 
so I cannot tell whether AnimateGraph was written like this 
intentionally, or this is a bug, but the behaviour you are looking for 
can be achieved by changing

{ l[[ Range[i] ]]  }


List /@ l[[ Range[i] ]]

Note that this change will only affect the case when the flag has the 
value All.  The AnimateGraph[g, l, One] case cannot be made to work with 
HighlightedEdgeColors without parsing the colour list inside 
AnimateGraph (instead of passing it to Highlight unchanged).  Probably 
this is the reason why the All case uses only a single style too.

I hope this helps,

P.S.  Actually Highlight seems to accept empty sublists too, so for the 
One case,


could be replaced by

ReplacePart[Table[{}, {Length[l]}], i -> {l[[i]]}]

to get the right colour.

  • Prev by Date: Re: Wolfram User Interface Research?
  • Next by Date: Re: OpenerView (with cells?)
  • Previous by thread: HighlightedEdgeColors with Combinatoric`ShowGraph and AnimateGraph
  • Next by thread: ReplacePart and Compile