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.

geofurb
  • 489
  • 4
  • 13

1 Answers1

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)
Peaceful
  • 4,920
  • 15
  • 54
  • 79