Skip to content

Commit eee9a90

Browse files
authored
Fix optimizer factory usage in Sandwiching (#148)
1 parent 10ab254 commit eee9a90

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

ext/MultiObjectiveAlgorithmsPolyhedraExt.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ function MOA.minimize_multiobjective!(
4545
n = MOI.output_dimension(model.f)
4646
scalars = MOI.Utilities.scalarize(model.f)
4747
status = MOI.OPTIMAL
48-
optimizer = typeof(model.inner.optimizer)
49-
δ_OPS_optimizer = optimizer()
50-
MOI.set(δ_OPS_optimizer, MOI.Silent(), true)
48+
δ_OPS_optimizer = MOI.instantiate(model.optimizer_factory)
49+
if MOI.supports(δ_OPS_optimizer, MOI.Silent())
50+
MOI.set(δ_OPS_optimizer, MOI.Silent(), true)
51+
end
5152
y = MOI.add_variables(δ_OPS_optimizer, n)
5253
anchors = Dict{Vector{Float64},Dict{MOI.VariableIndex,Float64}}()
5354
yI, yUB = zeros(n), zeros(n)

src/MultiObjectiveAlgorithms.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
124124
ideal_point::Vector{Float64}
125125
compute_ideal_point::Bool
126126
subproblem_count::Int
127+
optimizer_factory::Any
127128

128129
function Optimizer(optimizer_factory)
129130
return new(
@@ -137,6 +138,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
137138
Float64[],
138139
default(ComputeIdealPoint()),
139140
0,
141+
optimizer_factory,
140142
)
141143
end
142144
end

src/algorithms/Sandwiching.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"""
77
Sandwiching(precision::Float64)
88
9-
An algorithm that implemennts the paper described in Koenen, M., Balvert, M., & Fleuren, H. A. (2023). A Renewed Take on Weighted Sum in Sandwich Algorithms: Modification of the Criterion Space. (Center Discussion Paper; Vol. 2023-012). CentER, Center for Economic Research.
9+
An algorithm that implemennts the paper described in Koenen, M., Balvert, M., &
10+
Fleuren, H. A. (2023). A Renewed Take on Weighted Sum in Sandwich Algorithms:
11+
Modification of the Criterion Space. (Center Discussion Paper; Vol. 2023-012).
12+
CentER, Center for Economic Research.
1013
1114
## Compat
1215

test/algorithms/Sandwiching.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import MultiObjectiveAlgorithms as MOA
1212
import MultiObjectiveAlgorithms: MOI
1313
import Polyhedra
1414

15+
include(joinpath(dirname(@__DIR__), "mock_optimizer.jl"))
16+
1517
function run_tests()
1618
for name in names(@__MODULE__; all = true)
1719
if startswith("$name", "test_")
@@ -190,6 +192,35 @@ function test_time_limit()
190192
return
191193
end
192194

195+
function test_solve_failures()
196+
m, n = 2, 10
197+
p1 = [5.0 1 10 8 3 5 3 3 7 2; 10 6 1 6 8 3 2 10 6 1]
198+
p2 = [4.0 6 4 3 1 6 8 2 9 7; 8 8 8 2 4 8 8 1 10 1]
199+
w = [5.0 9 3 5 10 5 7 10 7 8; 4 8 8 6 10 8 10 7 5 1]
200+
b = [34.0, 33.0]
201+
for fail_after in 0:4
202+
model = MOA.Optimizer(mock_optimizer(fail_after))
203+
MOI.set(model, MOA.Algorithm(), MOA.Sandwiching(0.0))
204+
x_ = MOI.add_variables(model, m * n)
205+
x = reshape(x_, m, n)
206+
MOI.add_constraint.(model, x, MOI.Interval(0.0, 1.0))
207+
f = MOI.Utilities.operate(vcat, Float64, sum(p1 .* x), sum(p2 .* x))
208+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
209+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
210+
for i in 1:m
211+
f_i = sum(w[i, j] * x[i, j] for j in 1:n)
212+
MOI.add_constraint(model, f_i, MOI.LessThan(b[i]))
213+
end
214+
for j in 1:n
215+
MOI.add_constraint(model, sum(1.0 .* x[:, j]), MOI.EqualTo(1.0))
216+
end
217+
MOI.optimize!(model)
218+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.NUMERICAL_ERROR
219+
@test MOI.get(model, MOI.ResultCount()) == 0
220+
end
221+
return
222+
end
223+
193224
end # TestSandwiching
194225

195226
TestSandwiching.run_tests()

0 commit comments

Comments
 (0)