circulant_graph#
- circulant_graph(n, offsets, create_using=None)[源代码]#
返回具有 \(n\) 个节点的 circulant 图 \(Ci_n(x_1, x_2, ..., x_m)\)。
circulant 图 \(Ci_n(x_1, ..., x_m)\) 由 \(n\) 个节点 \(0, ..., n-1\) 组成,其中节点 \(i\) 连接到对于所有 \(x\) 属于 \(x_1, ..., x_m\) 的节点 \((i + x) \mod n\) 和 \((i - x) \mod n\)。因此 \(Ci_n(1)\) 是一个 cycle 图。
- 参数:
- n整数
图中的节点数。
- offsets整数列表
节点偏移量列表,如上所述,从 \(x_1\) 到 \(x_m\)。
- create_usingNetworkX 图构造函数,可选(默认=nx.Graph)
要创建的图类型。如果是图实例,则在填充前会清除。
- 返回:
- create_using 类型的 NetworkX 图
示例
许多著名的图族是 circulant 图的子族;例如,要创建 n 个节点的 cycle 图,我们将每个节点连接到两侧的节点(偏移量为正负一)。对于 n = 10,
>>> G = nx.circulant_graph(10, [1]) >>> edges = [ ... (0, 9), ... (0, 1), ... (1, 2), ... (2, 3), ... (3, 4), ... (4, 5), ... (5, 6), ... (6, 7), ... (7, 8), ... (8, 9), ... ] >>> sorted(edges) == sorted(G.edges()) True
类似地,我们可以使用偏移量集合 [1, 2] 创建包含 5 个节点的 complete 图
>>> G = nx.circulant_graph(5, [1, 2]) >>> edges = [ ... (0, 1), ... (0, 2), ... (0, 3), ... (0, 4), ... (1, 2), ... (1, 3), ... (1, 4), ... (2, 3), ... (2, 4), ... (3, 4), ... ] >>> sorted(edges) == sorted(G.edges()) True