グラフ内のすべての頂点にアクセス、フィルタリング、インデックス付けなどを行わずに、BGLの頂点からある程度の距離まで、深さまたは幅の最初の検索/訪問を実行することは可能ですか?
私が何とか書いた最も近いものは(グラフ0 <-> 1 <-> 2 <-> 3 <-> 4 <-> 5を作成しますが、頂点0から3にのみアクセスします):
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/depth_first_search.hpp>
using namespace std;
struct custom_dfs_visitor : public boost::default_dfs_visitor {
template < typename Vertex, typename Graph >
void discover_vertex(const Vertex& v, const Graph& g) const {
std::cout << v << std::endl;
}
};
struct Terminator {
template<class Vertex, class Graph>
bool operator()(const Vertex& v, const Graph& g) {
return v > 2;
}
};
int main()
{
typedef boost::adjacency_list<
boost::vecS,
boost::vecS,
boost::undirectedS
> Graph_T;
Graph_T g(6);
boost::add_edge(0, 1, g);
boost::add_edge(1, 2, g);
boost::add_edge(2, 3, g);
boost::add_edge(3, 4, g);
boost::add_edge(4, 5, g);
std::vector<boost::default_color_type> color_map(boost::num_vertices(g));
boost::depth_first_visit(
g,
boost::vertex(0, g),
custom_dfs_visitor(),
boost::make_iterator_property_map(
color_map.begin(),
boost::get(boost::vertex_index, g),
color_map[0]
),
Terminator()
);
return 0;
}
これは、すべての頂点にアクセスする代わりに0 1 2 3のみを出力しますが、コードには、グラフ全体と同じ大きさのカラーマップが必要です(boost :: num_vertices(g))。検索の複雑さをグラフのエッジ/頂点の総数とまったく比較できないようにする方法はありますか?
グラフのさまざまな部分で多くの検索が行われるため、バンドルされた色を使用することは許容されますが、O(number_of_vertices)から同じグラフでの個々の検索の複雑さを軽減することは可能ですか?ターミネーターがtrueに戻ったときに、頂点の初期カラーリングも停止することを願っていますが、それはすでに処理されているようです。おそらく関連する質問:グラフがvecS以外のものを使用している場合、インデックス付けはどうですか?その場合、BFS / DFSはインデックス付けなしで実行できますか?助けてくれてありがとう。