Skip to content

Commit 214db33

Browse files
authored
Update code coverage (#144)
1 parent 24decec commit 214db33

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/algorithms/KirlikSayin.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ function minimize_multiobjective!(algorithm::KirlikSayin, model::Optimizer)
146146
end
147147
optimize_inner!(model)
148148
if !_is_scalar_status_optimal(model)
149+
# If this fails, it likely means that the solver experienced a
150+
# numerical error with this box. Just skip it.
149151
_remove_rectangle(L, _Rectangle(_project(yI, k), uᵢ))
150152
MOI.delete.(model, ε_constraints)
151153
continue
@@ -163,6 +165,8 @@ function minimize_multiobjective!(algorithm::KirlikSayin, model::Optimizer)
163165
)
164166
optimize_inner!(model)
165167
if !_is_scalar_status_optimal(model)
168+
# If this fails, it likely means that the solver experienced a
169+
# numerical error with this box. Just skip it.
166170
MOI.delete.(model, ε_constraints)
167171
MOI.delete(model, zₖ_constraint)
168172
_remove_rectangle(L, _Rectangle(_project(yI, k), uᵢ))

test/algorithms/Dichotomy.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,24 @@ function test_solve_failures()
440440
return
441441
end
442442

443+
function test_scalar_time_limit()
444+
model = MOA.Optimizer(HiGHS.Optimizer)
445+
MOI.set(model, MOA.Algorithm(), MOA.Dichotomy())
446+
MOI.set(model, MOI.Silent(), true)
447+
MOI.set(model, MOI.TimeLimitSec(), 0.0)
448+
MOI.Utilities.loadfromstring!(
449+
model,
450+
"""
451+
variables: x
452+
minobjective: [2 * x]
453+
x >= 0.0
454+
""",
455+
)
456+
MOI.optimize!(model)
457+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.TIME_LIMIT
458+
return
459+
end
460+
443461
end # module TestDichotomy
444462

445463
TestDichotomy.run_tests()

test/algorithms/KirlikSayin.jl

Lines changed: 31 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,36 @@ 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.KirlikSayin())
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()) ==
174+
(fail_after <= 3 ? MOI.NUMERICAL_ERROR : MOI.OPTIMAL)
175+
@test MOI.get(model, MOI.ResultCount()) == 0
176+
end
177+
return
178+
end
179+
149180
end # TestKirlikSayin
150181

151182
TestKirlikSayin.run_tests()

0 commit comments

Comments
 (0)