reverse_cuthill_mckee_ordering#
- reverse_cuthill_mckee_ordering(G, heuristic=None)[source]#
生成图节点的排序(排列),以创建稀疏矩阵。
使用逆 Cuthill-McKee 启发式算法(基于广度优先搜索)[1]。
- 参数:
- G图
一个 NetworkX 图
- heuristic函数, 可选
选择 RCM 算法起始节点的函数。如果为 None,则使用伪外围对中的一个节点。可以提供一个用户定义的函数,该函数接受一个图对象并返回一个单个节点。
- 返回:
- nodes生成器
按照逆 Cuthill-McKee 顺序排列的节点生成器。
注意
带宽缩减的最优解是 NP 完全问题 [2]。
参考文献
[1]E. Cuthill and J. McKee. Reducing the bandwidth of sparse symmetric matrices, In Proc. 24th Nat. Conf. ACM, pages 157-72, 1969. http://doi.acm.org/10.1145/800195.805928
[2]Steven S. Skiena. 1997. The Algorithm Design Manual. Springer-Verlag New York, Inc., New York, NY, USA.
示例
>>> from networkx.utils import reverse_cuthill_mckee_ordering >>> G = nx.path_graph(4) >>> rcm = list(reverse_cuthill_mckee_ordering(G)) >>> A = nx.adjacency_matrix(G, nodelist=rcm)
度数最小的节点作为启发式函数
>>> def smallest_degree(G): ... return min(G, key=G.degree) >>> rcm = list(reverse_cuthill_mckee_ordering(G, heuristic=smallest_degree))