12
$\begingroup$

Bug introduced in 9.0 or earlier and fixed in 12.0


I am trying to add a new edge to an existing graph and set its capacity, but for some reason the SetProperty call is not evaluated. A minimal example:

g = Graph[{1 -> 2, 2 -> 3}, EdgeCapacity -> {10, 20}];
gt = EdgeAdd[g, 1 -> 3];
gt = SetProperty[{gt, 1 -> 3}, EdgeCapacity -> 10]

(* Out: SetProperty[{*graph with new edge pic*, 1 -> 3}, EdgeCapacity -> 10]*)

However, if I call SetProperty with EdgeWeight or EdgeLabels instead, it works fine. What is the proper way to set a new edge capacity?

I am using version 10.3.0.

$\endgroup$
  • $\begingroup$ This looks buggish to me; when I try PropertyValue[gt, EdgeCapacity] instead of SetProperty, I get a message saying part 3 of {1,3} does not exist, instead of $Failed. $\endgroup$ – Pillsy Nov 1 '15 at 0:28
  • $\begingroup$ I agree, looks very buggy! It works for some reason if you don't set any edge capacities in g. $\endgroup$ – paw Nov 1 '15 at 0:46
  • 1
    $\begingroup$ Yes. The only workaround I can think of is extracting the entire sets of vertices and edges with all their properties from an old graph, adding a new edge to the edge set, a new capacity to the capacity set, and creating a new graph from all of this from scratch. $\endgroup$ – xivaxy Nov 1 '15 at 17:31
  • 1
    $\begingroup$ Same results on V9. Tagging as a bug $\endgroup$ – Dr. belisarius Nov 2 '15 at 2:14
  • $\begingroup$ Please do report this problem to Wolfram Support. $\endgroup$ – Szabolcs Nov 2 '15 at 8:35
4
$\begingroup$

This is not an answer, just an analysis of the problem.

Mathematica stores different edge properties in different ways.

EdgeWeight, EdgeCost and EdgeCapacity seem to be stored as a plain list of numbers, set in a separate option of Graph. They are all affected by this problem.

What happens when using EdgeAdd is that this list is not amended:

gt // InputForm

Graph[{1, 2, 3}, {DirectedEdge[1, 2], DirectedEdge[2, 3], DirectedEdge[1, 3]}, 
 {EdgeCapacity -> {10, 20}}]

It still has length 2, even though the graph now has three vertices.

I would have expected EdgeCapacity -> {10, 20, 1}, as 1 is the default value of this property.

This way EdgeAdd essentially corrupts the internal structure of the Graph and makes it unsafe to use. All sorts of unexpected things may happen when trying to use weighted graph functions on it (typically they just don't evaluate).

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.