File: lengauer_tarjan_dominator.htm

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (187 lines) | stat: -rw-r--r-- 7,208 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<HTML>
<!--
  -- Copyright (c) JongSoo Park 2005
  --
  -- Permission to use, copy, modify, distribute and sell this software
  -- and its documentation for any purpose is hereby granted without fee,
  -- provided that the above copyright notice appears in all copies and
  -- that both that copyright notice and this permission notice appear
  -- in supporting documentation.  Jeremy Siek makes no
  -- representations about the suitability of this software for any
  -- purpose.  It is provided "as is" without express or implied warranty.
  -->
<Head>
<Title>Boost Graph Library: Lengauer-Tarjan Dominator Tree Algorithm</Title>
<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" 
        ALINK="#ff0000"> 
<IMG SRC="../../../boost.png" 
     ALT="C++ Boost" width="277" height="86"> 

<BR Clear>

<H1><A NAME="sec:lengauer-tarjan"></A>
<TT>lengauer_tarjan_dominator_tree</TT>
</H1>


<P>
<PRE>
<i>// The simplest version:
// Data structures for depth first search is created internally,
// and depth first search runs internally.</i>
template &lt;class Graph, class DomTreePredMap&gt;
void
lengauer_tarjan_dominator_tree
  (const Graph&amp; g,
   const typename graph_traits&lt;Graph&gt;::vertex_descriptor&amp; entry,
   DomTreePredMap domTreePredMap)

<i>// The version providing data structures for depth first search:
// After calling this function,
// user can reuse the depth first search related information
// filled in property maps.</i>
template &lt;class Graph, class IndexMap, class TimeMap, class PredMap,
             class VertexVector, class DomTreePredMap&gt;
void
lengauer_tarjan_dominator_tree
  (const Graph&amp; g,
   const typename graph_traits&lt;Graph&gt;::vertex_descriptor&amp; entry,
   const IndexMap&amp; indexMap,
   TimeMap dfnumMap, PredMap parentMap, VertexVector&amp; verticesByDFNum,
   DomTreePredMap domTreePredMap)

<i>// The version without depth first search:
// The caller should provide depth first search related information
// evaluated before.</i>
template &lt;class Graph, class IndexMap, class TimeMap, class PredMap,
             class VertexVector, class DomTreePredMap&gt;
