2
0
mirror of https://github.com/boostorg/graph.git synced 2026-02-03 09:12:14 +00:00

This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.

[SVN r36372]
This commit is contained in:
nobody
2006-12-14 02:08:05 +00:00
parent d83d611b18
commit 46ae2cb6c1
2 changed files with 320 additions and 0 deletions

187
doc/lengauer_tarjan_dominator.htm Executable file
View File

@@ -0,0 +1,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>

View File

@@ -0,0 +1,133 @@
<HTML>
<!--
-- Copyright (c) 2004, 2005 The Trustees of Indiana University
--
-- Use, modification and distribution is subject to the Boost Software
-- License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-- http://www.boost.org/LICENSE_1_0.txt)
--
-- Authors: Jeremiah Willcock
-- Douglas Gregor
-- Andrew Lumsdaine
-->
<Head>
<Title>Boost Graph Library: Erd&ouml;s-Renyi Generator</Title>
<script language="JavaScript" type="text/JavaScript">
<!--
function address(host, user) {
var atchar = '@';
var thingy = user+atchar+host;
thingy = '<a hre' + 'f=' + "mai" + "lto:" + thingy + '>' + user+atchar+host + '</a>';
document.write(thingy);
}
//-->
</script>
</head>
<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
ALINK="#ff0000">
<IMG SRC="../../../boost.png"
ALT="C++ Boost" width="277" height="86">
<tt>sorted_erdos_renyi_iterator</tt>
<br>
<PRE>
template&lt;typename RandomGenerator, typename Graph&gt;
class sorted_erdos_renyi_iterator
{
public:
typedef std::input_iterator_tag iterator_category;
typedef std::pair&lt;vertices_size_type, vertices_size_type&gt; value_type;
typedef const value_type&amp; reference;
typedef const value_type* pointer;
typedef void difference_type;
sorted_erdos_renyi_iterator();
sorted_erdos_renyi_iterator(RandomGenerator&amp; gen, vertices_size_type n,
double probability = 0.0, bool allow_self_loops = false);
// Iterator operations
reference operator*() const;
pointer operator-&gt;() const;
sorted_erdos_renyi_iterator&amp; operator++();
sorted_erdos_renyi_iterator operator++(int);
bool operator==(const sorted_erdos_renyi_iterator&amp; other) const;
bool operator!=(const sorted_erdos_renyi_iterator&amp; other) const;
};
</PRE>
<p> This class template implements a generator for Erd&ouml;s-Renyi
graphs, suitable for initializing an <a
href="adjacency_list.html"><tt>adjacency_list</tt></a> or other graph
structure with iterator-based initialization. An Erd&ouml;s-Renyi
graph <em>G = (n, p)</em> is a graph with <em>n</em> vertices
that. The probability of having an edge <em>(u, v)</em> in <em>G</em>
is <em>p</em> for any vertices <em>u</em> and <em>v</em>. Typically,
there are no self-loops, but the generator can optionally introduce
self-loops with probability <em>p</em>.</p>
<p>Erd&ouml;s-Renyi graphs typically exhibit very little
structure. For this reason, they are rarely useful in modeling
real-world problems. However, they are often used when determining
the theoretical complexity of complex graph algorithms.</p>
<h3>Where Defined</h3>
<a href="../../../boost/graph/erdos_renyi_generator.hpp"><tt>boost/graph/erdos_renyi_generator.hpp</tt></a>
<h3>Constructors</h3>
<a name="default-constructor"/>
<pre>sorted_erdos_renyi_iterator();</pre>
<blockquote>
Constructs a past-the-end iterator.
</blockquote>
<pre>
sorted_erdos_renyi_iterator(RandomGenerator&amp; gen, vertices_size_type n,
double probability = 0.0, bool allow_self_loops = false);
</pre>
<blockquote>
Constructs an Erd&ouml;s-Renyi generator iterator that creates a
graph with <tt>n</tt> vertices and a given <tt>probability</tt> of the
total number of edges that a simple graph may have.
<tt>probability</tt>. Random vertices and edges are selected using the
random number generator <tt>gen</tt>. Self-loops are permitted only when
<tt>allow_self_loops</tt> is <tt>true</tt>.
</blockquote>
<H3>Example</H3>
<pre>
#include &lt;boost/graph/adjacency_list.hpp&gt;
#include &lt;boost/graph/erdos_renyi_generator.hpp&gt;
#include &lt;boost/random/linear_congruential.hpp&gt;
typedef boost::adjacency_list&lt;&gt; Graph;
typedef boost::sorted_erdos_renyi_iterator&lt;boost::minstd_rand, Graph&gt; ERGen;
int main()
{
boost::minstd_rand gen;
// Create graph with 100 nodes and edges with probability 0.05
Graph g(ERGen(gen, 100, 0.05), ERGen(), 100);
return 0;
}
</pre>
<br>
<HR>
<TABLE>
<TR valign=top>
<TD nowrap>Copyright &copy 2005</TD><TD>
Jeremiah Willcock, Indiana University (<script language="Javascript">address("cs.indiana.edu", "jewillco")</script>)<br>
<A HREF="../../../people/doug_gregor.html">Doug Gregor</A>, Indiana University (<script language="Javascript">address("cs.indiana.edu", "dgregor")</script>)<br>
<A HREF=http://www.osl.iu.edu/~lums>Andrew Lumsdaine</A>,
Indiana University (<script language="Javascript">address("osl.iu.edu", "lums")</script>)
</TD></TR></TABLE>
</BODY>
</HTML>