rustworkx.graph_union#

graph_union(first, second, /, merge_nodes=False, merge_edges=False)#

通过对两个输入PyGraph对象进行并集操作返回一个新的PyGraph

这个函数中的算法分为三个阶段运行:

  1. second 中的所有节点添加到 first 中。操作的时间复杂度为 \(\mathcal{O}(n_2)\),其中 \(n_2\)second 中的节点数量。

  2. second 中的节点合并到 first 上,条件如下:

    • merge_nodes 设置为 True 时,时间复杂度为 \(\mathcal{O}(n_1 n_2)\), 其中 \(n_1\) 表示 first 中节点的数量,\(n_2\) 表示 second 中节点的数量

    • secondfirst 中的相应节点共享相同的权重/数据载荷。

  3. second中的所有边添加到first中。如果merge_edges参数为True,并且secondfirst中的相应边共享相同的权重/数据负载,它们将被合并在一起。

Parameters:
  • first (PyGraph) – 第一个无向图对象

  • second (PyGraph) – 第二个无向图对象

  • merge_nodes (bool) – 如果设置为 True,当权重相等时,secondfirst 之间的节点将被合并。默认值:False

  • merge_edges (bool) – 如果设置为 True,会在 secondfirst 之间合并权重相等的边。默认值:False

Returns:

一个新的PyGraph对象,它是secondfirst的并集。值得注意的是,权重/数据负载对象是 由firstsecond通过引用传递给该新对象的。

Return type:

PyGraph