2
votes

here is my sample code

Morb = 3;
NPar = 5;
Sols = Solve [
   Append[Array[n[#] >= 0 &, Morb], Array[n, Morb, 1, Plus] == NPar], 
   Integers];
CIElements = Array[n, Morb] /. Sols;

OpOB[ij_, Ind1_] := (
  If[Part[ Ind1, Part[ij, 2]] != 0,
   Ind2 = Ind1;


   Part[Ind2, Part[ij, 1]] = Part[Ind1, Part[ij, 1]] + 1; 
   Part[Ind2, Part[ij, 2]] = Part[Ind1, Part[ij, 2]] - 1;
   , Ind2 = 0 ];
  Return[Ind2]
  )
GenerateEdge[ij_, Ind1_] := Ind1 \[DirectedEdge] OpOB[ij, Ind1]


OpSol = Solve[{i < j, i > 0, i <= Morb, j > 0, j <= Morb}, {i, j}, 
   Integers];
OpLabels = {i, j} /. OpSol;
MapList = {};
Do[  
 If[Length[OpOB[ii, jj]] != 0,
  AppendTo[ MapList, GenerateEdge[ ii, jj] ],
  Unevaluated[Sequence[]]],
 {ii, OpLabels}, {jj, CIElements}]
Graph[MapList]

I generate a list of edges called MapList and it plots the graph just fine. However, I'd like to color code the edges of the graph based on which element of OpLabels generated the edge. I can easily modify my Do[ ] clause to include some label to be later interpreted as a color. However, other solutions I've encountered, such as

https://mathematica.stackexchange.com/questions/17658/how-can-i-display-a-multigraph-with-different-colored-edges

explicitly list the number of different colors. Here that number of colors depends on the value of Morb so I can specify in advance. Is there some way I can simply tag each edge by a number and then have the colors picked by number according to some predefined color palette?

1

1 Answers

2
votes

I assume you mean each ij here is a different color..

GenerateEdge[ij_, Ind1_] := 
 Style[ Ind1 \[DirectedEdge] OpOB[ij, Ind1] , color[ij] ]

the function color is defined like this:

ncolors = 0
Clear[color]
color[x_] := color[x] = ColorData[3, "ColorList"][[++ncolors]] ;   

this causes each unique argument to spawn a new color..

with the rest of your code the same..

enter image description here