Skip to content

Commit

Permalink
Add delete for nonlinear constraints (#3013)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jul 5, 2022
1 parent 046d1dc commit fd66aea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,18 @@ function is_valid(model::Model, c::NonlinearConstraintRef)
return MOI.is_valid(model.nlp_model, index)
end

"""
delete(model::Model, c::NonlinearConstraintRef)
Delete the nonlinear constraint `c` from `model`.
"""
function delete(model::Model, c::NonlinearConstraintRef)
_init_NLP(model)
index = MOI.Nonlinear.ConstraintIndex(c.index.value)
MOI.Nonlinear.delete(model.nlp_model, index)
return
end

"""
num_nonlinear_constraints(model::Model)
Expand Down
14 changes: 14 additions & 0 deletions test/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,20 @@ function test_nonlinear_constraint_dual()
return
end

function test_nonlinear_delete_constraint()
model = Model()
@variable(model, x)
@NLconstraint(model, c[i = 1:3], x^i <= i)
@test num_nonlinear_constraints(model) == 3
@test all_nonlinear_constraints(model) == [c[1], c[2], c[3]]
@test is_valid.(model, c) == [true, true, true]
delete(model, c[2])
@test num_nonlinear_constraints(model) == 2
@test all_nonlinear_constraints(model) == [c[1], c[3]]
@test is_valid.(model, c) == [true, false, true]
return
end

end

TestNLP.runtests()

0 comments on commit fd66aea

Please sign in to comment.