rustworkx.generators.directed_binomial_tree_graph#

directed_binomial_tree_graph(order, weights=None, bidirectional=False, multigraph=True)#

递归生成一个阶数为n的有向二项树。

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

Parameters:
  • order (int) – Order of the binomial tree. The maximum allowed value for order on the platform your running on. If it’s a 64bit platform, the max value is 60 and on 32bit systems the max value is 29. Any order value above these will raise an OverflowError.

  • weights (Sequence[Any]) – 一个节点权重序列,通常是一个列表。 如果权重数量小于 2**order,将会添加值为 None 的额外节点。

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

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

Returns:

一个有向二项树,包含2^n个顶点和2^n - 1条边

Return type:

PyDiGraph

Raises:
  • IndexError – If the length of weights is greater that 2^n

  • OverflowError – If the input order exceeds the maximum value for the current platform

import rustworkx.generators
from rustworkx.visualization import mpl_draw

graph = rustworkx.generators.directed_binomial_tree_graph(4)
mpl_draw(graph)
../_images/rustworkx.generators.directed_binomial_tree_graph_0_0.png