Message Boards Message Boards

1 Reply
3 Total Likes
View groups...
Share this post:

Multi-vertex version of SetProperty?

Posted 12 years ago
Hi All,
I have graph objects like the following:
g = CompleteGraph[2000]; 

These graph objects are then used further down the road by helper functions that need to assign additional information to each vertex. I currently do this via SetProperty[]:
pairs = {#, ToString[#]} &/@ VertexList[g]; 
This, as you can see, takes too long to evaluate. Apart from using Replace[] on the InputForm[] of Graph[], is there a 'mult-vertex' syntax for SetProperty[] that I could use here?
Thanks for your time,
POSTED BY: Adam Griffith
In[57]:= AbsoluteTiming[h = SetProperty[{g, VertexList[g]}, Thread["CustomString" -> ToString /@ VertexList[g]]];]
Out[57]= {0.043045, Null}

modify/add the property value in-place
In[58]:= AbsoluteTiming[PropertyValue[{g, VertexList[g]}, "CustomString"] = ToString /@ VertexList[g];]
Out[58]= {0.032022, Null}

In[59]:= AbsoluteTiming[Scan[(PropertyValue[{g, #}, "CustomString1"] = ToString[#] ) &, VertexList[g]];]
Out[59]= {0.037812, Null} 
POSTED BY: Charles Pooh
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract