BGL中的Lengauer-Tarjan算法

Lengauer Tarjan Algorithm in BGL (boost graph library)

本文关键字:算法 Lengauer-Tarjan 中的 BGL      更新时间:2023-10-16

我需要为给定的图创建一个支配树。我编译并运行的代码没有错误,但输出看起来与输入完全相同。

我已经为我的图形(待分析)定义了以下类型

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父代所在的支配者树是每个孩子的直接支配者。

因此,如果你想更改图形,你必须自己做:删除所有现有的边,然后在树中迭代,根据树的指定向图形添加边。