最大双向匹配方法出错

时间:2016-01-24 16:27:36

标签: algorithm graph bipartite max-flow

给出了具有源和接收器的二分图,如下所示。每个边缘的容量为1个单位: Source : GeeksforGeeks

我正试图找到从源到汇的最大流量。一种方法是使用Ford-Fulkerson算法求解最大流问题,该算法适用于所有图。 我找到了一种简单的方法来找到最大流量(太简单而不正确!)并且我无法在方法中发现任何错误。

方法:

c1 =在具有传出边的顶点列表中计算具有非零边数的顶点数。

c2 =在具有入边的顶点列表中计算具有非零边数的顶点数量。

最大流量是这两个数字的最小值,即min(c1,c2)。[由于任何路径都需要一个顶点来自输出顶点列表,另一个需要来自输入顶点列表。]

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

考虑像

这样的图表
*--*
  /
 /
*  *
  /
 /
*--*

(通过连接组件工作的补丁不能解决问题;将左下角连接到右上角。)

答案 1 :(得分:0)

Don't have an exact answer, but I have an iterative algorithm that works. To me you clearly need to equilibrate the flow, so that it is distributed among the left vertices that can send it to the right vertices that can receive it. Suppose you model your situation with a matrix A containing the bipartite links. You can then assume that if your matrix contains exactly the amount of flow (between 0 and 1) you want to pass in an edge, then the total flow given this decision is b=A*a where a is a vector of ones. If you start with the maximum capacity for A, putting all the edges at one and all the others at 0, you might have some elements of b with more than 1, but you can reduce their corresponding elements of A so they pass less flow. Then you can revert the flow and see what is the maximum reception capacity of your bipartite part, and test it with a=A'b. Again you might have elements of a that are more than 1 meaning that an ideal flow would be greater than the possible capacity from source to the element, and reduce these elements in the flow of A. With this ping-pong algorithm and reducing the corrections progressively, you are guaranteed to converge on the optimal matrix. Given a final b=Aa with a vector of ones, your maximal flow will be sum(b). See the octave code below, I use B as the converging matrix, and let me know your comments.

A=[0 1 0 1;1 0 0 1;1 1 0 0;0 0 1 0];
B=A;
repeat
  b=B*ones(4,1);
  B=B.*([.8 .8 .8 1]'*ones(1,4));
  a=B'*ones(4,1)
  B=B.*(ones(4,1)*[.9 .9 1 .9]);
until converge
maxflow=sum(b)