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