27 int[,] costs = { { 90, 75, 75, 80 }, { 35, 85, 55, 65 }, { 125, 95, 90, 105 }, { 45, 110, 95, 115 } };
28 int expectedCost = 275;
29 MinCostFlow minCostFlow =
new MinCostFlow();
30 Assert.NotNull(minCostFlow);
31 for (
int source = 0; source < numSources; ++source)
33 for (
int target = 0; target < numTargets; ++target)
35 minCostFlow.AddArcWithCapacityAndUnitCost(source, numSources + target, 1, costs[source, target]);
39 for (
int source = 0; source < numSources; ++source)
41 minCostFlow.SetNodeSupply(source, 1);
43 for (
int target = 0; target < numTargets; ++target)
45 minCostFlow.SetNodeSupply(numSources + target, -1);
47 MinCostFlowBase.Status solveStatus = minCostFlow.Solve();
48 Assert.Equal(solveStatus, MinCostFlow.Status.OPTIMAL);
49 long totalFlowCost = minCostFlow.OptimalCost();
50 Assert.Equal(expectedCost, totalFlowCost);
58 int[] tails = { 0, 0, 0, 0, 1, 2, 3, 3, 4 };
59 int[] heads = { 1, 2, 3, 4, 3, 4, 4, 5, 5 };
60 int[] capacities = { 5, 8, 2, 0, 4, 5, 6, 0, 4 };
61 int[] expectedFlows = { 4, 4, 2, 0, 4, 4, 0, 6, 4 };
62 int expectedTotalFlow = 10;
63 MaxFlow maxFlow =
new MaxFlow();
64 Assert.NotNull(maxFlow);
65 for (
int i = 0; i < numArcs; ++i)
67 maxFlow.AddArcWithCapacity(tails[i], heads[i], capacities[i]);
69 maxFlow.SetArcCapacity(7, 6);
70 MaxFlow.Status solveStatus = maxFlow.Solve(0, numNodes - 1);
71 Assert.Equal(solveStatus, MaxFlow.Status.OPTIMAL);
73 long totalFlow = maxFlow.OptimalFlow();
74 Assert.Equal(expectedTotalFlow, totalFlow);
76 Assert.Equal(numArcs, maxFlow.NumArcs());
77 for (
int i = 0; i < numArcs; ++i)
79 Assert.Equal(maxFlow.Flow(i), expectedFlows[i]);