49 #ifndef DSATUR2_COLORING_HPP 50 #define DSATUR2_COLORING_HPP 52 #include <boost/config.hpp> 53 #include <boost/graph/properties.hpp> 54 #include <boost/version.hpp> 55 #if BOOST_VERSION >= 104000 56 #include <boost/property_map/property_map.hpp> 58 #include <boost/property_map.hpp> 60 #include <boost/graph/adjacency_list.hpp> 61 #include <boost/graph/graph_traits.hpp> 62 #include <boost/graph/visitors.hpp> 63 #include <boost/limits.hpp> 64 #include <boost/tuple/tuple.hpp> 65 #if BOOST_VERSION >= 106400 66 #include <boost/serialization/array_wrapper.hpp> 69 #include <boost/numeric/ublas/matrix.hpp> 97 template <
typename size_type>
107 const std::vector<size_type>& _DegreeCount)
119 template <
typename VertexListGraph,
typename ColorMap,
typename size_type>
124 using Vertex =
typename GraphTraits::vertex_descriptor;
127 typename boost::numeric::ublas::matrix<bool>
ColorAdj;
130 const VertexListGraph&
G;
137 : num_node(_num_node),
138 valid(_num_node,
true),
139 ColorAdj(_num_node, _num_node),
140 ColorCount(_num_node, 0),
141 DegreeCount(_num_node),
144 HCF(ColorCount, DegreeCount)
146 unsigned int i, iheap = 0;
147 heap_container =
new size_type[_num_node];
148 for(i = 0; i < num_node; i++)
151 DegreeCount[i] = out_degree(v, _G);
152 heap_container[iheap] = i;
155 boost::numeric::ublas::noalias(ColorAdj) = boost::numeric::ublas::zero_matrix<bool>(_num_node, _num_node);
159 delete[] heap_container;
168 typename GraphTraits::adjacency_iterator v, vend;
169 for(boost::tie(v, vend) = adjacent_vertices(
boost::vertex(node, G), G); v != vend; ++v)
171 node1 =
get(vertex_index, G, *v);
172 if(!ColorAdj(node1, color))
176 ColorAdj(node1, color) =
true;
177 DegreeCount[node1]--;
185 size_type max_color = 0;
187 for(size_type i = 0; i < num_node; i++)
190 std::make_heap(heap_container + i, heap_container + num_node, HCF);
191 v = heap_container[i];
194 for(j = 0; j <= max_color; j++)
209 AssignColor(v, max_color);
211 return max_color + 1;
218 template <
typename VertexListGraph,
typename ColorMap>
219 typename property_traits<ColorMap>::value_type
dsatur2_coloring(
const VertexListGraph& G, ColorMap color)
221 using size_type =
typename property_traits<ColorMap>::value_type;
223 const size_type num_node = num_vertices(G);
void AssignColor(size_type node, size_type color)
const std::vector< size_type > & ColorCount
helper used to color the graph.
boost::numeric::ublas::matrix< bool > ColorAdj
This algorithm is to find coloring of a graph Algorithm: Let G = (V,E) be a graph with vertices v_1...
property_traits< ColorMap >::value_type dsatur2_coloring(const VertexListGraph &G, ColorMap color)
coloring of a graph following the DSATUR heuristic (version2)
~dsatur2_coloring_helper()
std::vector< size_type > DegreeCount
dsatur2_heap_compare_functor(const std::vector< size_type > &_ColorCount, const std::vector< size_type > &_DegreeCount)
typename GraphTraits::vertex_descriptor Vertex
dsatur2_heap_compare_functor< size_type > HCF
graph_traits< VertexListGraph > GraphTraits
const VertexListGraph & G
size_type * heap_container
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
dsatur2_coloring_helper(const VertexListGraph &_G, ColorMap &_CM, const size_type _num_node)
std::vector< bool > valid
bool operator()(size_type i1, size_type i2) const
const std::vector< size_type > & DegreeCount
std::vector< size_type > ColorCount