rustworkx.generators.directed_hexagonal_lattice_graph#

directed_hexagonal_lattice_graph(rows, cols, bidirectional=False, multigraph=True, periodic=False, with_positions=False)#

生成一个有向六边形格子图。

bidirectionalFalse时,边缘会向右和向下传播

Parameters:
  • rows (int) – 生成图使用的行数。

  • cols (int) – 用于生成图形的列数。

  • bidirectional (bool) – 表示节点之间的边是否应当存在于双方向的参数。默认为 False

  • multigraph (bool) – 当设为 False 时,输出的 PyDiGraph 对象将不是多重图,并且 不允许添加平行边。相反, 会创建平行边的调用将更新现有边。

  • periodic (bool) – 当设置为 True 时,晶格的边界将会连接形成一个周期性网格。要求 cols 为偶数,rows > 1,并且 cols > 1

  • with_positions (bool) – 当设置为 True 时,每个节点将被分配 一对坐标 (x, y) 作为载荷。这种设置将节点嵌入平面中,使得每个六边形都成为正六边形(边长均为1)。

Returns:

生成的有向六边形格子图

Return type:

PyDiGraph

Raises:

TypeError – If either rows or cols are not specified

import rustworkx.generators
from rustworkx.visualization import mpl_draw

graph = rustworkx.generators.directed_hexagonal_lattice_graph(2, 3)
mpl_draw(graph)
../_images/rustworkx.generators.directed_hexagonal_lattice_graph_0_0.png