I've created a graph using graph-tool library and added string labels to nodes using vertex_properties. However, when I'm reading the graph, getting the labels from the vertices became an issue, since I also want in-degree's and out-degree's of the vertices as well. The code is as follows:
g = gt.load_graph('saved_graph.graphml')
v_labels = g.vp["my_labels"]
for v in g.vertices():
print(v)
print(v.in_degree())
In the above code, v's are printed as integers from 0 to N, where N is the number of total vertices. Basically I'm asking is: if statistics, such as in_degree I'm printing, I get from v in the loop will correspond to the labeled node v_labels[v]. Is this how we're supposed to obtain the string label of each node and associate them with statistics?
I'm new to graph-tool, so I appreciate any pointers or explanations. I failed to find a proper explanation in graph-tool documentation or examples, and anywhere else as well.
As a follow-up question, if the vertex properties and indices are aligned, in case I was to remove some of these vertices, what happens to this ordering?
As it's been a while and nobody answered, I'd like to answer it myself so everybody who is curious about the outcome can be enlightened.
Basically the answer is YES. How graph-tool indexes the nodes is based on this ordering, thus those who'd like to reach node properties of a specific node and reach them from the index.
Deletion turned out to be a challenge. When some nodes are removed, the indexes need to be re-done, otherwise, they change, and nodes start to point at incorrect properties. How to do that can be found from the following post: graph_tool: re-index vertex ids to be consecutive integers