I am trying to create large graph via graph-tool
library (near 10^6 - 10^7 vertices) and fill vertex property with vertex name or use names instead of vertex indexes. I have:
list of names:
['50', '56', '568']
set of edges, but instead of vertex indexes it consists of their names:
edge_list = {frozenset({'568', '56'}), frozenset({'56', '50'}), frozenset({'50', '568'})}
Since add_edge_list()
allows to create vertices if they are no such vertix in the graph. I'm trying to use it to fill an empty graph. It works ok, but when I was trying to get vertex by its name, I got an error that there are no vertex with such index.
Here is the code of my program:
g = grt.Graph(directed=False)
edge_list = {frozenset({'568', '56'}), frozenset({'56', '50'}), frozenset({'50', '568'})}
ids = ['50', '56', '568']
g.add_edge_list(edge_list, hashed=True, string_vals=True)
print(g.vertex('50'))
The error message of print(g.vertex('50'))
:
ValueError: Invalid vertex index: 50
I want to create graph:
- Using
edge_list
only; - Having quick access to a vertex by its name;
- Optimal by time (and RAM if possible).
Is there any good way to do this?
EDIT: Current code:
g = grt.Graph(directed=False)
g.add_vertex(len(ids))
vprop = g.new_vertex_property("string", vals=ids)
g.vp.user_id = vprop
for vert1, vert2 in edges_list:
g.add_edge(g.vertex(ids_dict[vert1]), g.vertex(ids_dict[vert2]))
igraph
for clustering (or searching communities if you prefer this term) andgraph-tool
for measuring centralities and for drawing graphs. I am using frozenset to collect data from the source. Runtime is the main problem. The question is: what will be faster: usingadd_edge_lis()
oradd_edge()
in cycle? I added current code in the question field above. – Emmieemmit