Skip to content Skip to sidebar Skip to footer

Faster Way To Delete Edge By Vertex Index [igraph Python]

I'm working with AI and one of my algorithms needs to work adding and removing edges. I can do it with igraph, but my problem is: It's too slow. If I work with two dictionaries, I

Solution 1:

igraph's data structures are optimized for fast queries but not-so-fast updates. There are several data structures within an igraph graph that have to be updated / reindexed whenever you add a vertex, delete a vertex, add an edge or delete an edge. In many cases, deleting a single edge is almost as costly as deleting many of them in one single pass.

For instance, if I understood correctly, your goal above is to delete all edges that fall between two vertex groups (self.vertexSI and self.vertexSJ). You could do it like you did above, but this will be very slow since you are deleting edges one-by-one. You could speed it up already by collecting the IDs of the edges to delete first into a list, and then call self.g.delete_edges() with that list at the end. But there is an even simpler one-liner (assuming that your graph is undirected):

self.g.es.select(_between=(self.vertexSI, self.vertexSJ)).delete()

Post a Comment for "Faster Way To Delete Edge By Vertex Index [igraph Python]"