Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]
3

Next I evaluate

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

and check

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

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
1  
This clearly shouldn't happen. It is a bug that I can reproduce in version 9.0.1. –  Szabolcs Mar 12 at 18:26

1 Answer 1

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

 
discard

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.