public List <MinCutEdge <T> > ComputeMinCut(WeightedDiGraph <T, W> graph, T source, T sink) { var edmondsKarpMaxFlow = new EdmondKarpMaxFlow <T, W>(operators); var maxFlowResidualGraph = edmondsKarpMaxFlow .computeMaxFlowAndReturnResidualGraph(graph, source, sink); //according to Min Max theory //the Min Cut can be obtained by Finding edges //from Reachable Vertices from Source //to unreachable vertices in residual graph var reachableVertices = getReachable(maxFlowResidualGraph, source); var result = new List <MinCutEdge <T> >(); foreach (var vertex in reachableVertices) { foreach (var edge in graph.Vertices[vertex].OutEdges) { //if unreachable if (!reachableVertices.Contains(edge.Key.Value)) { result.Add(new MinCutEdge <T>(vertex, edge.Key.Value)); } } } return(result); }
public List <MinCutEdge <T> > ComputeMinCut(IDiGraph <T> graph, T source, T sink) { if (this.@operator == null) { throw new ArgumentException("Provide an operator implementation for generic type W during initialization."); } if (!graph.IsWeightedGraph) { if ([email protected]() != typeof(int)) { throw new ArgumentException("Edges of unweighted graphs are assigned an imaginary weight of one (1)." + "Provide an appropriate IFlowOperators<int> operator implementation during initialization."); } } var edmondsKarpMaxFlow = new EdmondKarpMaxFlow <T, W>(@operator); var maxFlowResidualGraph = edmondsKarpMaxFlow .computeMaxFlowAndReturnResidualGraph(graph, source, sink); //according to Min Max theory //the Min Cut can be obtained by Finding edges //from Reachable Vertices from Source //to unreachable vertices in residual graph var reachableVertices = getReachable(maxFlowResidualGraph, source); var result = new List <MinCutEdge <T> >(); foreach (var vertex in reachableVertices) { foreach (var edge in graph.GetVertex(vertex).OutEdges) { //if unreachable if (!reachableVertices.Contains(edge.TargetVertexKey)) { result.Add(new MinCutEdge <T>(vertex, edge.TargetVertexKey)); } } } return(result); }