Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jan 3, 2025
1 parent 71b86d8 commit 8be2f02
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,50 @@ function test_dual_objective_value_infeasible()
return
end

function test_ObjectiveFunction_VectorAffineFunction_to_ScalarAffineFunction()
model = HiGHS.Optimizer()
MOI.set(model, MOI.Silent(), true)
x = MOI.add_variables(model, 2)
MOI.add_constraint(model, x[1], MOI.Interval(1.0, 2.0))
MOI.add_constraint(model, x[2], MOI.Interval(3.0, 4.0))
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
f = MOI.Utilities.operate(vcat, Float64, 1.0 * x[1], 1.0 * x[2])
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
MOI.optimize!(model)
@test (MOI.get(model, MOI.ObjectiveValue()), 4.0)
g = 1.0 * x[1] - 2.0 * x[2]
MOI.set(model, MOI.ObjectiveFunction{typeof(g)}(), g)
MOI.optimize!(model)
@test (MOI.get(model, MOI.ObjectiveValue()), -7.0; atol = 1e-6)
@test (MOI.get(model, MOI.VariablePrimal(), x), [1.0, 4.0]; atol = 1e-6)
@test MOI.get(model, MOI.ObjectiveFunctionType()) ==
MOI.ScalarAffineFunction{Float64}
@test model.multi_objective === nothing
return
end

function test_ObjectiveFunction_VectorAffineFunction_to_ScalarQuadraticFunction()
model = HiGHS.Optimizer()
MOI.set(model, MOI.Silent(), true)
x = MOI.add_variables(model, 2)
MOI.add_constraint(model, x[1], MOI.Interval(1.0, 2.0))
MOI.add_constraint(model, x[2], MOI.Interval(3.0, 4.0))
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
f = MOI.Utilities.operate(vcat, Float64, 1.0 * x[1], 1.0 * x[2])
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
MOI.optimize!(model)
@test (MOI.get(model, MOI.ObjectiveValue()), 4.0)
g = 1.0 * x[1] + (1.0 * x[2] * x[2] - 8.0 * x[2] + 16.0)
MOI.set(model, MOI.ObjectiveFunction{typeof(g)}(), g)
MOI.optimize!(model)
@test (MOI.get(model, MOI.ObjectiveValue()), 1.0; atol = 1e-6)
@test (MOI.get(model, MOI.VariablePrimal(), x), [1.0, 4.0]; atol = 1e-6)
@test MOI.get(model, MOI.ObjectiveFunctionType()) ==
MOI.ScalarQuadraticFunction{Float64}
@test model.multi_objective === nothing
return
end

end # module

TestMOIHighs.runtests()

0 comments on commit 8be2f02

Please sign in to comment.