Smallest Last Ordering
Produces a vertex ordering by repeatedly removing the vertex with the smallest
degree. This ordering is a good heuristic for graph coloring: using it with
sequential_vertex_coloring often produces near-optimal results.
Complexity: O(V + E)
Defined in: <boost/graph/smallest_last_ordering.hpp>
Example
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/smallest_last_ordering.hpp>
#include <boost/property_map/shared_array_property_map.hpp>
#include <iostream>
#include <vector>
using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS>;
using Vertex = boost::graph_traits<Graph>::vertex_descriptor;
int main() {
Graph g(5);
boost::add_edge(0, 1, g);
boost::add_edge(0, 2, g);
boost::add_edge(1, 2, g);
boost::add_edge(2, 3, g);
boost::add_edge(3, 4, g);
auto order = boost::smallest_last_vertex_ordering(g);
std::cout << "Smallest-last ordering:\n";
for (std::size_t i = 0; i < order.size(); ++i) {
std::cout << " position " << i << ": vertex " << order[i] << "\n";
}
}
Smallest-last ordering:
position 0: vertex 0
position 1: vertex 1
position 2: vertex 2
position 3: vertex 3
position 4: vertex 4
(1) With full work-map set
template <typename VertexListGraph, typename Order,
typename Degree, typename Marker>
void smallest_last_vertex_ordering(const VertexListGraph& g,
Order order, Degree degree,
Marker marker);
Allocates a bucket_sorter keyed on degree and delegates to overload (2).
(2) With explicit bucket sorter
template <typename VertexListGraph, typename Order,
typename Degree, typename Marker, typename BucketSorter>
void smallest_last_vertex_ordering(const VertexListGraph& g,
Order order, Degree degree,
Marker marker,
BucketSorter& degree_buckets);
Useful if you want to reuse a pre-allocated bucket_sorter across multiple runs.
Parameters
| Direction | Parameter | Description |
|---|---|---|
IN |
|
Must model Vertex List Graph and Incidence Graph with an internal |
OUT |
|
WritablePropertyMap from position (integer) to vertex descriptor — |
UTIL |
|
ReadWritePropertyMap from vertex to current (remaining) degree. |
UTIL |
|
ReadWritePropertyMap from vertex to marker value; used to track removed vertices. |
UTIL |
|
A |
Combine with sequential_vertex_coloring for a simple but effective
graph coloring pipeline.
|