我想使用dfs算法创建图表的搜索树。我的编码错误一遍又一遍地编译错误(编译错误很长,以至于我没有粘贴它):
typedef adjacency_list <vecS, vecS, undirectedS> Graph;
typedef graph_traits <Graph>::edge_descriptor Edge;
typedef graph_traits <Graph>::vertex_descriptor Vertex;
typedef pair<int, int> E;
vector<E> edges;
Graph g(edges.begin(), edges.end(), n);
vector<Vertex> p(n);
Vertex s = vertex(0,g);
breadth_first_search(g, s, visitor(record_predecessors(&p[0], on_tree_edge())));
部分错误:
instantiated from here
/usr/include/boost/graph/breadth_first_search.hpp:39:7: error: ‘struct boost::predecessor_recorder<long unsigned int*, boost::on_tree_edge>’ has no member named ‘initialize_vertex’
/usr/include/boost/graph/breadth_first_search.hpp:40:7: error: ‘struct boost::predecessor_recorder<long unsigned int*, boost::on_tree_edge>’ has no member named ‘discover_vertex’
/usr/include/boost/graph/breadth_first_search.hpp:41:7: error: ‘struct boost::predecessor_recorder<long unsigned int*, boost::on_tree_edge>’ has no member named ‘examine_vertex’
/usr/include/boost/graph/breadth_first_search.hpp:42:7: error: ‘struct boost::predecessor_recorder<long unsigned int*, boost::on_tree_edge>’ has no member named ‘examine_edge’
/usr/include/boost/graph/breadth_first_search.hpp:43:7: error: ‘struct boost::predecessor_recorder<long unsigned int*, boost::on_tree_edge>’ has no member named ‘tree_edge’
/usr/include/boost/graph/breadth_first_search.hpp:44:7: error: ‘struct boost::predecessor_recorder<long unsigned int*, boost::on_tree_edge>’ has no member named ‘non_tree_edge’
/usr/include/boost/graph/breadth_first_search.hpp:45:7: error: ‘struct boost::predecessor_recorder<long unsigned int*, boost::on_tree_edge>’ has no member named ‘gray_target’
/usr/include/boost/graph/breadth_first_search.hpp:46:7: error: ‘struct boost::predecessor_recorder<long unsigned int*, boost::on_tree_edge>’ has no member named ‘black_target’
/usr/include/boost/graph/breadth_first_search.hpp:47:7: error: ‘struct boost::predecessor_recorder<long unsigned int*, boost::on_tree_edge>’ has no member named ‘finish_vertex’
make: *** [file] Error 1
答案 0 :(得分:3)
breadth_first_search
需要BFSVisitor
。 record_predecessors
会返回EventVisitor
。您需要使用make_bfs_visitor
才能使其正常运行。
breadth_first_search(g, s, visitor(make_bfs_visitor(record_predecessors(&p[0], on_tree_edge()))));