networkx.utils.rcm.cuthill_mckee_ordering¶

cuthill_mckee_ordering
(G, heuristic=None)[source]¶ Generate an ordering (permutation) of the graph nodes to make a sparse matrix.
Uses the CuthillMcKee heuristic (based on breadthfirst search) 1.
 Parameters
G (graph) – A NetworkX graph
heuristic (function, optional) – Function to choose starting node for RCM algorithm. If None a node from a pseudoperipheral pair is used. A userdefined function can be supplied that takes a graph object and returns a single node.
 Returns
nodes – Generator of nodes in CuthillMcKee ordering.
 Return type
generator
Examples
>>> from networkx.utils import cuthill_mckee_ordering >>> G = nx.path_graph(4) >>> rcm = list(cuthill_mckee_ordering(G)) >>> A = nx.adjacency_matrix(G, nodelist=rcm)
Smallest degree node as heuristic function:
>>> def smallest_degree(G): ... return min(G, key=G.degree) >>> rcm = list(cuthill_mckee_ordering(G, heuristic=smallest_degree))
See also
Notes
The optimal solution the the bandwidth reduction is NPcomplete 2.
References
 1
E. Cuthill and J. McKee. Reducing the bandwidth of sparse symmetric matrices, In Proc. 24th Nat. Conf. ACM, pages 157172, 1969. http://doi.acm.org/10.1145/800195.805928
 2
Steven S. Skiena. 1997. The Algorithm Design Manual. SpringerVerlag New York, Inc., New York, NY, USA.