Generate an ordering (permutation) of the graph nodes to make a sparse matrix.
Uses the Cuthill-McKee heuristic (based on breadth-first search) 1.
G (graph) – A NetworkX graph
heuristic (function, optional) – Function to choose starting node for RCM algorithm. If None a node from a pseudo-peripheral pair is used. A user-defined function can be supplied that takes a graph object and returns a single node.
nodes – Generator of nodes in Cuthill-McKee ordering.
- Return type
>>> 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))
The optimal solution the the bandwidth reduction is NP-complete 2.