1

What's the fastest/most performant way to add edges without duplicates to a digraph in Python's graph-tool?

The naive solution would be to call g.edge(u, v) before adding edges, but that seems like quite a performance hit, especially in scale-free networks. Does g.edge(u, v) do lookups in O(1) if g.set_fast_edge_removal() has been set? I imagine whatever additional data structure graph-tool allocates for that is something along the lines of an edge list.

1 Answer 1

4

In my opinion, it is best to add all the edges, and then remove the parallel edges.

You can add edges as a list:

g = gt.Graph()
edges = [(1, 2), (2, 5), (1, 2)]
g.add_edge_list(edges)
gt.remove_parallel_edges(g)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.