Skip to content

Commit

Permalink
Improve coverage for ConstraintDualStart (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Nov 24, 2024
1 parent d5ee69f commit 5f9598b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function test_ConstraintDualStart()
@test MOI.supports(model, MOI.ConstraintDualStart(), typeof(u))
@test MOI.supports(model, MOI.ConstraintDualStart(), typeof(e))
@test MOI.supports(model, MOI.ConstraintDualStart(), typeof(c))
@test MOI.supports(model, MOI.NLPBlockDualStart())
@test MOI.get(model, MOI.ConstraintDualStart(), l) === nothing
@test MOI.get(model, MOI.ConstraintDualStart(), u) === nothing
@test MOI.get(model, MOI.ConstraintDualStart(), e) === nothing
Expand Down Expand Up @@ -141,6 +142,45 @@ function test_ConstraintDualStart_ScalarNonlinearFunction()
return
end

function test_ConstraintDualStart_variable_bound_min_greater_than()
model = Ipopt.Optimizer()
x, c = MOI.add_constrained_variable(model, MOI.GreaterThan(1.0))
MOI.set(model, MOI.VariablePrimalStart(), x, 1.0)
MOI.set(model, MOI.ConstraintDualStart(), c, 1.0)
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(model, MOI.ObjectiveFunction{MOI.VariableIndex}(), x)
MOI.optimize!(model)
@test isapprox(MOI.get(model, MOI.ConstraintDual(), c), 1.0; atol = 1e-6)
@test MOI.get(model, MOI.ConstraintDualStart(), c) == 1.0
return
end

function test_ConstraintDualStart_variable_bound_max_less_than()
model = Ipopt.Optimizer()
x, c = MOI.add_constrained_variable(model, MOI.LessThan(1.0))
MOI.set(model, MOI.VariablePrimalStart(), x, 1.0)
MOI.set(model, MOI.ConstraintDualStart(), c, -1.0)
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
MOI.set(model, MOI.ObjectiveFunction{MOI.VariableIndex}(), x)
MOI.optimize!(model)
@test isapprox(MOI.get(model, MOI.ConstraintDual(), c), -1.0; atol = 1e-6)
@test MOI.get(model, MOI.ConstraintDualStart(), c) == -1.0
return
end

function test_ConstraintDualStart_variable_bound_min_equal_to()
model = Ipopt.Optimizer()
x, c = MOI.add_constrained_variable(model, MOI.EqualTo(1.0))
MOI.set(model, MOI.VariablePrimalStart(), x, 1.0)
MOI.set(model, MOI.ConstraintDualStart(), c, 1.0)
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(model, MOI.ObjectiveFunction{MOI.VariableIndex}(), x)
MOI.optimize!(model)
@test isapprox(MOI.get(model, MOI.ConstraintDual(), c), 1.0; atol = 1e-6)
@test MOI.get(model, MOI.ConstraintDualStart(), c) == 1.0
return
end

function test_solve_time()
model = Ipopt.Optimizer()
MOI.set(model, MOI.Silent(), true)
Expand Down

0 comments on commit 5f9598b

Please sign in to comment.