对不起新手的问题,但我正在试着开始使用BGL。我正在尝试深度优先搜索:
boost::default_dfs_visitor vis;
boost::depth_first_search( graph, boost::visitor(vis) );
我得到了关于彩色地图的大量错误消息:
In file included from /usr/include/boost/graph/named_function_params.hpp:22,
from /usr/include/boost/graph/depth_first_search.hpp:21,
from main.cc:6:
/usr/include/boost/property_map/shared_array_property_map.hpp: In member function 'T& boost::shared_array_property_map<T, IndexMap>::operator[](typename boost::property_traits<IndexMap>::key_type) const [with T = boost::default_color_type, IndexMap = boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t>]':
/usr/include/boost/property_map/property_map.hpp:324: instantiated from 'void boost::put(const boost::put_get_helper<Reference, PropertyMap>&, K, const V&) [with PropertyMap = boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >, Reference = boost::default_color_type&, K = void*, V = boost::default_color_type]'
/usr/include/boost/graph/depth_first_search.hpp:196: instantiated from 'void boost::depth_first_search(const VertexListGraph&, DFSVisitor, ColorMap, typename boost::graph_traits<Graph>::vertex_descriptor) [with VertexListGraph = boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, DFSVisitor = boost::dfs_visitor<boost::null_visitor>, ColorMap = boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >]'
/usr/include/boost/graph/depth_first_search.hpp:295: instantiated from 'void boost::depth_first_search(const VertexListGraph&, const boost::bgl_named_params<P, T, R>&) [with VertexListGraph = TreeGraph::graph_type, P = boost::dfs_visitor<boost::null_visitor>, T = boost::graph_visitor_t, R = boost::no_property]'
main.cc:272: instantiated from here
/usr/include/boost/property_map/shared_array_property_map.hpp:36: error: no match for 'operator[]' in '((const boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >*)this)->boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >::data[boost::get [with PropertyMap = boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t>, Reference = const boost::detail::error_property_not_found&, K = void*](((const boost::put_get_helper<const boost::detail::error_property_not_found&, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >&)((const boost::put_get_helper<const boost::detail::error_property_not_found&, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >*)(&((const boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >*)this)->boost::shared_array_property_map<boost::default_color_type, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node, boost::no_property>, boost::no_property, boost::no_property, boost::listS>, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t> >::index))), ((void* const&)((void* const*)(& v))))]'
/usr/include/boost/smart_ptr/shared_array.hpp:85: note: candidates are: T& boost::shared_array<T>::operator[](ptrdiff_t) const [with T = boost::default_color_type]
depth_first_search的文档说有一个默认值,我看过很多不提供自己颜色图的例子,所以我不确定为什么会有问题。
我的图表类型是:
typedef
boost::adjacency_list<
boost::vecS, boost::listS, boost::directedS,
boost::property<boost::vertex_treegraphnode_t, TreeGraph::node>
>
graph_type;
我想也许因为我有一个自定义属性映射,也许会覆盖一些depth_first_search需要的默认颜色映射,但我补充说:
boost::property<boost::vertex_color_t, boost::default_color_type>
到属性列表,这也没有帮助。
我尝试使用外部color_map进行depth_first搜索,这似乎也没有帮助。
关于我可能做错的任何想法?
感谢。
答案 0 :(得分:3)
const boost::detail::error_property_not_found&, boost::vertex_index_t
这是“错误之海”的重要部分。只有adjacency_list
作为vecS
模板参数的VertexList
具有默认的内部vertex_index
属性,默认颜色映射使用此属性(您正在使用{{1} })。你有几种选择:
listS
作为第二个参数(如果您不需要动态修改图形,这是最简单的一个)。 您可以创建内部属性,然后确保对其进行初始化并使其与图表保持同步。为此,您需要将vecS
定义为:
VertexProperty
然后:
boost::property<vertex_index_t, std::size_t, boost::property<boost::vertex_treegraphnode_t, TreeGraph::node>>
您可以创建外部属性,对其进行初始化并使其保持最新状态,然后使用命名参数将其传递给boost::property_map<graph_type,vertex_index_t>::type my_vertex_index_map=get(vertex_index,graph);
std::size_t current_index=0;
BGL_FORALL_VERTICES(v,graph,graph_type)
put(my_vertex_index_map,v,current_index++);
。
depth_first_search