Skip to content

Commit dc2a3aa

Browse files
authored
[Test] add a new test for solving a multiobjective problem (#2970)
1 parent e3c6918 commit dc2a3aa

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/Test/test_multiobjective.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,51 @@ function test_multiobjective_vector_nonlinear_modify(
379379
end
380380

381381
version_added(::typeof(test_multiobjective_vector_nonlinear_modify)) = v"1.19.0"
382+
383+
function test_multi_objective_solve_and_objective_value(
384+
model::MOI.ModelLike,
385+
config::Config{T},
386+
) where {T}
387+
F = MOI.VectorAffineFunction{T}
388+
@requires _supports(config, MOI.optimize!)
389+
@requires MOI.supports(model, MOI.ObjectiveFunction{F}())
390+
x = MOI.add_variables(model, 3)
391+
MOI.add_constraint.(model, x, MOI.Interval(zero(T), one(T)))
392+
f = sum(one(T) * x[i] for i in 1:3)
393+
MOI.add_constraint(model, f, MOI.LessThan(T(2)))
394+
g = MOI.Utilities.vectorize([
395+
T(3) * x[1],
396+
T(3) * x[1] + T(1) * x[2] + T(2) * x[3],
397+
])
398+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
399+
MOI.set(model, MOI.ObjectiveFunction{typeof(g)}(), g)
400+
MOI.optimize!(model)
401+
@test MOI.get(model, MOI.ResultCount()) > 0
402+
for i in 1:MOI.get(model, MOI.ResultCount())
403+
y = MOI.Utilities.eval_variables(model, g) do xi
404+
return MOI.get(model, MOI.VariablePrimal(i), xi)
405+
end
406+
@test isapprox(MOI.get(model, MOI.ObjectiveValue()), y)
407+
end
408+
return
409+
end
410+
411+
function setup_test(
412+
::typeof(test_multi_objective_solve_and_objective_value),
413+
model::MOIU.MockOptimizer,
414+
::Config{T},
415+
) where {T}
416+
MOIU.set_mock_optimize!(
417+
model,
418+
mock -> MOIU.mock_optimize!(
419+
mock,
420+
MOI.OPTIMAL,
421+
(MOI.FEASIBLE_POINT, T[1, 0, 1]),
422+
),
423+
)
424+
return
425+
end
426+
427+
function version_added(::typeof(test_multi_objective_solve_and_objective_value))
428+
return v"1.50.0"
429+
end

0 commit comments

Comments
 (0)