|
Boost Users : |
Subject: [Boost-users] BGL:add vertex and edge to subgraph
From: Alice.gugu (alice.gugu_at_[hidden])
Date: 2009-04-20 01:39:32
Hi,
I want to generate a local spanning tree of one graph(not MST) so I construct a subgraph of the original graph by add_vertex() and add_edge() function.
The problem is that after the add_vertex(). the local tree generate edges between the vertexes automaticlly. If I call add_edge() again, it will dumplicat edges since all the edges between existing vertex have been added by add_vertex() function.
I checked the example code of how to add vertex and edge in subgraph. It seems the add_vertex() function should not add edges automaticlly.
SUBGRAPH m_g;
...
//Create spanning tree
SUBGRAPH& localTree = m_g.create_subgraph();
//Add one vertex as root in spanning tree
boost::add_vertex(m_root, localTree);
//Add descendants to the tree
typedef graph_traits<SUBGRAPH> GTraits;
GTraits::out_edge_iterator tmpei, tmpei_end;
std::pair<GTraits::out_edge_iterator, GTraits::out_edge_iterator> p;
p = out_edges(m_root, m_g);
tmpei = p.first;
tmpei_end = p.second;
while ( tmpei != tmpei_end )
{
//Descendant
PolyGraphVertex tmpv = target(*tmpei , m_g);
//Add descendant
boost::add_vertex(tmpv, localTree);
//Add an edge from ancestor to descendant
boost::add_edge(m_root,tmpv,localTree);
tmpei++;
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net