简体   繁体   中英

Undirected, weighted graph partitioning

I need to partition a graph in such a way that node X and node Y are no longer connected. 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. 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.

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 .

Here is example Python code to compute the value for your graph using the Networkx library :

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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