Ich muss zählen, wie oft eine gegebene Bedingung (z. B. "ACondition") für jeden Scheitelpunkt in einem Diagramm erfüllt ist. Um dies zu tun, muss ich sicherstellen, dass die Vertex-Eigenschaft auf Null initialisiert wird, was ich explizit tue. Siehe den folgenden Code.Festlegen des Standardeigenschaftswerts in graph_tool
# 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
Gibt es eine Möglichkeit, einen Standardwert eine Eigenschaft an, so dass ich muß nicht explizit festgelegt seinen Anfangswert (das heißt, der zweite Block von Code oben)?
Vielen Dank für Ihre Antwort. Ich bin neu bei graph_tool und jetzt merke ich, dass ich die Signatur von 'new_vertex_property' übersehen habe ... mein Fehler. – AntA