Lengauer Tarjan Algorithm in BGL (boost graph libr

2019-07-30 03:32发布

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条回答
Summer. ? 凉城
2楼-- · 2019-07-30 04:12

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.

查看更多
登录 后发表回答