Thanks for the quick response Thiago!
In this code all the edges and vertices are created by graph-tool and the
result is something much faster...
is this the best I can do?
It's somewhat annoying to have to keep track of the vertices that will be
created like this:
def graph_tool_create_all_at_once():
""" Create a graph_tool graph given a list of pairs. """
G = Graph(directed=False)
objectTOi = {}
vertexpairs = []
counter = 0
for o1,o2 in get_pairs_of_ints():
if(o1 in objectTOi):
u = objectTOi[o1]
else:
u = counter
counter += 1
objectTOi[o1] = u
if(o2 in objectTOi):
v = objectTOi[o2]
else:
v = counter
counter += 1
objectTOi[o2] = v
vertexpairs.append((u,v))
G.add_edge_list(vertexpairs)
On 27 April 2015 at 16:39, Tiago de Paula Peixoto <[email protected]> wrote:
> On 27.04.2015 14:29, thekswenson wrote:
> > I've been using networkx to simply create a graph and check the connected
> > components. The bottleneck of the operation is the creation of the
> edges.
> >
> > I've heard that graph-tool is very efficient so I've replaces the code
> with
> > a graph-tool graph.
> > To my surprise, the creation of a graph-tool graph is MUCH slower than
> that
> > of a networkx graph.
> >
> > Am I doing something wrong?
>
> How does the performance change if you create the necessary edges
> beforehand?
>
> In graph-tool things are faster than in networkx when they are delegated
> to C++, otherwise this should be comparable in speed. In the case of
> adding many edges, this is done by using the Graph.add_edge_list()
> function, which runs in C++ internally. In your example, this should
> provide a massive speed-up.
>
> Best,
> Tiago
>
> --
> Tiago de Paula Peixoto <[email protected]>
>
>
> _______________________________________________
> graph-tool mailing list
> [email protected]
> http://lists.skewed.de/mailman/listinfo/graph-tool
>
>
_______________________________________________
graph-tool mailing list
[email protected]
http://lists.skewed.de/mailman/listinfo/graph-tool