2
$\begingroup$

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.
$\endgroup$
3
  • 1
    $\begingroup$ 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. $\endgroup$
    – rhermans
    Commented Oct 23, 2015 at 16:13
  • 1
    $\begingroup$ 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. $\endgroup$
    – m_goldberg
    Commented Oct 23, 2015 at 16:37
  • 1
    $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Commented Oct 23, 2015 at 16:50

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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