1

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

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

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。如果我选​​择任何其他节点作为函数的第二个参数,它仍然返回相同的结果。

我究竟做错了什么??感谢任何帮助。

4

1 回答 1

2

查看文档(http://www.boost.org/doc/libs/1_40_0/libs/graph/doc/lengauer_tarjan_dominator.htm)我看到第一个参数标记为IN。

这意味着这只是一个输入参数。所以你不应该期望它会被改变!

第三个参数标记为 OUT。所以这是调用后将更改的值。根据文档:

OUT:DomTreePredMap domTreePredMap 支配树,其中父母是每个孩子的直接支配者。

因此,如果要更改图形,则必须自己动手:删除所有现有边,然后遍历树,将边添加到树指定的图形中。

于 2013-08-07T02:13:02.973 回答