Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve coverage for ConstraintDualStart #438

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

odow marked this conversation as resolved.
Show resolved Hide resolved
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
Loading