Skip to content

Commit 0ba8fcc

Browse files
committed
add test from a textbook to Minimum Cost Flow
1 parent ad8bafe commit 0ba8fcc

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/maximumflow.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function solve(problem::MinimumCostFlowProblem, flow::Float64)::MinimumCostFlowR
217217
@variable(model, x[1:n, 1:n] .>= 0)
218218

219219
# Objective Function
220-
@objective(model, Max, sum(x[conn.from, conn.to] * conn.value for conn in costs))
220+
@objective(model, Min, sum(x[conn.from, conn.to] * conn.value for conn in costs))
221221

222222
# Constraints
223223
for nextnode in mynodes

test/testminimumcostflow.jl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,46 @@
4444
result = solve(problem)
4545

4646
@test result isa MinimumCostFlowResult
47-
@test result.cost == 95.0
47+
@test result.cost == 65.0
48+
end
49+
50+
@testset "Book example - 1" verbose = true begin
51+
52+
# Example is given from the url:
53+
# https://www.ams.jhu.edu/~castello/625.414/Handouts/WV8.5.pdf
54+
55+
conns = Connection[
56+
Connection(1,2,800),
57+
Connection(1,3,600),
58+
Connection(2,5,100),
59+
Connection(2,4,600),
60+
Connection(5,6,600),
61+
Connection(4,5,600),
62+
Connection(4,6,400),
63+
Connection(3,5,400),
64+
Connection(3,4,300)
65+
]
66+
67+
costs = Connection[
68+
Connection(1,2,10),
69+
Connection(1,3,50),
70+
Connection(2,5,70),
71+
Connection(2,4,30),
72+
Connection(5,6,30),
73+
Connection(4,5,30),
74+
Connection(4,6,60),
75+
Connection(3,5,60),
76+
Connection(3,4,10)
77+
]
78+
79+
definedflow = 900.0
80+
81+
problem = MinimumCostFlowProblem(conns, costs)
82+
83+
result = solve(problem, definedflow)
84+
85+
@test result isa MinimumCostFlowResult
86+
@test result.cost == 95000.0
4887

4988
end
5089
end

0 commit comments

Comments
 (0)