28 int[] startNodes = {0, 0, 0, 1, 1, 2, 2, 3, 3};
29 int[] endNodes = {1, 2, 3, 2, 4, 3, 4, 2, 4};
30 int[] capacities = {20, 30, 10, 40, 30, 10, 20, 5, 20};
35 MaxFlow maxFlow =
new MaxFlow();
38 for (
int i = 0; i < startNodes.Length; ++i)
40 int arc = maxFlow.AddArcWithCapacity(startNodes[i], endNodes[i],
42 if (arc != i)
throw new Exception(
"Internal error");
48 MaxFlow.Status solveStatus = maxFlow.Solve(0, 4);
52 if (solveStatus == MaxFlow.Status.OPTIMAL)
54 Console.WriteLine(
"Max. flow: " + maxFlow.OptimalFlow());
55 Console.WriteLine(
"");
56 Console.WriteLine(
" Arc Flow / Capacity");
57 for (
int i = 0; i < maxFlow.NumArcs(); ++i)
59 Console.WriteLine(maxFlow.Tail(i) +
" -> " +
60 maxFlow.Head(i) +
" " +
61 string.Format(
"{0,3}", maxFlow.Flow(i)) +
" / " +
62 string.Format(
"{0,3}", maxFlow.Capacity(i)));
67 Console.WriteLine(
"Solving the max flow problem failed. Solver status: " +