# `cuthill_mckee_ordering`

Graphs: | undirected
Properties: | color, degree
Complexity: | time: O(log(m)|E|) where m = max { degree(v) | v in V }

      (1)
      template <class IncidenceGraph, class OutputIterator,
                class ColorMap, class DegreeMap>
      void
      cuthill_mckee_ordering(IncidenceGraph& g,
                             typename graph_traits<Graph>::vertex_descriptor s,
                             OutputIterator inverse_permutation,
                             ColorMap color, DegreeMap degree)

      (2)
      template <class VertexListGraph, class OutputIterator,
                class ColorMap, class DegreeMap>
      void
      cuthill_mckee_ordering(VertexListGraph& G, OutputIterator inverse_permutation,
                             ColorMap color, DegreeMap degree)

The goal of the Cuthill-Mckee (and reverse Cuthill-Mckee) ordering algorithm[14, 43, 44, 45 ] is to reduce the bandwidth of a graph by reordering the indices assigned to each vertex. The Cuthill-Mckee ordering algorithm works by a local minimization of the i-th bandwidths. The vertices are basically assigned a breadth-first search order, except that at each step, the adjacent vertices are placed in the queue in order of increasing degree.

Version 1 of the algorithm lets the user choose the ``starting vertex'' whereas version 2 finds a good starting vertex using the pseudo-peripheral pair heuristic. The choice of the ``starting vertex'' can have a significant effect on the quality of the ordering.

The output of the algorithm are the vertices in the new ordering. Depending on what kind of output iterator you use, you can get either the Cuthill-Mckee ordering or the reverse Cuthill-McKee ordering. For example, if you store the output into a vector using the vector's reverse iterator, then you get the reverse Cuthill-McKee ordering.

      std::vector<vertex_descriptor> inv_perm(num_vertices(G));
      cuthill_mckee_ordering(G, inv_perm.rbegin());

Either way, storing the output into a vector gives you the permutation from the new ordering to the old ordering.

      inv_perm[new_index[u]] == old_index[u]

Often times, it is the opposite permutation that you want, the permutation from the old index to the new index. This can easily be computed in the following way.

      for (size_type i = 0; i != inv_perm.size(); ++i)
        perm[inv_perm[i]] = i;

### Parameters

For version 1:

- `IncidenceGraph& g` (IN)
  An undirected graph. The graph's type must be a model of IncidenceGraph.
- `vertex_descriptor s` (IN)
  The starting vertex.
- `OutputIterator inverse_permutation` (OUT)
  The new vertex ordering. The vertices are written to the output iterator in their new order.
- `ColorMap color_map` (WORK)
  Used internally to keep track of the progress of the algorithm (to avoid visiting the same vertex twice).
- `DegreeMap degree_map` (IN)
  This must map vertices to their degree.

For version 2:

- `VertexListGraph& g` (IN)
  An undirected graph. The graph's type must be a model of VertexListGraph.
- `OutputIterator inverse_permutation` (OUT)
  The new vertex ordering. The vertices are written to the output iterator in their new order.
- `ColorMap color_map` (WORK)
  Used internally to keep track of the progress of the algorithm (to avoid visiting the same vertex twice).
- `DegreeMap degree_map` (IN)
  This must map vertices to their degree.

### Example

See `example/cuthill_mckee_ordering.cpp`.

### See Also

bandwidth, and `degree_property_map` in `boost/graph/properties.hpp`.

Copyright © 2000 | Jeremy Siek, Univ.of Notre Dame (jsiek@lsc.nd.edu)