I would like to save class instances in a graph-tool graph , one object per node (or the 'vertex' as a graphical tool calls them). I am trying to use the vertex property as this seems like a way to do this .
class MyClass(object): def __init__(self, title): self.title = title graph = Graph() my_obj = MyClass('some title') vertex = graph.add_vertex() vprop = graph.new_vertex_property('object') vprop[vertex] = my_obj
Now I would like to read my class objects back, for example. iterate over all vertices / vertices and print their names:
for vertex in self.graph.vertices(): # TODO: how to access titles ? this just prints # "<Vertex object with index '0' at 0xb1e4bac>" print repr(vertex) + '\n'
Also, how do I get a class object with a specific title from the graph? One way, apparently, is to create a vertex filter using graph.set_edge_filter(...) and apply it, which seems like a pretty expensive operation, considering all I want is to return one object back. I really do not want to support the object's own name / vertex index transformation as IMO, this is one of the tasks of the graph.
Did I miss something fundamental here?
source share