[BGL] Remove all vertices from graph with zero degree
Hi all again!
I would really appreciate any ideas how to implement (subject)
efficiently with bearing in mind "Iterator" stability. Graph
representation is the following:
typedef adjacency_list<
listS, /// Graph; filtered_graph seems isn't what I need. I would like to right as follow
Graph g;
remove_empty_vertices(g);
//Now g doesn't contain zero degree vertices
Many thanks in advance,
regards,
--dima
On 12/15/05, Dmitry Bufistov
Hi all again!
I would really appreciate any ideas how to implement (subject) efficiently with bearing in mind "Iterator" stability. Graph representation is the following:
typedef adjacency_list< listS, ///
Graph;
filtered_graph seems isn't what I need. I would like to right as follow
Graph g; remove_empty_vertices(g); //Now g doesn't contain zero degree vertices
Do you need a vector to store your vertex ? With a vector, you can't remove (or add) vertices without invalidated all your vertex iterators. I suggest you to use a listS or setS for your vertex set. Thus, you can write your remove_empty_vertices function like this: template < class Graph > void remove_empty_vertices(Graph& g) { BGL_FORALL_VERTICES(v, g, Graph) { if (degree (v, g) == 0) remove_vertex (v, g); } } else, I don't see an efficient way to do it. (I think you have to restart the loop when you remove a vertex)
Many thanks in advance,
regards,
There may be a better solution... but choose your vertex set container
carefully:
http://www.boost.org/libs/graph/doc/adjacency_list.html>
In general, if you want your vertex and edge descriptors to be stable
(never invalidated) then use listS or setS for the VertexList and
OutEdgeList template parameters of adjacency_list. If you are not as
concerned about descriptor and iterator stability, and are more
concerned about memory consumption and graph traversal speed, use vecS
for the VertexList and/or OutEdgeList template parameters.
</quote>
--
Johan
The way that I had to implement a template function to erase a graph was like:
template<typename T1> inline void
WorkFlow_Datum::EraseGraph(T1& g)
{
typedef typename std::vector
Hi all again!
I would really appreciate any ideas how to implement (subject) efficiently with bearing in mind "Iterator" stability. Graph representation is the following:
typedef adjacency_list< listS, ///
Graph;
filtered_graph seems isn't what I need. I would like to right as follow
Graph g; remove_empty_vertices(g); //Now g doesn't contain zero degree vertices
Many thanks in advance,
regards, --dima
participants (3)
-
Dmitry Bufistov
-
Jeffrey Holle
-
Johan Oudinet