Re: HighlightedEdgeColors with Combinatoric`ShowGraph and AnimateGraph
- To: mathgroup at smc.vnet.net
- Subject: [mg88154] Re: HighlightedEdgeColors with Combinatoric`ShowGraph and AnimateGraph
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Sat, 26 Apr 2008 03:45:39 -0400 (EDT)
- Organization: University of Bergen
- References: <fus8db$82n$1@smc.vnet.net>
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
correct.
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] :=
ListAnimate[
Map[ShowGraph,
If[flag === One,
Table[
Highlight[g, {{l[[i]]}},
Sequence @@
FilterRules[{opts}, Except[Options[ListAnimate]]]], {i,
Length[l]}],
Table[Highlight[g, { l[[Range[i]]] },
Sequence @@
FilterRules[{opts}, Except[Options[ListAnimate]]]], {i,
Length[l]}]
]
], 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] ]] }
to
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,
Szabolcs
P.S. Actually Highlight seems to accept empty sublists too, so for the
One case,
{{l[[i]]}}
could be replaced by
ReplacePart[Table[{}, {Length[l]}], i -> {l[[i]]}]
to get the right colour.