# Set new edge capacity

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.

• 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. Nov 1, 2015 at 0:28
• I agree, looks very buggy! It works for some reason if you don't set any edge capacities in g.
– paw
Nov 1, 2015 at 0:46
• 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. Nov 1, 2015 at 17:31
• Same results on V9. Tagging as a bug Nov 2, 2015 at 2:14
• Please do report this problem to Wolfram Support. Nov 2, 2015 at 8:35

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).