# Constriant in ADNLPModels package

**URL:** <https://discourse.julialang.org/t/constriant-in-adnlpmodels-package/95832>\
**Category:** Optimization (Mathematical)\
**Tags:** question, package\
**Created:** [March 9, 2023, 11:46pm UTC](https://discourse.julialang.org/t/constriant-in-adnlpmodels-package/95832 "2023-03-09T23:46:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![X\_Chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/x_chen/32/47565_2.png) [@X\_Chen](https://discourse.julialang.org/u/X_Chen)\
**Post date:** [March 9, 2023, 11:46pm UTC](https://discourse.julialang.org/t/constriant-in-adnlpmodels-package/95832/1 "2023-03-09T23:46:33Z")

</div>

Hi everyone,

I am trying to do a nonlinear optimization with six parameters using the ADNLModles package. For example:

```julia
function constriants(para)
    cons=1-para[1]^2-para[2]^2-para[3]^2+2*para[1]*para[2]*para[3]
    return([para[1];para[2];para[3];cons])
end

lb=[-0.999;-0.999;-0.999;0.001]
ub=[0.999;0.999;0.999;Inf]

function obj(para)
         println(para)
          value
return (value)

opt=ADNLPModel(obj,para,constriants,lb,ub)

ipopt(opt)

```

And I printed out every parameter in the optimization routine, and I found that sometimes the searching area was outside the constraints, and the optimization crashed.

I was wondering if that’s a bug in the package or if there is another optimization package I could use for nonlinear constraints. I would appreciate any advice on making this function work.

Thanks！

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [March 10, 2023, 8:26am UTC](https://discourse.julialang.org/t/constriant-in-adnlpmodels-package/95832/2 "2023-03-10T08:26:22Z")

</div>

Welcome. I’ve moved your question to the Optimization category since it may be more easily seen by someone who can answer it.

Since it sounds like you are solving a small problem, can you post your actual code?

---

<div class="post-metadata">

**Author:** ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Post date:** [March 10, 2023, 8:46am UTC](https://discourse.julialang.org/t/constriant-in-adnlpmodels-package/95832/3 "2023-03-10T08:46:36Z")

</div>

Hi, answering from the phone.

Ipopt is responsible here, it doesn’t guarantee non-bounds constraints are satisfied in intermediate steps. See [https://stackoverflow.com/a/39125549](https://stackoverflow.com/a/39125549)  
This question was asked kn the past, you can check for more information.  
One thing to try is the Percival.jl solver. It is also compliant with adnlpmodels.

---

<div class="post-metadata">

**Author:** ![X\_Chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/x_chen/32/47565_2.png) [@X\_Chen](https://discourse.julialang.org/u/X_Chen)\
**Post date:** [March 10, 2023, 8:28pm UTC](https://discourse.julialang.org/t/constriant-in-adnlpmodels-package/95832/4 "2023-03-10T20:28:36Z")

</div>

Thanks for moving my post! I updated the constraints part in my code (my objective function is too long).

---

<div class="post-metadata">

**Author:** ![X\_Chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/x_chen/32/47565_2.png) [@X\_Chen](https://discourse.julialang.org/u/X_Chen)\
**Post date:** [March 10, 2023, 8:29pm UTC](https://discourse.julialang.org/t/constriant-in-adnlpmodels-package/95832/5 "2023-03-10T20:29:09Z")

</div>

Thanks! It’s exactly my problem. I will try Percival solver.
