我正在看解决方案here,这对我不起作用(但在 === 行下阅读以实际查看当前问题)。
I tried:
boost::undirected_dfs(G, vertex(0,G), boost::visitor(vis));
但我得到
error C2780: 'void boost::undirected_dfs(const Graph &,const boost::bgl_named_params<P,T,R> &)' : expects 2 arguments - 3 provided
error C2780: 'void boost::undirected_dfs(const Graph &,DFSVisitor,VertexColorMap,EdgeColorMap)' : expects 4 arguments - 3 provided
我有点明白问题是什么(我需要向它传递一些命名参数,但我认为我的图中没有任何参数。另外,我不明白颜色图的处理是什么,根本不。
=================================================== ===========================
我的图表定义为:
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, boost::no_property, EdgeInfoProperty > Graph;
typedef Graph::edge_descriptor Edge;
typedef Graph::vertex_descriptor Vertex;
我只想做 DFS,至少现在是这样。
所以我把它改为boost::depth_first_search
,而且它似乎有效。
我有(注意缺乏const
for void discover_vertex
与上面链接的解决方案相比):
class MyVisitor : public boost::default_dfs_visitor {
public:
void discover_vertex(Vertex v, const Graph& g) { //note the lack of const
if(boost::in_degree(v,g)!=0){ //only print the vertices in the connected component (I already did MCC and removed edges so all the extra vertices are isolated)
std::cerr << v << std::endl;
vv.push_back(v);
}
return;
}
std::vector<Vertex> GetVector() const { return vv; }
private:
std::vector<Vertex> vv;
};
如果我离开const
我得到了error C2663: 'std::vector<_Ty>::push_back' : 2 overloads have no legal conversion for 'this' pointer with [ _Ty=size_t ]
.
现在,这工作得很好,或者至少它以正确的顺序打印出正确访问的顶点:
MyVisitor vis;
boost::depth_first_search(G, boost::visitor(vis));
但是当我这样做时:
std::vector<Vertex> vctr = vis.GetVector();
std::cout<<vctr.size();
大小为零,因为我的vv
没有改变...
那么,当类用作参数时,如何获得适当的类行为boost::visitor
? (我什至不确定这是一个合适的问题)。我需要能够改变EdgeInfoProperty
基于之前访问过哪些节点(或者更确切地说,基于 DFS 遍历中哪个顶点是当前顶点的父节点,因此这可能只是实现这一目标的第一步)。