public void FordFulkersonMethodTest01() { var data = new double[,] { {1, 2, 12, 2}, {1, 6, 6, 6}, {2, 3, 2, 2}, {3, 4, 1, 1}, {3, 5, 5, 2}, {5, 4, 15, 7}, {5, 7, 2, 0}, {6, 2, 10, 0}, {6, 5, 5, 5}, {6, 7, 8, 1}, {7, 2, 2, 0}, {7, 3, 6, 1} }; Dictionary<Edge<int>, double> expectedResult; var graph = GraphHelper.CreateGraph(data, out expectedResult); var startVertex = graph.GetVertex(0); var endVertex = graph.GetVertex(3); var ffm = new FordFulkersonMethod(graph, startVertex, endVertex); var actualResult = ffm.Solve(); var actualCost = ffm.ResultCost; Assert.AreEqual(8, actualCost); Assert.AreEqual(expectedResult, actualResult); }
public void FordFulkersonMethodTest00() { var data = new double[,] { {1, 2, 4, 4, 0, 4}, {1, 4, 9, 5, 0, 6}, {2, 4, 2, 2, 0, 1}, {2, 5, 4, 2, 0, 3}, {3, 5, 1, 1, 0, 0}, {3, 6, 10, 0, 0, 1}, {4, 3, 1, 1, 0, 1}, {4, 6, 6, 6, 0, 6}, {5, 6, 1, 1, 0, 1}, {5, 7, 2, 2, 0, 2}, {6, 7, 9, 7, 0, 8} }; Dictionary<Edge<int>, double> startX; List<Edge<int>> baseU; Dictionary<Edge<int>, double> expectedResult; var graph = GraphHelper.CreateGraph(data, out startX, out baseU, out expectedResult); var startVertex = graph.GetVertex(0); var endVertex = graph.GetVertex(graph.Vertices.Count - 1); const double startCost = 9.0; var ffm = new FordFulkersonMethod(graph, startVertex, endVertex, startX, startCost); var actualResult = ffm.Solve(); var actualCost = ffm.ResultCost; Assert.AreEqual(10, actualCost); Assert.AreEqual(expectedResult, actualResult); }
public static void Test() { int n; n = 6; var edges = new[] { "1 2 10", "1 3 6", "2 5 5", "2 3 3", "2 4 15", "3 4 7", "3 5 10", "4 6 8", "4 5 4", "5 6 12" }; //ответ 16 /*n = 7; * var edges = new[] { "1 2 13", "1 3 10", "1 4 2" , * "2 4 2" , "2 5 4" , * "3 4 10", "3 6 14", * "4 5 8" , "4 6 3" , "4 7 4" , * "5 6 7" , "5 7 9" , * "6 7 6" };*/ //Ответ 19 4+4+3+6 = 17 /*n = 5; * var edges = new[] { "1 2 20", "1 3 30", "1 4 10" , * "2 3 40" , "2 5 30" , * "3 4 10", "3 5 20", * "4 5 20" * };*/ FordFulkersonMethod t = new FordFulkersonMethod(n); Console.WriteLine("Количество вершин = " + n); Console.WriteLine("-------------------------------------- Рёбра: "); Console.WriteLine("From".PadRight(5) + "To".PadRight(5) + "Capacity"); Console.WriteLine("----------------------------------------------"); foreach (var edge in edges) { string[] s = edge.Split(' '); int from = int.Parse(s[0]) - 1; int to = int.Parse(s[1]) - 1; int cap = int.Parse(s[2]); t.capacity[from, to] = cap; Console.WriteLine(s[0].PadRight(5) + s[1].PadRight(5) + s[2]); } Console.WriteLine("Максимальный поток = " + t.max_flow() + "\n Остаточная емкость:"); Console.WriteLine("From".PadRight(5) + "To".PadRight(5) + "Capacity"); for (int i = 0; i < t.capacity.GetLength(0); i++) { for (int j = 0; j < t.capacity.GetLength(1); j++) { if (t.capacity[i, j] == 0) { continue; } Console.WriteLine(((i + 1).ToString()).PadRight(5) + ((j + 1).ToString()).PadRight(5) + (t.capacity[i, j] - t.flow[i, j])); } } }
public void FordFulkersonMethodTest1() { var data = new double[,] { {1, 2, 3, 3}, {1, 3, 2, 2}, {1, 4, 1, 1}, {1, 6, 6, 4}, {2, 4, 1, 1}, {2, 5, 2, 2}, {3, 4, 1, 0}, {3, 5, 2, 2}, {3, 6, 4, 0}, {4, 5, 7, 0}, {4, 6, 5, 0}, {4, 7, 4, 2}, {4, 8, 1, 0}, {5, 7, 3, 2}, {5, 8, 2, 2}, {6, 8, 4, 4}, {7, 6, 3, 0}, {7, 8, 5, 4} }; Dictionary<Edge<int>, double> expectedResult; var graph = GraphHelper.CreateGraph(data, out expectedResult); var startVertex = graph.GetVertex(0); var endVertex = graph.GetVertex(graph.Vertices.Count - 1); var ffm = new FordFulkersonMethod(graph, startVertex, endVertex); /*var actualResult = */ffm.Solve(); var actualCost = ffm.ResultCost; Assert.AreEqual(10, actualCost); //Assert.AreEqual(expectedResult, actualResult); }
public void FordFulkersonMethodTest7() { var data = new double[,] { {1, 5, 4, 1}, {1, 6, 6, 6}, {1, 7, 2, 0}, {2, 1, 3, 0}, {2, 3, 2, 0}, {2, 5, 7, 0}, {4, 2, 3, 0}, {4, 3, 5, 0}, {4, 5, 2, 0}, {4, 7, 4, 0}, {4, 9, 2, 0}, {5, 6, 1, 1}, {6, 9, 7, 7}, {7, 6, 1, 0}, {8, 4, 6, 0}, {8, 7, 4, 0}, {8, 9, 1, 0} }; Dictionary<Edge<int>, double> expectedResult; var graph = GraphHelper.CreateGraph(data, out expectedResult); var startVertex = graph.GetVertex(0); var endVertex = graph.GetVertex(graph.Vertices.Count - 1); var ffm = new FordFulkersonMethod(graph, startVertex, endVertex); var actualResult = ffm.Solve(); var actualCost = ffm.ResultCost; Assert.AreEqual(7, actualCost); Assert.AreEqual(expectedResult, actualResult); }