# Changing edge weights in a graph using PropertyValue

I encountered a problem trying to change the EdgeWeights in a graph. I am runnning Mathematica 10.1 under Windows 7 Enterprise.

I have an undirected graph with 144 nodes and 576 edges. I first produce a sparce, symmetric adjacency matrix called "waminfful", then use that to define a graph called "myg".

 myg = WeightedAdjacencyGraph[
Range[144]
, waminffull
, DirectedEdges -> False
];


Everything seemed to work fine until I tried to change some of the edge weights. I found that some of them would change and others would not.

In the example below, the initial edge weight was 1, and I was able to reset it to 35 without a problem.

PropertyValue[{myg, 52 <-> 53}, EdgeWeight]

PropertyValue[{myg, 52 <-> 53}, EdgeWeight] = 35.0;

PropertyValue[{myg, 52 <-> 53}, EdgeWeight]

1.

35.


However, as the following example shows, this does not always work:

PropertyValue[{myg, 53 <-> 42}, EdgeWeight]

PropertyValue[{myg, 53 <-> 42}, EdgeWeight] = 35.0;

PropertyValue[{myg, 53 <-> 42}, EdgeWeight]

1.41421

1.41421.

• Greetings! To make the most of Mma.SE please take the tour now. Help us to help you, write an excellent question. Edit if improvable, show due diligence, give brief context, include minimum working examples of code and data in formatted form. As you receive give back, vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. – rhermans Oct 23 '15 at 16:13
• I suggest you cut the last part of your question, the part beginning with "I think I have discovered the problem ..." and post it, as self-answer, which is both permitted and welcomed on this site. – m_goldberg Oct 23 '15 at 16:37
• I agree, please post a self-answer. This looks like a bug, so I tagged it as such. Can you please report to Wolfram Support? The graph property system has too many bugs (since the day they were introduced in version 8). If more people report these problems there is a higher chance that they will be given priority. – Szabolcs Oct 23 '15 at 16:50

I think I have discovered the answer to this problem, but would be interested to hear other solutions.

If one looks at the complete list of Edges using EdgeList[myg], all of the listed edges have the smaller node number listed first. One sees in this list an edge denoted as 42<->53, but no edge listed as 53<->42. My experience indicates that Mathemetica will find the edge weight if given the input 53<->42, but it will not reset the edge weight if it is given an input with the larger node number listed first. If one puts the smaller node number first, then Mathematica resets the edge weight as it should, as illustrated below.

PropertyValue[{myg, 42 <-> 53}, EdgeWeight]

PropertyValue[{myg, 42 <-> 53}, EdgeWeight] = 35.0;

PropertyValue[{myg, 42 <-> 53}, EdgeWeight]

 1.41421

35.


In my example above where resetting the edge weight worked, the larger node number just happened to be listed first. I had thought that since this was an undirected graph both types of inputs would work, but that is evidently not the case.