Here's an example that illustrates how to automate the highlighting of a particular path through a graph.
Here's an example that illustrates how to automate the highlighting of a particular path through a graph. Here's a silly graph, specified by a list of edge rules: edges = Tablei -> Mod1 + i^2, 10, {i, 0, 9}; GraphPlotedges, VertexLabeling -> True Here's a path through the graph we'd like to highlight. Path = {0, 1, 2, 5, 6, 7, 0}; Let's partition the path into edges, accounting for the fact that we want to highlight the edge independent of its orientation.
EdgesToghlight = Partitionpath, 2, 1; edgesToghlight = JoinedgesTo Reverse /@ edgesTo We write an EdgeRenderingFunction that renders an edge in one of two styles, depending no whether it's in our list or not. Erfpts_, edge_, ___ := IfMemberQedgesTo edge, {Thick, Black, Arrowpts, 0.1}, {DarkerRed, Linepts}; Finally, we display the result. GraphPlotedges, EdgeRenderingFunction -> erf, VertexLabeling -> True.
Simple, elegant and general +1 – belisarius Oct 10 '10 at 2:26 @ Mark McClure: Mathematica is surprising me again. How can you call the function erf without passing any arguments to it? Even though you created 3 parameters in the function definition, I assume it automatically "finds" them in the current context?
– dbjohn Oct 10 '10 at 9:34 @dbjohn I haven't called the function; I'm simply telling GraphPlot what function to call when it draws the edges. Here's a similar example: SelectRange9, EvenQ. In this example, EvenQ is passed as an argument to Select.
Select then selects only those integers n for which EvenQn returns True. – Mark McClure Oct 10 '10 at 10:58 @Mark McClure: Ok I see, it is a kind of implicit pure function. It is the same as SelectRange9, EvenQ# & except without the more familar # and &.
– dbjohn Oct 10 '10 at 11:27.
GraphPlot {1 -> 2, 2 -> 3, 3 -> 4, 4 -> 1, 2 -> 4, 4 -> 5, 4 -> 6}, VertexLabeling -> True, EdgeRenderingFunction -> ( {If#2 == {1, 2}, Red, Black, Line#1} &) The rendering function is a callback function, which takes 3 arguments. The 1st is the list of coordinates of the line, the 2nd is the vertices of the edge, and the 3rd is the edge's label. In Mathematica you could create an anonymous function with (f#1,#2,#3,... &).
That works for one edge. But suppose I want to colour a path that covers more than one edge and vertex? I tried modification: If#2 == {1, 2, 3, 4, 5}... and If#2 == {{1, 2}, {3, 4}}... but didn't work.
Any ideas? – dbjohn Oct 9 '10 at 20:32 @dbjohn: See MemberQ. – KennyTM Oct 9 '10 at 20:33 You are suggesting I use MemberQ like: IfMemberQ#2, {2, 3, 4, 5}, Red... that is to say if vertices x,y,z are in members of the list of all vertices colour them red?
That code doesn't work, MemberQ can't take a list as its second argument. I am going to need more explicit direction. – dbjohn Oct 9 '10 at 21:11 The second argument to the EdgeRenderingFunction is a pair, like {2,3} which represents an edge between vertices 2 and 3.
You can reverse the arguments of MemberQ and do the following, for example: MemberQ{{1, 2}, {2, 4}}, #2 That will be True for edges 1->2 and 2->4. HTH! – Michael Pilat Oct 9 '10 at 23:11.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.