sequential_vertex_coloring.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <!--
  4. Copyright (c) 2005 Trustees of Indiana University
  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: Sequential Vertex Coloring</title>
  11. </head>
  12. <body>
  13. <IMG SRC="../../../boost.png"
  14. ALT="C++ Boost" width="277" height="86">
  15. <h1><img src="figs/python.gif" alt="(Python)"/><tt>sequential_vertex_coloring</tt></h1>
  16. <p>
  17. <pre>
  18. template&lt;class VertexListGraph, class OrderPA, class ColorMap&gt;
  19. typename property_traits&lt;ColorMap&gt;::value_type
  20. sequential_vertex_coloring(const VertexListGraph&amp; g, OrderPA order,
  21. ColorMap color);
  22. template&lt;class VertexListGraph, class ColorMap&gt;
  23. typename property_traits&lt;ColorMap&gt;::value_type
  24. sequential_vertex_coloring(const VertexListGraph&amp; g, ColorMap color);
  25. </pre>
  26. <p>Computes a <a href="graph_coloring.html">vertex coloring</a> for
  27. the vertices in the graph, using a simple algorithm [<a
  28. href="bibliography.html#coleman83">59</a>]. Given vertices
  29. ordered v<sub>1</sub>, v<sub>2</sub>, ... , v<sub>n</sub>, for k = 1,
  30. 2, ..., n the algorithm assigns v<sub>k</sub> to the smallest possible
  31. color. The algorithm does not guarantee an optimum coloring.
  32. <p>Here is the coloring that would be produced on a graph given the
  33. vertex ordering A, B, C, D, E.
  34. <p><img src="figs/sequential_vertex_coloring.png">,
  35. <h3>Where Defined</h3>
  36. <a href="../../../boost/graph/sequential_vertex_coloring.hpp"><tt>boost/graph/sequential_vertex_coloring.hpp</tt></a>
  37. <h3>Parameters</h3>
  38. IN: <tt>const Graph&amp; g</tt>
  39. <blockquote>
  40. The graph object on which the algorithm will be applied. The type
  41. <tt>Graph</tt> must be a model of <a
  42. href="VertexListGraph.html">Vertex List Graph</a> and <a
  43. href="AdjacencyGraph.html">Adjacency Graph</a>.<br>
  44. <b>Python</b>: The parameter is named <tt>graph</tt>.
  45. </blockquote>
  46. OUT: <tt>ColorMap color</tt>
  47. <blockquote>
  48. This property map records the colors of each vertex. It must be a
  49. model of
  50. <a href="../../property_map/doc/WritablePropertyMap.html">Writeable
  51. Property Map</a> whose key type is the same as the vertex descriptor
  52. type of the graph and whose value type is an integral type that can
  53. store all values of the graph's <tt>vertices_size_type</tt>.<br>
  54. <b>Python</b>: Must be an <tt>vertex_int_map</tt> for the graph.
  55. </blockquote>
  56. IN: <tt>OrderPA order</tt>
  57. <blockquote>
  58. A mapping from integers in the range <em>[0, num_vertices(g))</em>
  59. to the vertices of the graph.<br>
  60. <b>Default:</b> A property map ordering the vertices in the same way
  61. they are ordered by <tt>vertices(g)</tt>.<br>
  62. <b>Python</b>: Unsupported parameter.
  63. </blockquote>
  64. <h3>Complexity</h3>
  65. The time complexity is <em>O(V(d+k))</em>, where <em>V</em> is the
  66. number of vertices, <em>d</em> is the maximum degree of the vertices
  67. in the graph, and <em>k</em> is the number of colors used.
  68. <h3>Example</h3>
  69. <pre>
  70. typedef adjacency_list&lt;listS, vecS, undirectedS&gt; Graph;
  71. typedef graph_traits&lt;Graph&gt;::vertex_descriptor vertex_descriptor;
  72. typedef graph_traits&lt;Graph&gt;::vertices_size_type vertices_size_type;
  73. typedef property_map&lt;Graph, vertex_index_t&gt;::const_type vertex_index_map;
  74. typedef std::pair&lt;int, int&gt; Edge;
  75. enum nodes {A, B, C, D, E, n};
  76. Edge edge_array[] = { Edge(A, C), Edge(B, B), Edge(B, D), Edge(B, E),
  77. Edge(C, B), Edge(C, D), Edge(D, E), Edge(E, A),
  78. Edge(E, B) };
  79. int m = sizeof(edge_array) / sizeof(Edge);
  80. Graph g(edge_array, edge_array + m, n);
  81. <em>// Test with the normal order</em>
  82. std::vector&lt;vertices_size_type&gt; color_vec(num_vertices(g));
  83. iterator_property_map&lt;vertices_size_type*, vertex_index_map&gt;
  84. color(&amp;color_vec.front(), get(vertex_index, g));
  85. <b>vertices_size_type num_colors = sequential_vertex_coloring(g, color);</b>
  86. </pre>
  87. <hr>
  88. <TABLE>
  89. <TR valign=top>
  90. <TD nowrap>Copyright &copy; 1997-2004</TD><TD>
  91. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  92. Indiana University (<A
  93. HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)<br>
  94. <A HREF="http://www.boost.org/people/doug_gregor.html">Douglas Gregor</A>, Indiana University (dgregor -at- cs.indiana.edu)</A>)
  95. </TD></TR></TABLE>
  96. </body>
  97. </html>