I get a 'Segmentation fault (core dumped)' error when I try to calculate
the pseudo_diameter() of a GraphView object <class 'graph_tool.GraphView'>.
I must convert the GraphView object to a Graph object <class
'graph_tool.Graph'> to perform this calculation? How do I make this
conversion?
My detailed problem is:
I have a graph that is fragmented in several components and I want to
calculate several measures on every component, so I must extract every
component as a graph to be able to apply the different tools on it. To do
this I use label_components() to create a vertex PropertyMap that label the
components
vprop_comps, size_comps = gt.label_components(g)
from this Property Map (vprop_comps) I create one Boolean PropertyMap for
every component, the Boolean Property Map for a component will have 1 for
every vertex that belong to this component and 0 otherwise, finally I
construct a GraphView object from the Boolean Property Map of a component,
and then apply the different tools on this object. My code is:
# for all components
for i in range(size_comps.size):
# create a boolean property map
vprop_component_i = g.new_vertex_property("bool")
# explore the property map that label the components 'vprop_comps'
for j in range(vprop_comps.a.size):
# if vprop_comps sugest that vertex j is in component i
if (vprop_comps.a[j] == i):
# put 'true' in the property of vertex j in the property
map of component i
vprop_component_i[g.vertex(j)] = True
# With the boolean property map constructed for component i I can
create a
# GraphView object representing component i:
c_i = gt.GraphView(g, vfilt=vprop_component_i)
# and apply the different measures on it:
clust_c_i = gt.global_clustering(c_i)[0]
length_c_i = gt.pseudo_diameter(c_i)[0]
Everything goes fine until I calculate the pseudo_diameter() of c_i, if I
try to, I receive a 'Segmentation fault (core dumped)' error.
Is there a more direct way to extract the components as graph objects?
I get a 'Segmentation fault (core dumped)' error when I try to calculate
the pseudo_diameter() of a GraphView object <class 'graph_tool.GraphView'>.
I must convert the GraphView object to a Graph object <class
'graph_tool.Graph'> to perform this calculation? How do I make this
conversion?
My detailed problem is:
I have a graph that is fragmented in several components and I want to
calculate several measures on every component, so I must extract every
component as a graph to be able to apply the different tools on it. To do
this I use label_components() to create a vertex PropertyMap that label the
components
vprop_comps, size_comps = gt.label_components(g)
from this Property Map (vprop_comps) I create one Boolean PropertyMap for
every component, the Boolean Property Map for a component will have 1 for
every vertex that belong to this component and 0 otherwise, finally I
construct a GraphView object from the Boolean Property Map of a component,
and then apply the different tools on this object. My code is:
# for all components
for i in range(size_comps.size):
# create a boolean property map
vprop_component_i = g.new_vertex_property("bool")
# explore the property map that label the components 'vprop_comps'
for j in range(vprop_comps.a.size):
# if vprop_comps sugest that vertex j is in component i
if (vprop_comps.a[j] == i):
# put 'true' in the property of vertex j in the property
map of component i
vprop_component_i[g.vertex(j)] = True
# With the boolean property map constructed for component i I can
create a
# GraphView object representing component i:
c_i = gt.GraphView(g, vfilt=vprop_component_i)
# and apply the different measures on it:
clust_c_i = gt.global_clustering(c_i)[0]
length_c_i = gt.pseudo_diameter(c_i)[0]
Everything goes fine until I calculate the pseudo_diameter() of c_i, if I
try to, I receive a 'Segmentation fault (core dumped)' error.
Is there a more direct way to extract the components as graph objects?
I don't know about the segfault (I encountered the same problem with a test
graph), your approach uses too much code to select the components. I
suggest the following:
vprop_comps, size_comps = gt.label_components(g)
for i in range(len(size_comps)):
gv = gt.GraphView(g,vfilt=lambda x: vprop_comps==i)
I get a 'Segmentation fault (core dumped)' error when I try to calculate
the pseudo_diameter() of a GraphView object <class
'graph_tool.GraphView'>. I must convert the GraphView object to a Graph
object <class 'graph_tool.Graph'> to perform this calculation? How do I
make this conversion?
The segfault is obviously a bug, I'll fix that. As a workaround, you can
convert a GraphView into a Graph instance by doing the following:
g = Graph(g, prune=True)
Is there a more direct way to extract the components as graph objects?
You can do a little more compactly as Giuseppe showed, but as far as
actually efficiency is concerned, you cannot do much better.