rustworkx.generators.mesh_graph#
- mesh_graph(num_nodes=None, weights=None, multigraph=True)#
Generate an undirected mesh (complete) graph where every node is connected to every other.
- Parameters:
num_nodes (int) – 生成图时所使用的节点数量。如果指定了此参数,节点权重将为 None。如果同时设置了
num_nodes和weights,此参数将被忽略并采用weights。权重 (序列[任意类型]) – 节点权重的序列,通常为一个列表。 如果同时设置了
num_nodes和weights,此参数将被忽略,将使用权重。multigraph (bool) – 当设置为
False时,输出PyGraph对象将不会是多图,且 不允许添加平行边。相反, 本会创建平行边的操作将更新现有边。
- Returns:
生成的网格图
- Return type:
- Raises:
索引错误 – 如果既未指定
num_nodes也未指定weights
import rustworkx.generators from rustworkx.visualization import mpl_draw graph = rustworkx.generators.mesh_graph(4) mpl_draw(graph)