mirror of
https://github.com/boostorg/graph.git
synced 2026-01-28 19:22:11 +00:00
168 lines
5.0 KiB
HTML
168 lines
5.0 KiB
HTML
<HTML>
|
|
<!--
|
|
-- Copyright (c) Jeremy Siek 2000
|
|
--
|
|
-- 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: Strongly Connected Components</Title>
|
|
<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
|
|
ALINK="#ff0000">
|
|
<IMG SRC="../../../c++boost.gif"
|
|
ALT="C++ Boost" width="277" height="86">
|
|
|
|
<BR Clear>
|
|
|
|
|
|
<H1>
|
|
<A NAME="sec:connected-components"></A><A NAME="sec:strongly-connected-components"></A>
|
|
<TT>strong_components</TT>
|
|
</H1>
|
|
|
|
<P>
|
|
<DIV ALIGN="left">
|
|
<TABLE CELLPADDING=3 border>
|
|
<TR><TH ALIGN="LEFT"><B>Graphs:</B></TH>
|
|
<TD ALIGN="LEFT">see below</TD>
|
|
</TR>
|
|
<TR><TH ALIGN="LEFT"><B>Properties:</B></TH>
|
|
<TD ALIGN="LEFT">components, color, discover time, root vertex</TD>
|
|
</TR>
|
|
<TR><TH ALIGN="LEFT"><B>Complexity:</B></TH>
|
|
<TD ALIGN="LEFT"><i>O(V + E)</i></TD>
|
|
</TR>
|
|
</TABLE>
|
|
</DIV>
|
|
|
|
<P>
|
|
<PRE>
|
|
(1)
|
|
template <typename Graph, typename ComponentMap, typename RootMap,
|
|
typename ColorMap, typename DiscoverTime>
|
|
typename property_traits<ComponentMap>::value_type
|
|
strong_components(Graph& g,
|
|
ComponentMap comp,
|
|
RootMap root, ColorMap color, DiscoverTime d)
|
|
|
|
(2)
|
|
template <typename Graph, typename ComponentMap, typename RootMap,
|
|
typename ColorMap, typename DiscoverTime, typename DFSVisitor>
|
|
typename property_traits<ComponentMap>::value_type
|
|
strong_components(Graph& g,
|
|
ComponentMap comp,
|
|
RootMap root, ColorMap color, DiscoverTime discover_time,
|
|
DFSVisitor v)
|
|
</PRE>
|
|
|
|
<P>
|
|
The <TT>strong_components()</TT> functions compute the strongly
|
|
connected components of a directed graph using Tarjan's algorithm
|
|
based on DFS [<A
|
|
HREF="bibliography.html#tarjan72:dfs_and_linear_algo">41</A>].
|
|
|
|
<P>
|
|
The output of the algorithm is recorded in the component property
|
|
map <TT>comp</TT>, which will contain numbers giving the component ID
|
|
assigned to each vertex. The number of components is the return value
|
|
of the function.
|
|
|
|
<P>
|
|
The algorithm requires the use of several property maps: color,
|
|
discover time, and root vertex. There are two versions of this
|
|
algorithm to accommodate whether or not you wish to extend the
|
|
algorithm with a <a href="./DFSVisitor.html">DFSVisitor</a>.
|
|
|
|
<P>
|
|
|
|
<H3>Where Defined</H3>
|
|
|
|
<P>
|
|
<a href="../../../boost/graph/strong_components.hpp"><TT>boost/graph/strong_components.hpp</TT></a>
|
|
|
|
<P>
|
|
|
|
<H3>Definitions</H3>
|
|
|
|
<P>
|
|
A <b><I>strongly connected component</I></b> of a directed graph
|
|
<i>G=(V,E)</i> is a maximal set of vertices <i>U</i> which is in
|
|
<i>V</i> such that for every pair of vertices <i>u</i> and <i>v</i> in
|
|
<i>U</i>, we have both a path from <i>u</i> to <i>v</i> and path from
|
|
<i>v</i> to <i>u</i>. That is to say that <i>u</i> and <i>v</i> are
|
|
reachable from each other.
|
|
|
|
<P>
|
|
|
|
<H3>Requirements on Types</H3>
|
|
|
|
<P>
|
|
|
|
<UL>
|
|
<LI>The graph type must be a model of <a
|
|
href="./VertexListGraph.html">VertexListGraph</a>.
|
|
|
|
</LI>
|
|
<LI><TT>DiscoverTime</TT> must be a model of <a
|
|
href="../../property_map/WritablePropertyMap.html">
|
|
WritablePropertyMap</a> and their value type must be an integer
|
|
type. Vertex descriptors from the graph should be usable as the
|
|
key type for these maps.
|
|
</LI>
|
|
<LI>The <TT>ColorMap</TT> must be a <a
|
|
href="../../property_map/ReadWritePropertyMap.html">
|
|
ReadWritePropertyMap</a> and the graph's vertex descriptor type
|
|
should be usable as the map's key type. The value type of the map
|
|
must be a model of <I>ColorValue</I>.
|
|
</LI>
|
|
<LI>The <TT>RootMap</TT> must be a <a
|
|
href="../../property_map/ReadWritePropertyMap.html">
|
|
ReadWritePropertyMap</a>, where the key type and the value type
|
|
are the vertex descriptor type of the graph.
|
|
</LI>
|
|
<LI>The <TT>ComponentMap</TT> type must be a model of <a
|
|
href="../../property_map/ReadWritePropertyMap.html">
|
|
ReadWritePropertyMap</a>. The value type of the
|
|
<TT>ComponentMap</TT> property map should be an integer type,
|
|
preferably the same as the <TT>size_type</TT> of the graph. The
|
|
key type should be the graph's vertex descriptor type.
|
|
</LI>
|
|
</UL>
|
|
|
|
<P>
|
|
|
|
<H3>Complexity</H3>
|
|
|
|
<P>
|
|
The time complexity for the strongly connected components algorithm is
|
|
<i>O(V + E)</i>.
|
|
|
|
<P>
|
|
|
|
<h3>See Also</h3>
|
|
|
|
<a href="./connected_components.html"><tt>connected_components()</tt></a>
|
|
and <a href="./incremental_components.html"><tt>incremental_components()</tt></a>
|
|
|
|
<H3>Example</H3>
|
|
|
|
<P>
|
|
See <a
|
|
href="../example/strong_components.cpp"><tt>examples/strong_components.cpp</tt></a>.
|
|
|
|
<br>
|
|
<HR>
|
|
<TABLE>
|
|
<TR valign=top>
|
|
<TD nowrap>Copyright © 2000</TD><TD>
|
|
<A HREF="../../../people/jeremy_siek.htm">Jeremy Siek</A>, Univ.of Notre Dame (<A HREF="mailto:jsiek@lsc.nd.edu">jsiek@lsc.nd.edu</A>)
|
|
</TD></TR></TABLE>
|
|
|
|
</BODY>
|
|
</HTML>
|