The GraphView
object in the python graph_tool
package does not seem to work as I expect when the base graph is itself a GraphView
object. Here is some code that shows the issue:
from graph_tool import *
import numpy as np
g = Graph()
p1 = g.new_vertex_property("bool")
gv1 = GraphView(g, p1)
p2 = gv1.new_vertex_property("bool")
gv2 = GraphView(gv1, p2)
print gv1.num_vertices()
This prints 0 as expected; we haven't added any vertices.
v = g.add_vertex()
p1[v] = True
print gv1.num_vertices()
This prints 1 as expected. Changing the property map updates the view.
for w in gv1.vertices():
p2[w] = True
print gv2.num_vertices()
This prints 0, which I did not expect. Changing the property map doesn't seem to update the view.
p2[v] = True
print gv2.num_vertices()
Using the vertex objects from g
instead of gv1
doesn't seem to help; 0 is again printed.
gv2 = GraphView(gv1, p2)
print gv2.num_vertices()
This prints 1, suggesting that the problem is not with the property map but, somehow, the view.
What am I missing?