3
私は双方向グラフを持っています。いくつかの頂点は未接続です。私はboost :: depth_first_searchを使って頂点を走査します。私はまた、出発点ノードを提供します。私は接続されているノードが完了した後に未接続の頂点も処理されることを知ります。どのように私はそのようなノードを訪問することを防ぎますか実際、ソースノードから到達可能なノードだけを訪問し、他のノードを訪問しないようにDFSに指示するにはどうすればよいですか。ブーストグラフライブラリ:DFSが未接続ノードにアクセスしないようにする
私は、次のコードを持って:あなたはdepth_first_visit
、ないdepth_first_search
を使用したい
/// Define vertex properties.
struct NodeProperty
{
unsigned id; /// Id.
unsigned kind; /// Kind.
unsigned depth; /// Depth.
unsigned layer_color; /// Layer color.
unsigned signal_color; /// Signal color.
unsigned sch_color; /// Sch color.
CBoundingBox bounds; /// Bounds of polygon.
NodeProperty()
: id(0), kind(0), depth(0), layer_color(0), signal_color(0), sch_color(0), bounds(0,0,0,0)
{
;
}
};
/// Define net topology graph.
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, NodeProperty> Graph;
class receiver_visitor : public boost::default_dfs_visitor
{
public:
receiver_visitor(std::vector<Vertex>& r)
: res(r)
{
;
}
void discover_vertex(Vertex v, Graph const& g) const
{
std::cout << "Visit: " << v << std::endl;
if (g[v].sch_color) {
res.push_back(g[v].sch_color);
}
}
std::vector<Vertex>& res;
};
std::vector<std::size_t>
NetTopology::getReceivers(std::size_t src) const
{
std::vector<Vertex> r;
receiver_visitor vis(r);
boost::depth_first_search(data_->g, boost::visitor(vis).root_vertex(src));
return r;
}
depth_first_visitには、ColorMapプロパティが必要です。どのように(デフォルト)1つを供給するのですか? – user4979733
http://stackoverflow.com/questions/11666131/color-map-in-boost-graph-breadth-first-visit – MSN