cuthill_mckee_ordering#
- cuthill_mckee_ordering(G, heuristic=None)[源]#
生成图节点的排序(排列),以生成稀疏矩阵。
使用 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-172, 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 cuthill_mckee_ordering >>> G = nx.path_graph(4) >>> rcm = list(cuthill_mckee_ordering(G)) >>> A = nx.adjacency_matrix(G, nodelist=rcm)
将最小度节点作为启发式函数
>>> def smallest_degree(G): ... return min(G, key=G.degree) >>> rcm = list(cuthill_mckee_ordering(G, heuristic=smallest_degree))