Exemple #1
0
        private int FindMinCutKargerSteinRecursive(UnionFind graph, int verticesCount)
        {
            int vertexLimit;
            var random = new Random(++_seed);

            if (verticesCount <= 6)
            {
                vertexLimit = 2;

                ContractGraph(random, graph, verticesCount, vertexLimit);

                return(CountCuts(graph));
            }

            vertexLimit = (int)Math.Ceiling(1 + verticesCount / Math.Sqrt(2));

            var graph1 = UtilityMethods.CopyUnionFind(graph);
            var graph2 = UtilityMethods.CopyUnionFind(graph);

            ContractGraph(new Random(++_seed), graph1, verticesCount, vertexLimit);
            ContractGraph(new Random(++_seed), graph2, verticesCount, vertexLimit);

            var firstMinCut  = FindMinCutKargerSteinRecursive(graph1, vertexLimit);
            var secondMinCut = FindMinCutKargerSteinRecursive(graph2, vertexLimit);

            return(secondMinCut < firstMinCut ? secondMinCut : firstMinCut);
        }