[graph-tool] Fast initialization of graph
Tiago de Paula Peixoto
tiago at skewed.de
Tue Mar 19 11:51:20 CET 2013
Hi,
On 03/19/2013 09:39 AM, arnfred wrote:
> I'm currently trying to instantiate a fully connected graph with some 600
> vertices, but I find that adding all the edges usually takes around 10
> seconds on my system. The fastest way of doing it that I have come up with
> so far is to write:
>
> from itertools import combinations
> edges = [g.add_edge(v1,v2) for (v1,v2) in combinations(g.vertices(),2)]
>
> But I'm wondering if there is a faster method?
You can create a "random" graph with all degrees equal to N - 1:
g = random_graph(600, lambda: 600 - 1, directed=False, random=False)
This should be much faster. Note the option 'random=False' which avoids
the random placement of the edges, which would be completely pointless
in this case.
I'm planning to include a complete graph generator, as well as some
other simple generators, which would make this more straightforward.
Cheers,
Tiago
--
Tiago de Paula Peixoto <tiago at skewed.de>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 555 bytes
Desc: OpenPGP digital signature
URL: <https://lists.skewed.de/pipermail/graph-tool/attachments/20130319/19187304/attachment.asc>
More information about the graph-tool
mailing list