private static void Main(string[] args) { if (args.Count() == 1) { string filePath = args[0]; var vertices = new List<Vertex>(); using (var reader = new StreamReader(filePath)) { while (!reader.EndOfStream) { var verticeArray = reader.ReadLine().Split(new[] {' ', '\t'}, StringSplitOptions.RemoveEmptyEntries); vertices.Add(new Vertex(int.Parse(verticeArray[0]), verticeArray.Skip(1).Select(int.Parse).ToArray())); } } vertices.Sort(); var stopWatch = new Stopwatch(); //var repeatCount = (int)(Math.Pow(vertices.Count, 2)*Math.Log(vertices.Count, Math.E)); var repeatCount = (int)(Math.Pow(vertices.Count, 2)); stopWatch.Start(); var kargerAlg = new KargerMinCut(vertices.ToArray()); var minCut = Enumerable.Range(1, repeatCount) .Select(i => kargerAlg.CalculateMinCut()) .Min(); stopWatch.Stop(); Console.WriteLine("min cut={0}, repeatCount = {1}, running time = {2} ms", minCut, repeatCount, stopWatch.ElapsedMilliseconds); Console.WriteLine("press any key"); Console.ReadLine(); } }
public void FourVertices() { var vertices = new Vertex[] { new Vertex(1, new [] {2, 4, 3}), new Vertex(2, new [] {1, 3}), new Vertex(3, new [] {1, 2}), new Vertex(4, new [] {1}) }; var alg = new KargerMinCut(vertices); var minCut = Enumerable.Range(1, 32).Select(i => alg.CalculateMinCut()).Min(); Assert.AreEqual(1, minCut); }
public void EigthVertices() { var vertices = new Vertex[] { new Vertex(1, new [] {5, 2, 6}), new Vertex(2, new [] {1, 5, 6, 3}), new Vertex(3, new [] {2, 7, 4, 8}), new Vertex(4, new [] {3, 7, 8}), new Vertex(5, new [] {1, 2, 6}), new Vertex(6, new [] {1, 2, 5, 7}), new Vertex(7, new [] {6, 3, 4, 8}), new Vertex(8, new [] {3, 4, 7}), }; var alg = new KargerMinCut(vertices); var minCut = Enumerable.Range(1, 200).Select(i => alg.CalculateMinCut()).Min(); Assert.AreEqual(2, minCut); }