2

How come there is no routine to remove multiple vertices at the same time in the graph? There is only remove_vertex() which is very costly if the vertices are vecS.

In boost/graph/detail/adjacency_list.hpp remove_vertex_dispatch() starting line # 1966 routine, it erases the given node, then re-indexes the edges. Can another routine be added that takes say, the indexes of the vertices to be removed and they're erased in one shot (how? can be discussed) and the re-indexing happens just once?

I understand using listS makes it constant time, but not all algorithms work for listS so that's out of the question.

Dula
  • 1,404
  • 1
  • 14
  • 29

1 Answers1

3

If you remove a vertex, you cant avoid to reindex all edges and update your vector. This has a non local cost that is at least linear with the number of vertices and this may indeed be costly.

That being said, one technique you may use is to cache a boolean in every vertex that is initially set to true. Now, to remove a vertex you remove all edges connected to the vertex and you set the vertex boolean to false. That way, the deletion time is only local and you dont have a linear time with the number of vertices. You then need to adapt some operations, for instance to iterate over vertices, you select only those having their boolean set to true.

This technique is quite common and it is used for instance to simplify 3D triangulation (you remove vertex iteratively and you want a local cost to be fast). Compared to listS you can still acess directly to your vertices (vertex handles remain valid after deletion of a vertex).

geoalgo
  • 678
  • 3
  • 11
  • Insightful answer. You have my upvote – sehe Feb 26 '15 at 13:20
  • Right, I'm using the technique already. But my case is where the graph can be used for weeks, adding and removing large number of nodes. Also during that time it's serialized to save and re-open. I only try to actually delete the "deleted" nodes right before serializing. I wonder if I can manipulate the serialized string to remove the "deleted" nodes since they have no in or out edges. – Dula Feb 26 '15 at 18:20