3 @brief Graph coloring algorithm: DSATUR 4 @details Implementation based on paper @cite article::gcolor::dsatur::1. 6 @authors Andrei Novikov (pyclustering@yandex.ru) 8 @copyright GNU Public License 10 @cond GNU_PUBLIC_LICENSE 11 PyClustering is free software: you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by 13 the Free Software Foundation, either version 3 of the License, or 14 (at your option) any later version. 16 PyClustering is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License for more details. 21 You should have received a copy of the GNU General Public License 22 along with this program. If not, see <http://www.gnu.org/licenses/>. 29 @brief Represents DSATUR algorithm for graph coloring problem that uses greedy strategy. 35 @brief Constructor of DSATUR algorithm. 37 @param[in] data (list): Matrix graph representation. 40 if (len(data[0]) != len(data)):
41 raise NameError(
'Only matrix graph representation is available.');
49 @brief Perform graph coloring using DSATUR algorithm. 62 index_maximum_degree = 0;
66 degrees.append( ( sum(self.
__data_pointer[index_node]), index_node ) );
69 if (degrees[index_node][0] > maximum_degree):
70 (maximum_degree, node_index) = degrees[index_node];
71 index_maximum_degree = index_node;
75 for index_neighbor
in neighbors:
76 saturation_degrees[index_neighbor] += 1;
79 self.
__coloring[index_maximum_degree] = color_counter;
80 uncolored_vertices.remove(index_maximum_degree);
82 while(len(uncolored_vertices) > 0):
84 maximum_satur_degree = -1;
85 for index
in uncolored_vertices:
86 if (saturation_degrees[index] > maximum_satur_degree):
87 maximum_satur_degree = saturation_degrees[index];
90 indexes_maximum_satur_degree = [index
for index
in uncolored_vertices
if saturation_degrees[index] == maximum_satur_degree];
92 coloring_index = indexes_maximum_satur_degree[0];
93 if (len(indexes_maximum_satur_degree) > 1):
96 for index
in indexes_maximum_satur_degree:
97 (degree, node_index) = degrees[index];
98 if (degree > maximum_degree):
99 coloring_index = node_index;
100 maximum_degree = degree;
104 for number_color
in range(1, color_counter + 1, 1):
106 self.
__coloring[coloring_index] = number_color;
112 self.
__coloring[coloring_index] = color_counter;
115 uncolored_vertices.remove(coloring_index);
119 for index_neighbor
in node_index_neighbors:
123 saturation_degrees[index_neighbor] += 1;
127 @brief Returns results of graph coloring. 129 @return (list) list with assigned colors where each element corresponds 130 to node in the graph, for example [1, 2, 2, 1, 3, 4, 1]. 138 def __get_amount_color(self, node_indexes, color_number):
140 @brief Countes how many nodes has color 'color_number'. 142 @param[in] node_indexes (list): Indexes of graph nodes for checking. 143 @param[in] color_number (uint): Number of color that is searched in nodes. 145 @return (uint) Number found nodes with the specified color 'color_number'. 150 for index
in node_indexes:
154 return color_counter;
157 def __get_neighbors(self, node_index):
159 @brief Returns indexes of neighbors of the specified node. 161 @param[in] node_index (uint): 163 @return (list) Neighbors of the specified node. def __init__(self, data)
Constructor of DSATUR algorithm.
def process(self)
Perform graph coloring using DSATUR algorithm.
def get_colors(self)
Returns results of graph coloring.
def __get_amount_color(self, node_indexes, color_number)
Countes how many nodes has color 'color_number'.
def __get_neighbors(self, node_index)
Returns indexes of neighbors of the specified node.
Represents DSATUR algorithm for graph coloring problem that uses greedy strategy. ...