Bug persisting through 12.0
Unsupported Functionality (loosely, a bug)
Mathematica (as of 11.0.1 for Mac OS X x86 (64-bit) (September 21, 2016)) does not support multi-graph where edge properties vary between two nodes that share multiple edges. Although this is not recognised officially by Wolfram with a bug reference number they could provide, it is a failure to fully provide multi-graph support.
While the following yields False
the feature remains unsupported:
g1 = Graph[{1, 2, 3, 4, 5}, {1 <-> 2, 1 <-> 2, 2 <-> 3, 4 <-> 4,
5 <-> 1, 2 <-> 4},
EdgeWeight -> Range[6]];
PropertyValue[{g1, #}, EdgeWeight] & /@ EdgeList[g1] == Range[6]
(*FALSE*)
Original Issue
Today I was working with a large multi-graph with properties on the edges when I discovered that properties aren't assigned as expected.
My preferred graph construction method is to specify properties before creating a graph, using the following undocumented syntax:
Graph[{vertices},{edges)]
The following minimal example shows my problem, the two edges 1<->2
have been given different values of the Property
"foo"
- but that's not what PropertyValue
reports:
seGraph1 =
Graph[{1, 2, 3, 4}, {Property[1 <-> 2, "foo" -> 1],
Property[1 <-> 2, "foo" -> 3], Property[2 <-> 3, "foo" -> 5],
Property[3 <-> 4, "foo" -> 6]}]
seGraph2 =
Graph[{1, 2, 3, 4}, {Property[1 <-> 2, "foo" -> 30],
Property[1 <-> 2, "foo" -> 10], Property[2 <-> 3, "foo" -> 5],
Property[3 <-> 4, "foo" -> 6]}];
PropertyValue[{seGraph1, #}, "foo"] & /@ EdgeList[seGraph1]
PropertyValue[{seGraph2, #}, "foo"] & /@ EdgeList[seGraph2]
(*{3,3,5,6}*)
(*10,10,5,6}*)
Not one to stick to undocumented naughtiness, I also tried adding properties after the creation of the Graph
. But the same problem:
seGraph3 = Graph[{1 <-> 2, 1 <-> 2, 2 <-> 3, 3 <-> 4}];
MapThread[(PropertyValue[{seGraph3, #1}, "foo"] = #2) &, {EdgeList[
seGraph3], {1, 3, 5, 6}}];
PropertyValue[{seGraph3, #}, "foo"] & /@ EdgeList[seGraph3]
(*{3, 3, 5, 6}*)
Question
Is there a way to build a multigraph with different PropertyValue
s for identical edges?
Note: I'm on 10.1 for at least a few more days, but I'd happily have a solution that will work for 10.2
MultigraphQ
function if you truly cannot handle multigraphs!). Can anyone tell me whether 10.4 manages any better? $\endgroup$ – Quantum_Oli May 17 '16 at 11:37