[英]Lengauer Tarjan Algorithm in BGL (boost graph library)
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. 当我将dominator_tree的内容输出到.dot文件时,它与trace中的内容完全相同。 Ie 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 输入图如下所示: 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. INIT节点是节点0。如果我选择其他任何节点作为该函数的第二个参数,它仍将返回相同的结果。
What am I doing wrong?? 我究竟做错了什么?? Apreciate any help. 感谢任何帮助。
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. 看一下文档( http://www.boost.org/doc/libs/1_40_0/libs/graph/doc/lengauer_tarjan_dominator.htm ),我看到第一个参数标记为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. THIRD参数标记为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. OUT:DomTreePredMap domTreePredMap父级树,其中父级是每个孩子的直接父级。
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. 因此,如果要更改图形,则必须自己做:删除所有现有边,然后遍历树,按照树指定的方式将边添加到图形中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.