void
lengauer_tarjan_dominator_tree_without_dfs(
  (const Graph&amp; g,
   const typename graph_traits&lt;Graph&gt;::vertex_descriptor&amp; entry,
   const IndexMap&amp; indexMap,
   TimeMap dfnumMap, PredMap parentMap, VertexVector&amp; verticesByDFNum,
   DomTreePredMap domTreePredMap)
</PRE>

<P> This algorithm&nbsp;[<A
HREF="bibliography.html#lengauer-tarjan79">65</A>,<A
HREF="bibliography.html#muchnick97">66</A>,<A
HREF="bibliography.html#appel98">67</A>] builds the dominator tree for
directed graph. There are three options for dealing the depth first
search related values. The simplest version creates data structures
and run depth first search internally. However, chances are that a
user wants to reuse the depth first search data, so we have two
versions.  </P>

<P> A vertex <i>u</i> dominates a vertex <i>v</i>, if every path of
directed graph from the entry to <i>v</i> must go through <i>u</i>. In
the left graph of <a href="#fig:dominator-tree-example">Figure 1</a>,
vertex 1 dominates vertex 2, 3, 4, 5, 6 and 7, because we have to pass
vertex 1 to reach those vertex. Note that vertex 4 dominates vertex 6,
even though vertex 4 is a successor of vertex 6. Dominator
relationship is useful in many applications especially for compiler
optimization. We can define the immediate dominator for each vertex
such that <i>idom(n) dominates n</i> but does not dominate any other
dominator of <i>n</i>. For example, vertex 1, 3 and 4 are dominators
of vertex 6, but vertex 4 is the immediate dominator, because vertex 1
and 3 dominates vertex 4. If we make every idom of each vertex as its
parent, we can build the dominator tree like the right part of <a
href="#fig:dominator-tree-example">Figure 1</a> </P>

<P></P>
<DIV ALIGN="CENTER"><A NAME="fig:dominator-tree-example">
<TABLE>
<CAPTION ALIGN="BOTTOM"><STRONG>Figure 1:</STRONG>
An example graph and its dominator tree.</CAPTION>
<TR>
<TD><IMG SRC="./figs/dominator-tree1.gif"></TD>
<TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
<TD><IMG SRC="./figs/dominator-tree2.gif"></TD>
</TR>
</TABLE>
</DIV><P></P>

<P> An easy way to build dominator tree is to use iterative bit vector
algorithm, but it may be slow in the worst case. We implemented
Lengauer-Tarjan algorithm whose time complexity is
<i>O((V+E)log(V+E))</i>.  </P>

<P> Lengauer-Tarjan algorithm utilizes two techniques. The first one
is, as an intermediate step, finding semidominator which is relatively
easier to evaluate than immediate dominator, and the second one is the
path compression. For the detail of the algorithm, see [<A
HREF="bibliography.html#lengauer-tarjan79">65</A>].  </P>

<h3>Where Defined</h3>

<a href="../../../boost/graph/dominator_tree.hpp"><tt>boost/graph/dominator_tree.hpp</tt></a>

<h3>Parameters</h3>

IN: <tt>const Graph&amp; g</tt>
<blockquote>
  The graph object on which the algorithm will be applied.
  The type <tt>Graph</tt> must be a model of
  <a href="./VertexListGraph.html">Vertex List Graph</a>
  and <a href="./BidirectionalGraph.html">Bidirectional Graph</a>.<br>
</blockquote>

IN: <tt>vertex_descriptor entry</tt>
<blockquote>
  The entry vertex. The dominator tree will be rooted at this vertex.
</blockquote>

IN: <tt>IndexMap indexMap</tt>
<blockquote>
  This maps each vertex to an integer in the range <tt>[0, num_vertices(g))</tt>.
  The type 
  <tt>VertexIndexMap</tt> must be a model of
  <a href="../../property_map/ReadablePropertyMap.html">Readable Property Map</a>. The value type of the map must be an
  integer type. The vertex descriptor type of the graph needs to be
  usable as the key type of the map.
</blockquote>

IN/OUT: <tt>TimeMap dfnumMap</tt>
<blockquote>
  The sequence number of depth first search. The type <tt>TimeMap</tt> must be a model of <a href="../../property_map/ReadWritePropertyMap.html">Read/Write Property Map</a>. The vertex descriptor type of the graph needs to be usable as the key type of the <tt>TimeMap</tt>.
</blockquote>

IN/OUT: <tt>PredMap parentMap</tt>
<blockquote>
  The predecessor map records the parent of the depth first search tree. The <tt>PredMap</tt> type must be a <a href="../../property_map/ReadWritePropertyMap.html">Read/Write Property Map</a> whose key and value types are the same as the vertex descriptor type of the graph.
</blockquote>

IN/OUT: <tt>VertexVector verticesByDFNum</tt>
<blockquote>
  The vector containing vertices in depth first search order. If we access this vector sequentially, it's equivalent to access vertices by depth first search order.
</blockquote>

OUT: <tt>DomTreePredMap domTreePredMap</tt>
<blockquote>
  The dominator tree where parents are each children's immediate dominator.
</blockquote>

<H3>Complexity</H3>

<P>
The time complexity is <i>O((V+E)log(V+E))</i>.

<H3>Example</H3>

<P>
See <a href="../test/dominator_tree_test.cpp">
<TT>test/dominator_tree_test.cpp</TT></a> for an example of using Dijkstra's
algorithm.

<br>
<HR>
<TABLE>
<TR valign="top">
<TD>Copyright &copy; 2005</TD><TD>
JongSoo Park, Stanford University
</TD></TR></TABLE>

</BODY>
</HTML>