Lengauer Tarjan Algorithm in BGL (boost graph library)

白昼怎懂夜的黑 提交于 2019-12-11 12:13:03

问题


I need to create a dominator tree for a given graph. The code I have compiles and runs without errors, but the output looks exactly the same as the input.

I have defined the following type for my graph (to be analyzed)

typedef boost::adjacency_list<boost::listS, boost::vecS,
  boost::bidirectionalS, vertex_info, edge_info> Graph;

and I would like to have another object containing the corresponding dominator tree. I tried the following:

  // 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);

When I output the content of dominator_tree to a .dot file, it is exactly the same as in trace. I.e. it looks like the call of the last line above did not change anything. The input graph looks like this: http://s24.postimg.org/y17l17v5x/image.png

The INIT node is the node 0. If I choose any other node as the second argument of the function, it still returns an identical result.

What am I doing wrong?? Apreciate any help.


回答1:


Taking a look at the documentation ( http://www.boost.org/doc/libs/1_40_0/libs/graph/doc/lengauer_tarjan_dominator.htm ) I see that the first parameter is marked IN.

This means that this is an input parameter ONLY. So you should not expect it to be changed!

The THIRD parameter is marked OUT. So this is the value that will be changed following the call. According to the documentation:

OUT: DomTreePredMap domTreePredMap The dominator tree where parents are each children's immediate dominator.

So, if you want the graph to be changed, you will have to do it yourself: remove all existing edges and then iterate through the tree adding edges to the graph as specified by the tree.



来源:https://stackoverflow.com/questions/18091758/lengauer-tarjan-algorithm-in-bgl-boost-graph-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!