is_bipartite.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html>
  3. <!--
  4. Authors: Matthias Walter
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt)
  8. -->
  9. <head>
  10. <title>Boost Graph Library: is_bipartite</title>
  11. </head>
  12. <body>
  13. <IMG SRC="../../../boost.png"
  14. ALT="C++ Boost" width="277" height="86">
  15. <h1>
  16. <tt>is_bipartite</tt>
  17. </h1>
  18. <pre>
  19. <i>// Version with a colormap to retrieve the bipartition</i>
  20. template &lt;typename Graph, typename IndexMap, typename PartitionMap&gt;
  21. bool is_bipartite (const Graph&amp; graph, const IndexMap index_map, PartitionMap partition_map)
  22. template &lt;typename Graph, typename IndexMap&gt;
  23. bool is_bipartite (const Graph&amp; graph, const IndexMap index_map)
  24. <i>// Version which uses the internal index map</i>
  25. template &lt;typename Graph&gt;
  26. bool is_bipartite (const Graph&amp; graph);
  27. </pre>
  28. <p>
  29. The <tt>is_bipartite()</tt> functions tests a given graph for
  30. bipartiteness using a DFS-based coloring approach.
  31. </p>
  32. <p>
  33. An undirected graph is bipartite if one can partition its set of vertices
  34. into two sets "left" and "right", such that each edge goes from either side
  35. to the other. Obviously, a two-coloring of the graph is exactly the same as
  36. a two-partition. <tt>is_bipartite()</tt> tests whether such a two-coloring
  37. is possible and can return it in a given property map.
  38. </p>
  39. <p>
  40. The bipartition is recorded in the color map <tt>partition_map</tt>,
  41. which will contain a two-coloring of the graph, i.e. an assignment of
  42. <i>black</i> and <i>white</i> to the vertices such that no edge is monochromatic.
  43. The predicate whether the graph is bipartite is the return value of the function.
  44. </p>
  45. <h3>Where Defined</h3>
  46. <p>
  47. <a href="../../../boost/graph/bipartite.hpp"><tt>boost/graph/bipartite.hpp</tt></a>
  48. </p>
  49. <h3>Parameters</h3>
  50. <p>
  51. IN: <tt>const Graph&amp; graph</tt>
  52. </p>
  53. <blockquote><p>
  54. An undirected graph. The graph type must be a model of <a
  55. href="VertexListGraph.html">Vertex List Graph</a> and <a
  56. href="IncidenceGraph.html">Incidence Graph</a>.<br/>
  57. </p></blockquote>
  58. <p>
  59. IN: <tt>const IndexMap index_map</tt>
  60. </p>
  61. <blockquote><p>
  62. This maps each vertex to an integer in the range <tt>[0,
  63. num_vertices(graph))</tt>. The type <tt>VertexIndexMap</tt>
  64. must be a model of <a
  65. href="../../property_map/doc/ReadablePropertyMap.html">Readable Property
  66. Map</a>. The value type of the map must be an integer type. The
  67. vertex descriptor type of the graph needs to be usable as the key
  68. type of the map.<br/>
  69. </p></blockquote>
  70. <p>
  71. OUT: <tt>PartitionMap partition_map</tt>
  72. </p>
  73. <blockquote><p>
  74. The algorithm tests whether the graph is bipartite and assigns each
  75. vertex either a white or a black color, according to the partition.
  76. The <tt>PartitionMap</tt> type must be a model of
  77. <a href="../../property_map/doc/ReadablePropertyMap.html">Readable Property
  78. Map</a> and
  79. <a href="../../property_map/doc/WritablePropertyMap.html">Writable Property
  80. Map</a> The value type must model <a href="./ColorValue.html">ColorValue</a>.
  81. </p></blockquote>
  82. <h3>Complexity</h3>
  83. <p>
  84. The time complexity for the algorithm is <i>O(V + E)</i>.
  85. </p>
  86. <h3>See Also</h3>
  87. <p>
  88. <a href="./find_odd_cycle.html"><tt>find_odd_cycle()</tt></a>
  89. </p>
  90. <h3>Example</h3>
  91. <p>
  92. The file <a href="../example/bipartite_example.cpp"><tt>examples/bipartite.cpp</tt></a>
  93. contains an example of testing an undirected graph for bipartiteness.
  94. <br/>
  95. </p>
  96. <hr/>
  97. <p>
  98. Copyright &copy; 2010 Matthias Walter
  99. (<a class="external" href="mailto:xammy@xammy.homelinux.net">xammy@xammy.homelinux.net</a>)
  100. </p>
  101. </body>
  102. </html>