I am currently working with graph_tool to analyse text documents. let's say
that in my graph each vertex is a word that appears in the text and each
edge corresponds to a relationship between two words. Because of the fact
that vertex is individuated only by its index i suppose to use a vertex
property map (let's call it 'name', of type 'string') to put the word
related to the vertex, assuring a bijective property of the "word <-> vertex
index" function.
Intuitively i'd like to do something like idx = g.vertex("example").
I cannot see how to implement it with the PropertyMaps because i can only
have the function "vertex index -> word".
I cannot keep the "word -> vertex index" elsewhere because remove_vertex()
is changing my indexes under my feet.
I am currently working with graph_tool to analyse text documents. let's
say that in my graph each vertex is a word that appears in the text and
each edge corresponds to a relationship between two words. Because of
the fact that vertex is individuated only by its index i suppose to use
a vertex property map (let's call it 'name', of type 'string') to put
the word related to the vertex, assuring a bijective property of the
"word <-> vertex index" function.
Intuitively i'd like to do something like idx = g.vertex("example").
I cannot see how to implement it with the PropertyMaps because i can
only have the function "vertex index -> word".
I cannot keep the "word -> vertex index" elsewhere because
remove_vertex() is changing my indexes under my feet.
Does anybody of you have a suggestion?
There is no simple solution for this if you intend to modify the graph by
removing vertices... You have basically two options:
1 - Don't remove the vertex, and instead just mask it out of the graph, with
set_vertex_filter(). This way, all vertex objects remain valid, and
you can store them as values of a dictionary.
2 - Use the find_vertex() function to find vertices with a given property
map value. This is easy, but it is also slow, since every lookup
takes O(V) time.