graphscope.nx.generators.classic.circulant_graph

graphscope.nx.generators.classic.circulant_graph(n, offsets, create_using=None)[源代码]

返回具有$n$个节点的循环图$Ci_n(x_1, x_2, …, x_m)$。

循环图 $Ci_n(x_1, …, x_m)$ 由 $n$ 个节点 $0, …, n-1$ 组成, 其中节点 $i$ 与所有 $(i + x) mod n$ 和 $(i - x) mod n$ 的节点相连, $x$ 取自 $x_1, …, x_m$。因此 $Ci_n(1)$ 是一个环形图。

Parameters:
  • n (整数) – 图中的节点数量。

  • offsets (list of integers) – 如上所述的节点偏移量列表,从$x_1$到$x_m$。

  • create_using (NetworkX 图构造函数可选 (默认=nx.Graph)) - 要创建的图类型。如果是图实例,则在填充前会被清空。

Return type:

类型为 create_using 的 NetworkX 图

示例

许多著名的图族都是循环图的子类;例如,要创建一个包含n个点的环状图,我们会将每个节点连接到两侧的节点(偏移量为正负一)。当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个点的完整图:

>>> 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