【问题标题】:Lengauer Tarjan Algorithm in BGL (boost graph library)BGL 中的 Lengauer Tarjan 算法(boost 图形库)
【发布时间】:2013-08-07 19:40:56
【问题描述】:

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

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

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 中的内容完全相同。 IE。看起来上面最后一行的调用没有改变任何东西。输入图如下所示: http://s24.postimg.org/y17l17v5x/image.png

INIT 节点是节点 0。如果我选​​择任何其他节点作为函数的第二个参数,它仍然返回相同的结果。

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

【问题讨论】:

    标签: c++ graphviz graph-algorithm boost-graph


    【解决方案1】:

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

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

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

    OUT: DomTreePredMap domTreePredMap 父节点所在的支配树 是每个孩子的直接支配者。

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

    【讨论】:

    • 非常感谢!我认为这是有道理的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    相关资源
    最近更新 更多