It just got even more interesting. I tried assigning a list to a VertexWeight
and couldn't. I could however assign an EmpiricalDistribution
(which is odd as it has a lot of structure inside it).
Check this the following timings though:
Clear[g]
g = CycleGraph[1000];
Timing@Do[
PropertyValue[{g, v}, VertexWeight] =
EmpiricalDistribution[RandomReal[{0, 1}, {1000}]], {v,
VertexList[g]}]
MemberQ[PropertyList[g], VertexWeight]
(* Out[3]= {28.7813, Null} *)
(* Out[4]= True *)
Clear[g]
g = CycleGraph[1000];
Timing@Do[
PropertyValue[{g, v}, "MyVertexWeight"] =
EmpiricalDistribution[RandomReal[{0, 1}, {1000}]], {v,
VertexList[g]}]
MemberQ[PropertyList[{g, 1}], "MyVertexWeight"]
PropertyList[g]
PropertyList[{g, 1}]
(* Out[7]= {0.171875, Null} *)
(* Out[8]= True *)
(* Out[9]= {GraphHighlight, GraphHighlightStyle, GraphLayout, \
GraphStyle, EdgeShapeFunction, EdgeStyle, VertexCoordinates, \
VertexShapeFunction, VertexShape, VertexSize, VertexStyle} *)
(* Out[10]= {"MyVertexWeight", VertexCoordinates, VertexShape, \
VertexShapeFunction, VertexSize, VertexStyle} *)
Clear[g]
g = CycleGraph[1000];
Timing@Do[
g = SetProperty[{g, v},
"MyVertexWeight" ->
EmpiricalDistribution[RandomReal[{0, 1}, {1000}]]], {v,
VertexList[g]}]
MemberQ[PropertyList[{g, 1}], "MyVertexWeight"]
PropertyList[g]
PropertyList[{g, 1}]
(* {0.296875, Null} *)
(* True *)
(* Out[15]= {GraphHighlight, GraphHighlightStyle, GraphLayout, \
GraphStyle, EdgeShapeFunction, EdgeStyle, VertexCoordinates, \
VertexShapeFunction, VertexShape, VertexSize, VertexStyle} *)
(* Out[16]= {"MyVertexWeight", VertexCoordinates, VertexShape, \
VertexShapeFunction, VertexSize, VertexStyle} *)
It appears that if you create your own graph properties they behave much faster. It also turned out that you CAN assign lists to them in addition to anything else.
Funny thing is now after all that PropertyValue
appears to be faster than SetProperty
even with the re-assignment (and modulo Scan
, Map
,Do
).
PropertyValue
is new in version 8, but when mma 9 comes along this tag will become redundant... $\endgroup$Combinatorica
package and theGraphPlot
et al, which have been there at least since version 6; the other is theGraph
object, which is new to version 8. The tag graphs-and-networks alone would not make this distinction. $\endgroup$