I'm using JGraphT, and I'm using EdmondsKarpMFImpl.
The question is: How to define the whole set of edges what is 'participate' in min-cut.
I tried to use the getCutEdges
method, but it only returns 1 edge.
I have the following graph:
(all the edges has a weight value(1) and a residual capacity value(10))
public SimpleDirectedWeightedGraph generateAbilene(){
Supplier<Integer> vSupplier3 = new Supplier<Integer>() {
private int id = 1;
@Override
public Integer get() {
return id++;
}
};
SimpleDirectedWeightedGraph exGraph3 =
new SimpleDirectedWeightedGraph<Integer, MyDefaultWeightedEdge>(vSupplier3, MyUtil.createDefaultWeightedEdgeSupplier());
exGraph3.addVertex(1);
exGraph3.addVertex(2);
exGraph3.addVertex(3);
exGraph3.addVertex(4);
exGraph3.addVertex(5);
exGraph3.addVertex(6);
exGraph3.addVertex(7);
exGraph3.addVertex(8);
exGraph3.addVertex(9);
exGraph3.addVertex(10);
exGraph3.addVertex(11);
exGraph3.addEdge(1,2);
exGraph3.addEdge(1,7);
exGraph3.addEdge(2,3);
exGraph3.addEdge(3,4);
exGraph3.addEdge(4,5);
exGraph3.addEdge(6,7);
exGraph3.addEdge(10,7);
exGraph3.addEdge(7,8);
exGraph3.addEdge(8,5);
exGraph3.addEdge(8,9);
exGraph3.addEdge(8,11);
return exGraph3;
}
And with that method I only get the first 2 edge(1-2 & 1-7) between the Source node (1) and the Sink node (5)
I want to retrieve all the edges in the min cut. For example in the case above it should return: 1-2, 1-7, 2-3, 7-8, 3-4, 8-5, 4-5 (about the order of the edges I do not care)
The Graph looks like this:
I think you are misinterpreting the definition of a minimum cut. A (weighted) min cut is a partitioning of the vertices in two disjoint subsets (say S and T) such that the sum of the weights of edges crossing the partition is minimum. In your case, you are specifically asking for a minimum s-t cut, which is a specific case of a minimum cut: in the minimum s-t cut, you require that the source vertex (s) is a member of S, and the sink vertex t is a member of T. Observe that the more general problem of finding a minimum cut in the graph could yield a solution where both vertices s and t are in the same partition.
Looking at your graph, a minimum s-t cut with s=1 and t=5, would be: S={1,2,6,7,10} and T={3,4,5,8,9,11}. The total weight of the edges ((2,3),(7,8)) crossing these partitions is 2, so this cut has value 2. Similarly, you can identify other s-t cuts in this graph with the same value.
Now the maximum flow min cut theorem tells us the relation between a cut and a flow. If we were to compute a max s-t flow in your graph, with s=1 and t=5, the max flow min cut theorem tells us that we cannot send more than 2 units of flow from s to t. An example of a max flow in this graph: we send 1 unit of flow on the path 1-7-8-5 and 1 unit on the path 1-2-3-4-5 resulting in a total flow of 2.
So what you seem to be looking for, is not a solution to the min cut problem, but a solution to the max flow problem. In particular, you want to compute which edges in the max flow problem have a positive flow value. Naturally, you can use JGraphT to get these results. Here's a cleaned-up version of your example:
The output of the above code: