Hello,
Is there an obvious way to collect vertices of degree 1 for reading the
property of their edge?
The following code succeed in doing the job on a tiny scale, but I am sure
this not the way to do:
/import graph_tool.all as gt
#from graph_tool import topology
## Make a graph
T = gt.Graph(directed = False)
edge_weights = T.new_edge_property('double')
T.properties[("e","weight")] = edge_weights
T.add_vertex(n=5)
e_1 = T.add_edge(0,1)
e_2 = T.add_edge(1,2)
e_3 = T.add_edge(0,0)
e_4 = T.add_edge(1,3)
edge_weights[e_1]= 2
edge_weights[e_2]= 6
edge_weights[e_3]= 1
edge_weights[e_4]= 3
## Get the vertices of degree 1 in a dictionary (keys= vertices degree,
values=vertices)
from collections import defaultdict
deg_dic = defaultdict(list)
for v in T.vertices():
degree = v.out_degree()
deg_dic[degree].append(v)
## Read the weight of the bounded edge
print 'vertices of degree 1:'
for d1 in deg_dic[1]:
weight_of_bound_edge = [edge_weights[e] for e in d1.out_edges()]
print 'vertex',d1,' weight of out edge:', weight_of_bound_edge/
By the way, the objective is to count the vertices of degree 1 as a function
of the pruning steps. Is there sucha a function in graph-tool?
Best regards
Jean-Patrick