howard_cycle_ratio.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
  5. <TITLE>Boost Graph Library: Maximum (Minimum) cycle ratio</TITLE>
  6. <META NAME="CREATED" CONTENT="20061218;17562954">
  7. <META NAME="CHANGEDBY" CONTENT="Dmitry Bufistov">
  8. <META NAME="CHANGED" CONTENT="20070128;20552300">
  9. <!-- Copyright 2007 Technical University of Catalonia
  10. Use, modification and distribution is subject to the Boost Software
  11. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. http://www.boost.org/LICENSE_1_0.txt)
  13. Authors: Dmitry Bufistov
  14. Andrey Parfenov
  15. -->
  16. <!--
  17. <STYLE>
  18. @page { size: 3.5cm 2.5cm }
  19. TD P { color: #000000 }
  20. H1 { color: #000000 }
  21. P { color: #000000 }
  22. PRE { color: #000000 }
  23. H3 { color: #000000 }
  24. BLOCKQUOTE { color: #000000 }
  25. A:link { color: #0000ee }
  26. A:visited { color: #551a8b }
  27. </STYLE>
  28. -->
  29. </HEAD>
  30. <BODY TEXT="#000000" LINK="#0000ee" VLINK="#551a8b" BGCOLOR="#ffffff" DIR="LTR">
  31. <P><IMG SRC="../../..//boost.png" NAME="graphics1" ALT="C++ Boost" ALIGN=BOTTOM WIDTH=277 HEIGHT=86 BORDER=0>
  32. </P>
  33. <H1><TT>[maximum|minimum]_cycle_ratio</TT></H1>
  34. <P>
  35. <PRE>
  36. template &lt;typename Graph, typename VertexIndexMap,
  37. typename EdgeWeight1, typename EdgeWeight2&gt;
  38. dobule
  39. maximum_cycle_ratio(const Graph &amp;g, VertexIndexMap vim,
  40. EdgeWeight1 ewm, EdgeWeight2 ew2m,
  41. std::vector&lt;typename boost::graph_traits&lt;Graph&gt;::edge_descriptor&gt; *pcc = 0);
  42. template &lt;typename FloatTraits, Graph, typename VertexIndexMap,
  43. typename EdgeWeight1, typename EdgeWeight2&gt;
  44. typename FloatTraits::float_type
  45. maximum_cycle_ratio(const Graph &amp;g, VertexIndexMap vim,
  46. EdgeWeight1 ewm, EdgeWeight2 ew2m,
  47. std::vector&lt;typename boost::graph_traits&lt;Graph&gt;::edge_descriptor&gt; *pcc = 0,
  48. FloatTraits = FloatTraits());
  49. template &lt;typename Graph, typename VertexIndexMap,
  50. typename EdgeWeight1, typename EdgeWeight2&gt;
  51. dobule
  52. minimum_cycle_ratio(const Graph &amp;g, VertexIndexMap vim,
  53. EdgeWeight1 ewm, EdgeWeight2 ew2m,
  54. std::vector&lt;typename boost::graph_traits&lt;Graph&gt;::edge_descriptor&gt; *pcc = 0);
  55. template &lt;typename FloatTraits, typename <A HREF="http://boost.org/libs/graph/doc/Graph.html">Graph</A>, typename VertexIndexMap,
  56. typename EdgeWeight1, typename EdgeWeight2&gt;
  57. typename FloatTraits::float_type
  58. minimum_cycle_ratio(const Graph &amp;g, VertexIndexMap vim,
  59. EdgeWeight1 ewm, EdgeWeight2 ew2m,
  60. std::vector&lt;typename boost::graph_traits&lt;Graph&gt;::edge_descriptor&gt; *pcc = 0,
  61. FloatTraits = FloatTraits());
  62. </PRE>
  63. </P>
  64. The <tt>maximum_cycle_ratio()</tt> function calculates the maximum cycle ratio of a
  65. weighted directed multigraph <I>G=(V,E,W1,W2)</I>, where <i>V</i> is a vertex set,
  66. <i>E</i> is an edge set, W1 and W2 are edge weight functions, W2 is nonnegative.
  67. As a multigraph, <i>G</i> can have multiple edges connecting a pair of vertices.
  68. </P>
  69. <P>Let every edge <I>e</I> has two weights <I>W1(e)</I> and <I>W2(e)</I>.
  70. Let <I>c</I> be a cycle of the graph<I>g</I>. Then, the <i>cycle ratio</i>, <I>cr(c)</I>, is defined as:</P>
  71. <P>
  72. <IMG SRC="figs/cr.jpg" ALT="Cycle ratio definition" BORDER=0>
  73. </P>
  74. The <I>maximum (minimum) cycle ratio</I> (mcr) is the maximum (minimum) cycle ratio
  75. of all cycles of the graph. A cycle is called <I>critical</I> if its ratio is equal
  76. to the <I>mcr</I>. The calculated maximum cycle ratio will be the return value
  77. of the function. The <tt>maximum_cycle_ratio()/minimum_cycle_ratio()</tt> returns
  78. <tt>-FloatTraits::infinity()/FloatTraits::infinity()</tt> if graph has no cycles.
  79. If the <i>pcc</i> parameter is not zero then one critical cycle will be written
  80. to the corresponding <tt>std::vector</tt> of edge descriptors. The edges in the
  81. vector stored in the way such that <tt>*pcc[0], *ppc[1], ..., *ppc[n]</tt> is a
  82. correct path.
  83. </P>
  84. <P>
  85. The algorithm is due to Howard's iteration policy algorithm, descibed in
  86. <A HREF="./cochet-terrasson98numerical.pdf">[1]</A>.
  87. Ali Dasdan, Sandy S. Irani and Rajesh K.Gupta in their paper
  88. <A HREF="./dasdan-dac99.pdf">Efficient Algorithms for Optimum Cycle Mean and Optimum Cost to Time Ratio
  89. Problems</A> state that this is the most efficient algorithm to the time being (1999).</P>
  90. <p>
  91. For the convenience, functions <tt>maximum_cycle_mean()</tt> and <tt>minimum_cycle_mean()</tt>
  92. are also provided. They have the following signatures:
  93. <pre>
  94. template &lt;typename Graph, typename VertexIndexMap,
  95. typename EdgeWeightMap, typename EdgeIndexMap&gt;
  96. double
  97. maximum_cycle_mean(const Graph &amp;g, VertexIndexMap vim,
  98. EdgeWeightMap ewm, EdgeIndexMap eim,
  99. std::vector&lt;typename graph_traits&lt;Graph&gt;::edge_descriptor&gt; *pcc = 0);
  100. template &lt;typename FloatTraits, typename Graph, typename VertexIndexMap,
  101. typename EdgeWeightMap, typename EdgeIndexMap&gt;
  102. typename FloatTraits::float_type
  103. maximum_cycle_mean(const Graph &amp;g, VertexIndexMap vim,
  104. EdgeWeightMap ewm, EdgeIndexMap eim,
  105. std::vector&lt;typename graph_traits&lt;Graph&gt;::edge_descriptor&gt; *pcc = 0,
  106. FloatTraits = FloatTraits());
  107. template &lt;typename Graph, typename VertexIndexMap,
  108. typename EdgeWeightMap, typename EdgeIndexMap&gt;
  109. double
  110. minimum_cycle_mean(const Graph &amp;g, VertexIndexMap vim,
  111. EdgeWeightMap ewm, EdgeIndexMap eim,
  112. std::vector&lt;typename graph_traits&lt;Graph&gt;::edge_descriptor&gt; *pcc = 0);
  113. template &lt;typename FloatTraits, typename Graph, typename VertexIndexMap,
  114. typename EdgeWeightMap, typename EdgeIndexMap&gt;
  115. typename FloatTraits::float_type
  116. minimum_cycle_mean(const Graph &amp;g, VertexIndexMap vim,
  117. EdgeWeightMap ewm, EdgeIndexMap eim,
  118. std::vector&lt;typename graph_traits&lt;Graph&gt;::edge_descriptor&gt; *pcc = 0,
  119. FloatTraits = FloatTraits());
  120. </pre>
  121. </p>
  122. <H3>Where Defined</H3>
  123. <P STYLE="background: transparent"><TT><A HREF="../../../boost/graph/howard_cycle_ratio.hpp">boost/graph/howard_cycle_ratio.hpp</A></TT>
  124. </P>
  125. <H3>Parameters</H3>
  126. <P>IN: <tt>FloatTraits</tt> </P>
  127. <blockquote>
  128. The <tt>FloatTrats</tt> encapsulates customizable limits-like information for
  129. floating point types. This type <i>must</i> provide an associated type,
  130. <tt>value_type</tt> for the floating point type.
  131. The default value is <tt>boost::mcr_float&lt;&gt;</tt>which has the following
  132. definition:<br/>
  133. <pre>
  134. template &lt;typename Float = double&gt;
  135. struct mcr_float {
  136. typedef Float value_type;
  137. static Float infinity()
  138. { return (std::numeric_limits&lt;value_type&gt;::max)(); }
  139. static Float epsilon()
  140. { return Float(-0.005); }
  141. };
  142. </pre>
  143. The value <tt>FloatTraits::epsilon()</tt> controls the "tolerance" of the
  144. algorithm. By increasing the absolute value of epsilon you may slightly decrease
  145. the execution time but there is a risk to skip a global optima. By decreasing
  146. the absolute value you may fall to the infinite loop. The best option is to
  147. leave this parameter unchanged.
  148. </blockquote>
  149. <P>IN: <tt>const Graph&amp; g </tt>
  150. </P>
  151. <BLOCKQUOTE>A weighted directed multigraph.
  152. The graph's type must be a model of <A HREF="http://boost.org/libs/graph/doc/VertexListGraph.html">VertexListGraph</A>
  153. and <A HREF="http://boost.org/libs/graph/doc/IncidenceGraph.html">IncidenceGraph</A>
  154. </BLOCKQUOTE>
  155. <P>IN: <tt>VertexIndexMap vim</tt>
  156. </P>
  157. <BLOCKQUOTE>Maps each vertex of the graph to a unique integer in the
  158. range [0, num_vertices(g)).
  159. </BLOCKQUOTE>
  160. <P>IN: <tt>EdgeWeight1 ew1m</t>
  161. </P>
  162. <BLOCKQUOTE>
  163. The W1 edge weight function.
  164. </BLOCKQUOTE>
  165. <P>IN: <tt>EdgeWeight2 ew2m</tt>
  166. </P>
  167. <BLOCKQUOTE>
  168. The W2 edge weight function. Should be nonnegative. The actual limitation of the
  169. algorithm is the positivity of the total weight of each directed cycle of the graph.
  170. </BLOCKQUOTE>
  171. <P>
  172. OUT: <tt>std::vector&lt;typename boost::graph_traits&lt;Graph&gt;::edge_descriptor&gt;* pcc</tt>
  173. </P>
  174. <BLOCKQUOTE>
  175. If non zero then one critical cycle will be stored in the std::vector. Default
  176. value is 0.
  177. </BLOCKQUOTE>
  178. <P>
  179. IN (only for maximum/minimal_cycle_mean()): <tt>EdgeIndexMap eim</tt>
  180. </P>
  181. <BLOCKQUOTE>
  182. Maps each edge of the graph to a unique integer in the range [0, num_edges(g)).
  183. </BLOCKQUOTE>
  184. <BLOCKQUOTE STYLE="margin-left: 0cm">
  185. All property maps must be models of <A HREF="http://boost.org/libs/property_map/ReadablePropertyMap.html">Readable
  186. Property Map</A>
  187. </BLOCKQUOTE>
  188. <H3>Complexity</H3>
  189. <P>There is no known precise upper bound for the time complexity of the
  190. algorithm. Imperical time complexity is <I>O(|E|)</I>, where the constant tends to
  191. be pretty small (about 20-30). Space complexity is equal to <i>7*|V|</i> plus the
  192. space required to store a graph.
  193. </P>
  194. <H3>Example</H3>
  195. <P>The program in <A HREF="../example/cycle_ratio_example.cpp">libs/graph/example/cycle_ratio_example.cpp</A>
  196. generates a random graph and computes its maximum cycle ratio.
  197. </P>
  198. <HR>
  199. <TABLE CELLPADDING=2 CELLSPACING=2>
  200. <TR VALIGN=TOP>
  201. <TD>
  202. <P>Copyright &copy; 2006-2009</P>
  203. </TD>
  204. <TD>
  205. <P><A HREF="https://web.archive.org/web/20081122083634/http://www.lsi.upc.edu/~dmitry">Dmitry
  206. Bufistov</A>, Andrey Parfenov</P>
  207. </TD>
  208. </TR>
  209. </TABLE>
  210. <P><BR><BR>
  211. </P></HTML>