c++ - 为深度优先搜索定义 ColorMap 的最简单方法

标签 c++ boost boost-graph

我想使用深度优先搜索算法。既然我需要 指定起始顶点的 DFS 版本,我也 必须定义一个 ColorMap。这就是我想要的功能 使用:

template <class Graph, class DFSVisitor, class ColorMap>
void depth_first_search(const Graph& g, DFSVisitor vis, ColorMap color, 
             typename graph_traits<Graph>::vertex_descriptor start)

https://www.boost.org/doc/libs/1_67_0/libs/graph/doc/depth_first_search.html

由于 map 与我无关,默认的 ColorMap 就足够了。 您能否给我一个提示,如何创建它并将其作为深度_first_search 中的参数传递?

最佳答案

只需使用命名参数重载即可,这样您就可以在使用默认颜色贴图时指定起始顶点。

template <class Graph, class class P, class T, class R>
void depth_first_search(Graph& G, const bgl_named_params<P, T, R>& params);

示例:

boost::depth_first_search(graph, boost::root_vertex(start_vertex));

关于c++ - 为深度优先搜索定义 ColorMap 的最简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53874626/

相关文章:

c++ - 无法从其他类的函数访问对象的参数

c++ - 根据 boost::filesystem,为什么这个文件不是常规文件?

c++ - Boost 的 UDP 异步客户端接收自己的数据报

c++ - 动态添加 vertex_index 到 listS 图以实现中间中心性

c++ - 通过 boost :MPI got error 发送一个简单的 boost 图形对象

c++ - sizeof 对 gdb 中数组的引用

c++ - 从 std::set 或 std::map 继承初始化语法

c++ - 继承二级基类构造函数: silent error

c++ - boost::unordered_map 是……有序的?

shortest-path - 实际保存路线的全对最短路径算法?