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

Allow adding nonlinear constraints after solving #171

Merged
merged 2 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/MOI_wrapper/nonlinear_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ function MOI.set(o::Optimizer, ::MOI.NLPBlock, data::MOI.NLPBlockData)
error("Nonlinear objective not supported by SCIP.jl!")
end

# go back to problem stage
allow_modification(o::Optimizer)

MOI.initialize(data.evaluator, [:ExprGraph])
for i in 1:length(data.constraint_bounds)
expr = MOI.constraint_expr(data.evaluator, i)
Expand Down
24 changes: 24 additions & 0 deletions test/MOI_nonlinear_exprs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,27 @@ end
@test min(sol[19], sol[20]) ≈ 1.0 atol=atol rtol=rtol
@test max(sol[19], sol[20]) ≈ 3.0 atol=atol rtol=rtol
end

@testset "add nonlinear constraint after solve" begin
optimizer = SCIP.Optimizer()
MOI.set(optimizer, MOI.RawParameter("display/verblevel"), 0)

x, y = MOI.add_variables(optimizer, 2)

data1 = MOI.NLPBlockData(
[MOI.NLPBoundsPair(rhs, rhs) for rhs in [1.0, 2.0]],
ExprEvaluator([:(x[$x] == 1.0), :(x[$y] == 2.0)]),
false
)
MOI.set(optimizer, MOI.NLPBlock(), data1)

MOI.optimize!(optimizer)

data2 = MOI.NLPBlockData(
[MOI.NLPBoundsPair(rhs, rhs) for rhs in [1.0, 2.0, 3.0]],
ExprEvaluator([:(x[$x] == 1.0), :(x[$y] == 2.0),
:(x[$x] + x[$y] == 3.0)]),
false
)
MOI.set(optimizer, MOI.NLPBlock(), data2)
end