13
$\begingroup$

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 PropertyValues 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

$\endgroup$
  • $\begingroup$ This problem has come up a number of times. I don't think it's possible to do it. Personally I think that this is glaring design error, yet another example of the problems the graph-related functionality has. $\endgroup$ – Szabolcs Aug 20 '15 at 19:19
  • $\begingroup$ @Szabolcs oh shoot! I've dealt with some problems with properties before and looked briefly for similar on mma.SE but hoped the multigraph functionality was new enough they might've made sure it worked. $\endgroup$ – Martin John Hadley Aug 20 '15 at 19:21
  • 1
    $\begingroup$ I'm not very happy with how the graph-related stuff is being developed and about WRI's responses to complaints. There are an unusually high amount of bugs in this area, bugs tend to go unfixed for a long time, and sometimes they even claim that obvious problems are not bugs. There's also the thing when deleting edges or vertices from a weighted graph (or graph with properties) tends to corrupt the graph. $\endgroup$ – Szabolcs Aug 20 '15 at 19:25
  • 1
    $\begingroup$ Related: mathematica.stackexchange.com/questions/74125/… $\endgroup$ – Sjoerd C. de Vries Aug 20 '15 at 21:02
  • 1
    $\begingroup$ I'm still on 10.3 and kinda scuppered by the lack of multigraph support (really whats the point in including a 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.