BGL中的Lengauer-Tarjan算法
Lengauer Tarjan Algorithm in BGL (boost graph library)
我需要为给定的图创建一个支配树。我编译并运行的代码没有错误,但输出看起来与输入完全相同。
我已经为我的图形(待分析)定义了以下类型
typedef boost::adjacency_list<boost::listS, boost::vecS,
boost::bidirectionalS, vertex_info, edge_info> Graph;
并且我想要另一个包含相应支配者树的对象。我尝试了以下方法:
// dominator tree is an empty Graph object
dominator_tree = trace;
typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
typedef typename boost::property_map<Graph, boost::vertex_index_t>::type IndexMap;
typedef typename boost::iterator_property_map<typename std::vector<Vertex>::iterator, IndexMap> PredMap;
IndexMap indexMap(get(boost::vertex_index, dominator_tree));
std::vector<Vertex> domTreePredVector = std::vector<Vertex>(
num_vertices(dominator_tree),
boost::graph_traits<Graph>::null_vertex());
PredMap domTreePredMap = make_iterator_property_map(
domTreePredVector.begin(), indexMap);
lengauer_tarjan_dominator_tree(dominator_tree, vertex(0, dominator_tree),
domTreePredMap);
当我将dominator_tree的内容输出到.dot文件时,它与trace中的内容完全相同。也就是说,上面最后一行的调用似乎没有改变任何东西。输入图如下所示:http://s24.postimg.org/y17l17v5x/image.png
INIT节点是节点0。如果我选择任何其他节点作为函数的第二个参数,它仍然会返回相同的结果。
我做错了什么??请接受任何帮助。
查看文档(http://www.boost.org/doc/libs/1_40_0/libs/graph/doc/lengauer_tarjan_dominator.htm)我看到第一个参数标记为IN。
这意味着这只是一个输入参数ONLY。所以你不应该期望它被改变!
第三个参数标记为OUT。因此,这是在调用之后将更改的值。根据文件:
OUT:DomTreeRedMap domTreeRedMap父代所在的支配者树是每个孩子的直接支配者。
因此,如果你想更改图形,你必须自己做:删除所有现有的边,然后在树中迭代,根据树的指定向图形添加边。
相关文章:
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 基于ELO的团队匹配算法
- C++选择排序算法中的逻辑错误
- 有没有办法将谓词中的元素偏移量传递给 std 算法?
- C++A*算法并不总是在路径中具有目标节点
- 排序算法c++
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 算法问题:查找从堆栈中弹出的所有序列
- 下面是排序算法O(n)吗
- KMP算法和LPS表构造的运行时间
- 为什么我的排序算法会更改数组值
- 求最大元素位置的分治算法
- 具有非整数边容量的最大流量的Dinic算法
- 到连接组件算法的问题(递归)
- STL算法函数在多个一维容器上的使用
- 读取最后一行代码算法 - c++ 时出现问题
- 括号更改 O(n) 算法
- std::unordered_map 搜索算法是如何实现的?
- 如何实现高效的算法来计算大型数据集的多个不同值?
- BGL中的Lengauer-Tarjan算法