local_edge_connectivity#

local_edge_connectivity(G, s, t, flow_func=None, auxiliary=None, residual=None, cutoff=None)[源代码]#

返回节点s和t在g中的本地边缘连接。

两个节点s和t的本地边缘连接是断开连接时必须删除的最小边缘数。

这是基于流的边缘连接实施。我们在从原始网络构建的辅助有向图上计算最大流量(详情见下文)。这等于局部边连通性,因为最大s-t流的值等于最小s-t割的容量(Ford和Fulkerson定理)。 [1]

参数
G网络X图表

无向图或有向图

s结点

源节点

t结点

目标节点

flow_func功能

一种函数,用于计算一对节点之间的最大流。该函数必须接受至少三个参数:有向图、源节点和目标节点。并返回遵循NetworkX约定的剩余网络(请参见 maximum_flow() 有关详细信息,请参见)。如果FLOW_FUNC为NONE,则默认的最大流量函数 (edmonds_karp() )被使用。详情见下文。默认功能的选择可能因版本不同而有所不同,不应依赖。默认值:无。

auxiliary网络X有向图

用于计算基于流的边连通性的辅助有向图。如果提供,它将被重复使用,而不是重新创建。默认值:无。

residual网络X有向图

计算最大流量的残差网络。如果提供,它将被重复使用,而不是重新创建。默认值:无。

cutoff整数、浮点数

如果指定,当流量值达到或超过分界值时,最大流量算法将终止。这仅适用于支持截止参数的算法: edmonds_karp()shortest_augmenting_path() 。其他算法将忽略此参数。默认值:无。

返回
K整数

节点s和t的局部边缘连通性。

参见

edge_connectivity()
local_node_connectivity()
node_connectivity()
maximum_flow()
edmonds_karp()
preflow_push()
shortest_augmenting_path()

笔记

这是边缘连接的基于流的实现。默认情况下,我们使用 edmonds_karp() 从原始输入图生成辅助有向图的算法:

如果输入图是无向的,我们将替换每条边 (uv),带有两个倒数弧 (uv )和 (vu ),然后我们将每个圆弧的属性‘Capacity’设置为1。如果输入图是定向的,我们只需添加‘Capacity’属性。这是中算法1的实现 [1].

辅助网络中的最大流量等于局部边缘连接,因为最大S-T流量的值等于最小S-T-Cut的容量(Ford和Fulkerson定理)。

工具书类

1(1,2)

Abdol Hossein Esfahanian。连接算法。http://www.cse.msu.edu/~cse835/papers/graph_connectivity_revised.pdf

实例

此函数未导入到基本NetworkX命名空间中,因此必须从连接包中显式导入:

>>> from networkx.algorithms.connectivity import local_edge_connectivity

我们在这个例子中使用柏拉图二十面体图,它具有边连通性5。

>>> G = nx.icosahedral_graph()
>>> local_edge_connectivity(G, 0, 6)
5

如果需要在同一个图中的多对节点上计算本地连接,建议重用NetworkX在计算中使用的数据结构:用于边缘连接的辅助有向图,以及用于底层最大流量计算的剩余网络。

如何利用数据结构计算柏拉图二十面体图中所有节点对之间的局部边连通性的例子。

>>> import itertools
>>> # You also have to explicitly import the function for
>>> # building the auxiliary digraph from the connectivity package
>>> from networkx.algorithms.connectivity import build_auxiliary_edge_connectivity
>>> H = build_auxiliary_edge_connectivity(G)
>>> # And the function for building the residual network from the
>>> # flow package
>>> from networkx.algorithms.flow import build_residual_network
>>> # Note that the auxiliary digraph has an edge attribute named capacity
>>> R = build_residual_network(H, "capacity")
>>> result = dict.fromkeys(G, dict())
>>> # Reuse the auxiliary digraph and the residual network by passing them
>>> # as parameters
>>> for u, v in itertools.combinations(G, 2):
...     k = local_edge_connectivity(G, u, v, auxiliary=H, residual=R)
...     result[u][v] = k
>>> all(result[u][v] == 5 for u, v in itertools.combinations(G, 2))
True

您还可以使用其他流算法来计算边缘连接。例如,在稠密网络中,算法 shortest_augmenting_path() 通常会比默认性能更好 edmonds_karp() 对于高度倾斜度分布的稀疏网络,这一点更快。必须从流包显式导入可选流函数。

>>> from networkx.algorithms.flow import shortest_augmenting_path
>>> local_edge_connectivity(G, 0, 6, flow_func=shortest_augmenting_path)
5