File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -456,6 +456,18 @@ function is_valid(model::Model, c::NonlinearConstraintRef)
456
456
return MOI. is_valid (model. nlp_model, index)
457
457
end
458
458
459
+ """
460
+ delete(model::Model, c::NonlinearConstraintRef)
461
+
462
+ Delete the nonlinear constraint `c` from `model`.
463
+ """
464
+ function delete (model:: Model , c:: NonlinearConstraintRef )
465
+ _init_NLP (model)
466
+ index = MOI. Nonlinear. ConstraintIndex (c. index. value)
467
+ MOI. Nonlinear. delete (model. nlp_model, index)
468
+ return
469
+ end
470
+
459
471
"""
460
472
num_nonlinear_constraints(model::Model)
461
473
Original file line number Diff line number Diff line change @@ -1406,6 +1406,20 @@ function test_nonlinear_constraint_dual()
1406
1406
return
1407
1407
end
1408
1408
1409
+ function test_nonlinear_delete_constraint ()
1410
+ model = Model ()
1411
+ @variable (model, x)
1412
+ @NLconstraint (model, c[i = 1 : 3 ], x^ i <= i)
1413
+ @test num_nonlinear_constraints (model) == 3
1414
+ @test all_nonlinear_constraints (model) == [c[1 ], c[2 ], c[3 ]]
1415
+ @test is_valid .(model, c) == [true , true , true ]
1416
+ delete (model, c[2 ])
1417
+ @test num_nonlinear_constraints (model) == 2
1418
+ @test all_nonlinear_constraints (model) == [c[1 ], c[3 ]]
1419
+ @test is_valid .(model, c) == [true , false , true ]
1420
+ return
1421
+ end
1422
+
1409
1423
end
1410
1424
1411
1425
TestNLP. runtests ()
You can’t perform that action at this time.
0 commit comments