Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
This clearly shouldn't happen. It is a bug that I can reproduce in version 9.0.1. – Szabolcs Mar 12 '14 at 18:26
up vote 3 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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