Skip to content

Commit 04da3d7

Browse files
committed
More tidying of the tests
1 parent 0f7fa15 commit 04da3d7

3 files changed

Lines changed: 833 additions & 850 deletions

File tree

test/instances.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
# Use of this source code is governed by an MIT-style license that can be found
44
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
55

6+
module Instances
7+
68
using JuMP
9+
using Test
10+
11+
import Ipopt
712

813
# Solution reported by Sven Leyffer in MacMPEC:
914
# https://wiki.mcs.anl.gov/leyffer/index.php/MacMPEC
@@ -19,6 +24,29 @@ const MACMPEC_SOLUTIONS = Dict{Symbol,Float64}(
1924
:water_net_model => 930.6687, # Solution reported is slightly worse than in MacMPEC (929.169)
2025
)
2126

27+
# Some instances are flaky in CI around the reference optimum, so we loosen
28+
# the tolerance on a per-instance basis.
29+
const MACMPEC_TOLERANCES = Dict(:water_net_model => (rtol = 1e-2, atol = 1e-2))
30+
31+
function runtests(make_opt)
32+
is_test(s) = !startswith("$s", "#") && endswith("$s", "_model")
33+
@testset "$name" for name in filter(is_test, names(@__MODULE__; all = true))
34+
model = getfield(@__MODULE__, name)()
35+
set_optimizer(model, () -> make_opt(Ipopt.Optimizer()))
36+
set_attribute(model, "bound_relax_factor", 0.0)
37+
set_attribute(model, "mu_strategy", "adaptive")
38+
set_attribute(model, "bound_push", 1e-1)
39+
set_silent(model)
40+
optimize!(model)
41+
@test is_solved_and_feasible(model)
42+
if haskey(MACMPEC_SOLUTIONS, name)
43+
tol = get(MACMPEC_TOLERANCES, name, (rtol = 1e-4, atol = 1e-4))
44+
@test objective_value(model) MACMPEC_SOLUTIONS[name] rtol=tol.rtol atol=tol.atol
45+
end
46+
end
47+
return
48+
end
49+
2250
# Ex. (2.2) from "Local convergence of SQP methods for MPECs".
2351
# Solution is (0.5, 0.5), basic multipliers is (0, 1, 0)
2452
function fletcher_leyffer_ex1_model()
@@ -439,3 +467,5 @@ function water_net_model()
439467

440468
return model
441469
end
470+
471+
end # module Instances

0 commit comments

Comments
 (0)