I need to count how many times a given condition (e.g., "ACondition") is satisfied for each vertex in a graph. To do so, I need to make sure that the vertex property is initialized to zero, which I do explicitly. See the code below.
# Instantiates the graph object and the vertex property.
import graph_tool.all as gt
g1 = gt.Graph()
g1.vp.AProperty = g1.new_vertex_property("int32_t")
# Sets the vertex property to zero (prior to counting).
for v1 in g1.vertices():
g1.vp.AProperty[v1] = 0
# Counts the number of times "ACondition" is satisfied for each vertex.
for v1 in g1.vertices():
if(ACondition == True):
g1.vp.AProperty[v1] += 1
Is there a way to specify a default value of a property so that I don't need to set its initial value explicitly (i.e, the second block of code above)?