Bug introduced in 9.0 or earlier and fixed in version 10.0.0

I evaluate

gt = Graph[{"A" <-> "B", "B" <-> "C", "A" <-> "C", "C" <-> "D"}, VertexLabels -> "Name"]
gt = SetProperty[{gt, "B"}, VertexWeight -> 3];  

I check that the property is set.

PropertyValue[{gt, "B"}, VertexWeight]

Next I evaluate

gt = SetProperty[{gt, "A"}, VertexWeight -> 4];  

and check

PropertyValue[{gt, "A"}, VertexWeight]

Then I check to confirm the B vertex still has the weight I set

PropertyValue[{gt, "B"}, VertexWeight]
1 (* should be 3 *)

Any ideas what I'm doing wrong?

  • 1
    $\begingroup$ This clearly shouldn't happen. It is a bug that I can reproduce in version 9.0.1. $\endgroup$
    – Szabolcs
    Mar 12 '14 at 18:26

I can reproduce this in version 9.0.1 and I think this is a bug. As a workaround, you can set all the vertices' weight at once instead of one-by-one using a different syntax:

gt = SetProperty[gt, VertexWeight -> {"A" -> 4, "B" -> 3}];  
VertexList[gt] -> PropertyValue[gt, VertexWeight] // Thread
(* {"A" -> 4, "B" -> 3, "C" -> 1, "D" -> 1} *)

Trying to set the VertexWeight on any single vertex afterwards will re-set the VertexWeight of all other values to 1 (which is incorrect behaviour).

In version 8.0.4 SetProperty doesn't work at all with VertexWeight: it either returns $Failed or simply doesn't have an effect.


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.