Skip to content

Commit 10ab254

Browse files
authored
Improve code coverage (#147)
1 parent 214db33 commit 10ab254

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

src/algorithms/TambyVanderpooten.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ function minimize_multiobjective!(
158158
end
159159
end
160160
optimize_inner!(model)
161-
if !_is_scalar_status_optimal(model)
161+
status = MOI.get(model.inner, MOI.TerminationStatus())
162+
if !_is_scalar_status_optimal(status)
162163
MOI.delete.(model, ε_constraints)
163164
return status, nothing
164165
end
@@ -171,7 +172,8 @@ function minimize_multiobjective!(
171172
MOI.EqualTo(y_k),
172173
)
173174
optimize_inner!(model)
174-
if !_is_scalar_status_optimal(model)
175+
status = MOI.get(model.inner, MOI.TerminationStatus())
176+
if !_is_scalar_status_optimal(status)
175177
MOI.delete.(model, ε_constraints)
176178
MOI.delete(model, y_k_constraint)
177179
return status, nothing

test/algorithms/Lexicographic.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@ function test_knapsack()
4949
return
5050
end
5151

52+
function test_caching_optimizer_knapsack()
53+
model = MOI.instantiate(
54+
() -> MOA.Optimizer(HiGHS.Optimizer);
55+
with_cache_type = Float64,
56+
)
57+
P = Float64[1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0]
58+
MOI.set(model, MOA.Algorithm(), MOA.Lexicographic())
59+
@test MOI.supports(model, MOA.LexicographicAllPermutations())
60+
@test MOI.supports(model, MOA.ObjectiveRelativeTolerance(1))
61+
MOI.set(model, MOA.LexicographicAllPermutations(), false)
62+
MOI.set(model, MOA.ObjectiveRelativeTolerance(1), 0.1)
63+
MOI.set(model, MOI.Silent(), true)
64+
x = MOI.add_variables(model, 4)
65+
MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
66+
MOI.add_constraint.(model, x, MOI.LessThan(1.0))
67+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
68+
f = MOI.Utilities.operate(vcat, Float64, P * x...)
69+
f.constants[4] = 1_000.0
70+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
71+
MOI.add_constraint(model, sum(1.0 * x[i] for i in 1:4), MOI.LessThan(2.0))
72+
MOI.optimize!(model)
73+
@test MOI.get(model, MOI.ResultCount()) == 1
74+
x_sol = MOI.get(model, MOI.VariablePrimal(), x)
75+
@test (x_sol, [0.9, 1, 0, 0.1]; atol = 1e-3)
76+
return
77+
end
78+
5279
function test_knapsack_default()
5380
P = Float64[1 0 0 0; 0 1 0 0; 0 0 0 1]
5481
model = MOA.Optimizer(HiGHS.Optimizer)

test/algorithms/TambyVanderpooten.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import HiGHS
1111
import MultiObjectiveAlgorithms as MOA
1212
import MultiObjectiveAlgorithms: MOI
1313

14+
include(joinpath(dirname(@__DIR__), "mock_optimizer.jl"))
1415
include(joinpath(dirname(@__DIR__), "problems.jl"))
1516
include(joinpath(dirname(@__DIR__), "vOptLib.jl"))
1617

@@ -146,6 +147,35 @@ function test_vector_of_variables_objective()
146147
return
147148
end
148149

150+
function test_solve_failures()
151+
m, n = 2, 10
152+
p1 = [5.0 1 10 8 3 5 3 3 7 2; 10 6 1 6 8 3 2 10 6 1]
153+
p2 = [4.0 6 4 3 1 6 8 2 9 7; 8 8 8 2 4 8 8 1 10 1]
154+
w = [5.0 9 3 5 10 5 7 10 7 8; 4 8 8 6 10 8 10 7 5 1]
155+
b = [34.0, 33.0]
156+
for fail_after in 0:5
157+
model = MOA.Optimizer(mock_optimizer(fail_after))
158+
MOI.set(model, MOA.Algorithm(), MOA.TambyVanderpooten())
159+
x_ = MOI.add_variables(model, m * n)
160+
x = reshape(x_, m, n)
161+
MOI.add_constraint.(model, x, MOI.Interval(0.0, 1.0))
162+
f = MOI.Utilities.operate(vcat, Float64, sum(p1 .* x), sum(p2 .* x))
163+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
164+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
165+
for i in 1:m
166+
f_i = sum(w[i, j] * x[i, j] for j in 1:n)
167+
MOI.add_constraint(model, f_i, MOI.LessThan(b[i]))
168+
end
169+
for j in 1:n
170+
MOI.add_constraint(model, sum(1.0 .* x[:, j]), MOI.EqualTo(1.0))
171+
end
172+
MOI.optimize!(model)
173+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.NUMERICAL_ERROR
174+
@test MOI.get(model, MOI.ResultCount()) == 0
175+
end
176+
return
177+
end
178+
149179
end # module TestTambyVanderpooten
150180

151181
TestTambyVanderpooten.run_tests()

0 commit comments

Comments
 (0)