How to add a list of vectors (lists) to a directed graph as an edge weight?
I think this is worth reporting to support. A workaround is to use a wrapper to prevent EdgeWeight
from interpreting a list as an edge specification:
Block[{Identity},
Graph[
{1\[DirectedEdge]1, 1\[DirectedEdge]1, 1\[DirectedEdge]1},
EdgeWeight -> Identity /@ {{1,0},{0,1},{1,1}}
]
]
If I want to display the EdgeWeights, there are also issues.
Using Carl Woll's answer to generate a graph with edge weights and using a variant of the accepted answer in the linked q/a:
ClearAll[displayWeightedMultiGraph]
displayWeightedMultiGraph = Module[{i = 1, j, g = #, bcurves,
labels = PropertyValue[#, EdgeWeight],
gccoords = Cases[ToBoxes[#], GraphicsComplexBox[x_, y_, z___] :> x, Infinity][[1]]},
bcurves = Cases[ToBoxes[g], {dir___, ar : Longest[__ArrowBox], ___} :>
(## & @@ Thread[{dir, {ar}}]), Infinity] /.
{ArrowBox[BezierCurveBox[x_, y___], z___] :>
Arrow[BezierCurve[x /. k_Integer :> gccoords[[k]], y], z],
ArrowBox[x : {__}, y_] :> Arrow[gccoords[[x]], y]};
SetProperty[g, EdgeShapeFunction -> ({j = i++; Text[labels[[j]],
BezierFunction[#, SplineDegree -> 7][0.5]], bcurves[[j]]} &)]] &;
Examples:
g1 = Block[{Identity}, Graph[{1 -> 1, 1 -> 1, 1 -> 1},
EdgeWeight -> Identity /@ {{1, 0}, {0, 1}, {1, 1} }]];
displayWeightedMultiGraph @ g1
g2 = Block[{Identity}, Graph[{1 <-> 2, 1 -> 2, 1 -> 2},
EdgeWeight -> Identity /@ {{0, 0}, {0, 1}, {1, 0}}]];
displayWeightedMultiGraph @ g2