Message Boards Message Boards

Properly initialize properties for vertices in a graph?



I am trying to define a new property on my graph, and I want it to set a base value for it. The docs file says I can use All as a parameter to apply a SetProperty command to all objects, but it doesn't work. minimal example is using:

g = CompleteGraph[4]
SetProperty[{g,All}, VertexStyle -> Red]

returns: $Failed

What am I missing here? I can try brute-forcing the SetProperty function across all the vertices in the graph, but is that the only option? It doesn't feel very wolframish.

Thanks in advance!


POSTED BY: Lior Samuel
10 months ago

Use simply:

SetProperty[g, VertexStyle -> Red]

Not sure why All does not work.

POSTED BY: Kapio Letto
10 months ago

It worked! Feeling pretty silly right now for not trying this...

Many thanks!

POSTED BY: Lior Samuel
10 months ago

Now I am having trouble defining custom properties. my code is

g = CompleteGraph[4]
g2 = SetProperty[g, "name" -> "shambalulu"]
BreadthFirstScan[g2, {
  "DiscoverVertex" -> Function[{child, parent, deg}, {
     Print[PropertyValue[{g2, child}, "name"]],
     Print[PropertyList[{g2, child}]]

which works for VertexStyle->Red, but not for this case. running this code returns $Failed for each vertex's PropertyValue, and {VertexCoordinates,VertexShape,VertexShapeFunction,VertexSize,VertexStyle} for the PropertyList. So it seems like the SetProperty function failed silently for some reason, but here at 'user properties' and here at the basic examples it seems possible. I also tried this code:

Property[g2, "name"-> "shambalulu"]

but it didn't even work with vertexStyle, simply returning the Property relation as typed. Again, the goal is to create a custom property with a default value for all vertices, so specifying every vertex like in:

Graph[{Property[1, "name" -> "shambalulu"], 2, 3}, {1 <-> 2, 2 <-> 3, 3 <-> 1}]

is not good enough... Any ideas?

POSTED BY: Lior Samuel
10 months ago

Group Abstract Group Abstract