two_graphs_common_spanning_trees.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <html>
  2. <!--
  3. Copyright (C) 2012, Michele Caini.
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. Two Graphs Common Spanning Trees Algorithm
  8. Based on academic article of Minty, Read and Tarjan
  9. Efficient Algorithm for Common Spanning Tree Problem
  10. Electron. Lett., 28 April 1983, Volume 19, Issue 9, p.346–347
  11. -->
  12. <head>
  13. <title>Boost Graph Library: Two-Graphs Common Spanning Trees</title>
  14. <body bgcolo="#ffffff" link="#0000ee" text="#000000" vlink="#551a8b" alink="#ff0000">
  15. <img src="../../../boost.png" alt="C++ Boost" width="277" height="86">
  16. <br clear>
  17. <h1><tt><a name="sec:two-graphs-common-spanning-trees">Two-Graphs Common Spanning Trees (MRT Algorithm)</a></tt></h1>
  18. <p>
  19. The <b>MRT</b> algorithm, based on an academic article of <b>Minty</b>, <b>Read</b> and
  20. <b>Tarjan</b>, is an efficient algorithm for the common spanning tree problem.<br/>
  21. This kind of algorithm is widely used in electronics, being the basis of the
  22. analysis of electrical circuits. Another area of interest may be that of the
  23. networking.
  24. </p>
  25. <p>
  26. The proposed algorithm receives several arguments and works with callbacks.<br/>
  27. The prototypes are:
  28. </p>
  29. <p>
  30. <i>// Ordered Edges List</i>
  31. <pre>
  32. template &lt; typename Graph, typename Order, typename Func, typename Seq &gt;
  33. void two_graphs_common_spanning_trees
  34. (
  35. const Graph&amp; iG,
  36. Order iG_map,
  37. const Graph&amp; vG,
  38. Order vG_map,
  39. Func func,
  40. Seq inL
  41. )
  42. </pre>
  43. <i>// Unordered Edges List</i>
  44. <pre>
  45. template &lt; typename Graph, typename Func, typename Seq &gt;
  46. void two_graphs_common_spanning_trees
  47. (
  48. const Graph&amp; iG,
  49. const Graph&amp; vG,
  50. Func func,
  51. Seq inL
  52. )
  53. </pre>
  54. </p>
  55. <p>
  56. The problem of common spanning tree is easily described.<br/>
  57. Imagine we have two graphs that are represented as lists of edges. A common
  58. spanning tree is a set of indices that identifies a spanning tree for both
  59. the first and for the second of the two graphs. Despite it is easily accomplished
  60. with edge list representation for graphs, it is intuitively difficult to achieve
  61. with adjacency list representation. This is due to the fact that it is necessary
  62. to represent an edge with an absolute index.
  63. </p>
  64. <p>
  65. Note that the set of common spanning trees of the two graphs is a subset of
  66. the set of spanning trees of the first graph, as well as those of the second
  67. graph.
  68. </p>
  69. <h3>Where Defined</h3>
  70. <p>
  71. <a href="../../../boost/graph/two_graphs_common_spanning_trees.hpp"><TT>boost/graph/two_graphs_common_spanning_trees.hpp</TT></a>
  72. <h3>Parameters</h3>
  73. <tt>const Graph& iG, const Graph& vG</tt>
  74. <blockquote>
  75. These are the graphs to be analyzed.<br/>
  76. They must comply with the concepts VertexAndEdgeListGraphConcept and IncidenceGraphConcept.<br/>
  77. In addition, the directed_category should be of type undirected_tag.
  78. </blockquote>
  79. <tt>Order iG_map, Order vG_map</tt>
  80. <blockquote>
  81. These are lists of references to edges, that define the preferred order for access to the lists of edges.<br/>
  82. They must comply with the concept RandomAccessContainer.
  83. </blockquote>
  84. <tt>Func func</tt>
  85. <blockquote>
  86. This is a callback that is invoked by the algorithm for each common spanning tree found.<br/>
  87. It must comply with the concept UnaryFunction with void as return value, and an object of type <i>typeof(inL)</i> as argument.
  88. </blockquote>
  89. <tt>Seq inL<a href="#1">[1]</a></tt>
  90. <blockquote>
  91. This is the way in which the edges are marked as belonging to the common spanning tree.<br/>
  92. It must comply with the concept Mutable_RandomAccessContainer. In addition, the value_type should be of type bool.
  93. If the i-th edge or <i>inL[i]</i> is true, then it belongs to the common spanning tree, otherwise it does not belong.
  94. </blockquote>
  95. <h3>Example</h3>
  96. <p>
  97. The file
  98. <a href="../example/two_graphs_common_spanning_trees.cpp"><tt>examples/two_graphs_common_spanning_trees.cpp</tt></a>
  99. contains an example of finding common spanning trees of two undirected graphs.
  100. </p>
  101. <h3>Notes</h3>
  102. <p>
  103. <a name="1">[1]</a><br/>
  104. The presence of <i>inL</i> may seem senseless. The algorithm can use a vector of
  105. placeholders internally generated. However, doing so has more flexibility on
  106. the callback function. Moreover, being largely involved in the electronics
  107. world, there are cases where some edges have to be forced in every tree (ie
  108. you want to search all the trees that have the same root): With this
  109. solution, the problem is easily solved.<br/>
  110. Intuitively from the above, <i>inL</i> must be of a size equal to <i>(V-1)</i>, where
  111. <i>V</i> is the number of vertices of the graph.
  112. </p>
  113. <br/>
  114. <hr>
  115. <table>
  116. <tr valign=top>
  117. <td nowrap>Copyright &copy; 2012</td>
  118. <td>Michele Caini, (<a href="mailto:michele.caini@gmail.com">michele.caini@gmail.com</a>)</td>
  119. </tr>
  120. </table>
  121. </body>
  122. </html>