private IWeightedGraph <int, double> FindCostMinimalFlow(Graph <int, double> graph, Algorithm algorithm) { IWeightedGraph <int, double> flow = null; int vertexCount = graph.GetAllVerteces().Count(); switch (algorithm) { case Algorithm.CycleCanceling: flow = CycleCanceling.FindCostMinimalFlow(graph, vertexCount, vertexCount + 1, (v1, v2) => v1 + v2, (v1, v2) => v1 - v2, v => v * -1, 0.0, double.MaxValue); break; case Algorithm.SuccessiveShortestPath: flow = SuccessiveShortestPath.FindCostMinimalFlow(graph, vertexCount, vertexCount + 1, (v1, v2) => v1 + v2, (v1, v2) => v1 - v2, v => v * -1, 0.0, double.MaxValue); break; default: throw new NotSupportedException($"No tests available for minimum cost flows algorithm '{algorithm}'"); } return(flow); }
private static void P7CycleCanceling() { Console.WriteLine("-------------------------------"); Console.WriteLine("Neuer Graph"); var hFileName = GraphFileRessources.P7CostMinFluesse1; var hGraph = AdjacentListGraphImporter.ImportAdjacentListBalancedNodesCostCapacityEdges(hFileName); var hCycleCancelingAlgorithm = new CycleCancelingAlgorithm(hGraph); hCycleCancelingAlgorithm.Execute(); var hSuccessiveShortestPath = new SuccessiveShortestPath(hGraph); hSuccessiveShortestPath.Execute(); Console.WriteLine("-------------------------------"); Console.WriteLine("Neuer Graph"); hFileName = GraphFileRessources.P7CostMinFluesse2; hGraph = AdjacentListGraphImporter.ImportAdjacentListBalancedNodesCostCapacityEdges(hFileName); hCycleCancelingAlgorithm = new CycleCancelingAlgorithm(hGraph); hCycleCancelingAlgorithm.Execute(); hSuccessiveShortestPath = new SuccessiveShortestPath(hGraph); hSuccessiveShortestPath.Execute(); Console.WriteLine("-------------------------------"); Console.WriteLine("Neuer Graph"); hFileName = GraphFileRessources.P7CostMinFluesse3; hGraph = AdjacentListGraphImporter.ImportAdjacentListBalancedNodesCostCapacityEdges(hFileName); hCycleCancelingAlgorithm = new CycleCancelingAlgorithm(hGraph); hCycleCancelingAlgorithm.Execute(); hSuccessiveShortestPath = new SuccessiveShortestPath(hGraph); hSuccessiveShortestPath.Execute(); Console.WriteLine("-------------------------------"); Console.WriteLine("Neuer Graph"); hFileName = GraphFileRessources.P7CostMinFluesse4; hGraph = AdjacentListGraphImporter.ImportAdjacentListBalancedNodesCostCapacityEdges(hFileName); hCycleCancelingAlgorithm = new CycleCancelingAlgorithm(hGraph); hCycleCancelingAlgorithm.Execute(); hSuccessiveShortestPath = new SuccessiveShortestPath(hGraph); hSuccessiveShortestPath.Execute(); }