46 #ifndef DEGREE_COLORING_HPP 47 #define DEGREE_COLORING_HPP 49 #include <boost/config.hpp> 50 #include <boost/graph/properties.hpp> 51 #include <boost/version.hpp> 52 #if BOOST_VERSION >= 104000 53 #include <boost/property_map/property_map.hpp> 55 #include <boost/property_map.hpp> 59 #include <boost/graph/graph_traits.hpp> 60 #include <boost/graph/visitors.hpp> 61 #include <boost/limits.hpp> 62 #include <boost/tuple/tuple.hpp> 81 template <
typename VertexListGraph>
85 template <
typename Vertex>
88 return out_degree(v1,
G) < out_degree(v2,
G);
95 const VertexListGraph&
G;
101 template <
class VertexListGraph,
class ColorMap>
102 typename property_traits<ColorMap>::value_type
degree_coloring(
const VertexListGraph&
G, ColorMap color)
104 using GraphTraits = graph_traits<VertexListGraph>;
105 using Vertex =
typename GraphTraits::vertex_descriptor;
106 using size_type =
typename property_traits<ColorMap>::value_type;
108 size_type max_color = 0;
109 const size_type V = num_vertices(G);
122 unsigned iheap = 0, heapsize;
124 typename GraphTraits::vertex_iterator v, vend;
125 for(boost::tie(v, vend) = vertices(G); v != vend; ++v)
127 put(color, *v, V - 1);
131 Vertex* heap_container;
132 heap_container =
new size_type[iheap];
133 for(boost::tie(v, vend) = vertices(G); v != vend; ++v)
136 heap_container[iheap] = *v;
139 std::make_heap(heap_container, heap_container + heapsize, HCF);
142 for(size_type i = 0; i < heapsize; ++i)
144 Vertex current = heap_container[0];
145 std::pop_heap(heap_container, heap_container + heapsize - i, HCF);
146 typename GraphTraits::adjacency_iterator v1, v1end;
150 for(boost::tie(v1, v1end) = adjacent_vertices(current, G); v1 != v1end; ++v1)
152 mark[
get(color, *v1)] = i;
163 while(j < max_color && mark[j] == i)
174 put(color, current, j);
176 delete[] heap_container;
bool operator()(Vertex v1, Vertex v2) const
This algorithm is to find coloring of a graph Algorithm: Let G = (V,E) be a graph with vertices v_1...
redefinition of set to manage ordered/unordered structures
degree_compare_functor(const VertexListGraph &_G)
const VertexListGraph & G
property_traits< ColorMap >::value_type degree_coloring(const VertexListGraph &G, ColorMap color)
coloring of a graph following the descandant degree of vertices