简体   繁体   English

无向加权图分区

[英]Undirected, weighted graph partitioning

I need to partition a graph in such a way that node X and node Y are no longer connected. 我需要以不再连接节点X和节点Y的方式对图进行分区。 Additionally, the sum of the weights of the removed edges must be the lowest one possible. 此外,已去除边缘的权重之和必须尽可能低。

For example: 例如:

    3       1       2
X ----- Z ----- W ----- Y

Should become: 应该变成:

    3               2
X ----- Z       W ----- Y

I first thought that I could use a loop to calculate the shortest path between X and Y and remove the cheapest edge, until there are no more paths. 我首先想到我可以使用循环来计算X和Y之间的最短路径并删除最便宜的边,直到没有更多路径为止。 However, after thinking about it I realized that this approach doesn't work in all cases. 但是,经过深思熟虑,我意识到这种方法并非在所有情况下都有效。

Searching in Wikipedia brought me to the Kernighan–Lin and Fiduccia-Mattheyses algorithms, but it looks like they are meant to solve other partitioning problems. 在Wikipedia中进行搜索使我进入了Kernighan-Lin和Fiduccia-Mattheyses算法,但看起来它们旨在解决其他分区问题。

Is there a standard algorithm to solve this problem? 是否有解决此问题的标准算法?

What you are looking for is called the minimum cut of a graph. 您正在寻找的被称为图形的最小割。

By the Max-flow_min-cut_theorem the value of the minimum cut is equal the the value of the maximum flow. 通过最大流量最小定理 ,最小流量值等于最大流量值。

Computing the maximum flow in a network is a standard problem and there are several algorithms for computing this depending on the nature of your graph. 计算网络中的最大流量是一个标准问题,根据图形的性质,有几种算法可以计算该流量。

A good tutorial is here on topcoder . 在topcoder上有一个很好的教程。

Here is example Python code to compute the value for your graph using the Networkx library : 这是使用Networkx库计算图形值的示例Python代码:

import networkx as nx
G = nx.Graph()
G.add_edge('x','z', capacity = 3)
G.add_edge('z','w', capacity = 1)
G.add_edge('w','y', capacity = 2)
print nx.minimum_cut_value(G, 'x', 'y')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM