It seems that the following doesn't work on v9. It does work on v8 and v10.
Here is what I propose based on this:
rule = {0 -> 1, 1 -> 2, 2 -> 3, 0 -> 1, 1 -> 4, 4 -> 5, 0 -> 2, 2 -> 4, 4 -> 6, 0 -> 3,
3 -> 7, 7 -> 9, 0 -> 6, 6 -> 8, 8 -> 9, 1 -> 2, 2 -> 7, 7 -> 8, 1 -> 3, 3 -> 6,
6 -> 9, 1 -> 4, 4 -> 7, 7 -> 9, 1 -> 5, 5 -> 6, 6 -> 8, 2 -> 3, 3 -> 5, 5 -> 9,
2 -> 4, 4 -> 8, 8 -> 9, 2 -> 5, 5 -> 6, 6 -> 7, 3 -> 4, 4 -> 5, 5 -> 8, 3 -> 4,
4 -> 6, 6 -> 7};
blocks = {{0, 1, 2, 3}, {0, 1, 4, 5}, {0, 2, 4, 6}, {0, 3, 7, 8}, {0, 5, 7, 9},
{0, 6, 8, 9}, {1, 2, 7, 8}, {1, 3, 6, 9}, {1, 4, 7, 9}, {1, 5, 6, 8},
{2, 3, 5, 9}, {2, 4, 8, 9}, {2, 5, 6, 7}, {3, 4, 5, 8}, {3, 4, 6, 7}};
coloredRule = Select[Flatten[
Thread[{Rule @@@ Subsets[blocks[[#]], {2}],
ConstantArray[#, 6]}] & /@ Range@Length@blocks, 1], MemberQ[rule, First@#] &];
col = Flatten[{#, {#2, Line[foo]}} & @@@
Thread[{Range@Length@blocks,
RGBColor /@ RandomReal[{0, 1}, {Length@blocks, 3}]}] /. foo -> #1, 1];
GraphPlot[coloredRule, ImagePadding -> 10,
EdgeRenderingFunction -> (Function@Switch[Slot@3, foo] /. foo -> Sequence @@ Evaluate@col),
VertexLabeling -> True,
Method -> "CircularEmbedding"]
Of course, the doubled edges are coloured twice, so the last colour applied remains. I was wrong, the edges in that example are doubled, with two different colours.
The following produces the right number of edges:
grule = GatherBy[Gather[rule], Length];
singledColoredRule = Delete[coloredRule, List /@ Last /@ Table[Flatten@
Position[MemberQ[grule[[2, i]], First@#] & /@ coloredRule,
True], {i, Length@grule[[2]]}]];
SeedRandom@4;
colours = RandomReal[{0, 1}, {Length@blocks, 3}];
col = Flatten[{#, {#2, Line[foo]}} & @@@
Thread[{Range@Length@blocks, RGBColor /@ colours}] /. foo -> #1, 1];
g[size_] := GraphPlot[singledColoredRule,
EdgeRenderingFunction -> (Function@Switch[Slot@3, foo] /. foo -> Sequence @@ Evaluate@col), VertexLabeling -> True,
Method -> "CircularEmbedding", ImageSize -> size];
label =
Grid[Partition[Graphics[{RGBColor@#, Rectangle[], White, Text[#2, {0.5, 0.5}]}] & @@@
Thread@{colours, StringJoin /@ Map[ToString, blocks, {2}]}, 3, 3, 1, {}],
Spacings -> {-1, -1}, ItemSize -> {[email protected], 0}];
Row@{g@350, label}
Of course, now one edge belonging to two different blocks will only take the colour of the latest block.
Graph
in Mathematica 10. The the new-in-10 multigraph support is not the way to go. $\endgroup$