# NonLinear Optimization fails with JuMP (infeasible?)

**URL:** <https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [May 13, 2024, 7:45am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190 "2024-05-13T07:45:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nouha941](https://avatars.discourse-cdn.com/v4/letter/n/3e96dc/32.png) [@nouha941](https://discourse.julialang.org/u/nouha941)\
**Post date:** [May 13, 2024, 7:45am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/1 "2024-05-13T07:45:30Z")

</div>

Hello everyone, I’m currently focused on minimizing the specific consumption of a desalination unit. I’ve formulated an equation that incorporates the various hydraulic and pressure parameters of the system under investigation. I’m in the process of developing a simple code to determine the minimum points for each parameter. I’ve recently tried using the JuMP and Ipopt packages, but unfortunately, they are not working as expected. Could you suggest any other packages that might be helpful for this task?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [May 13, 2024, 7:49am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/2 "2024-05-13T07:49:30Z")

</div>

You need to be much more specific about what did not work to get any useful responses.

---

<div class="post-metadata">

**Author:** ![nouha941](https://avatars.discourse-cdn.com/v4/letter/n/3e96dc/32.png) [@nouha941](https://discourse.julialang.org/u/nouha941)\
**Post date:** [May 13, 2024, 7:51am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/3 "2024-05-13T07:51:53Z")

</div>

this is my code, When I execute it, it gives me errors.  
using JuMP, Ipopt  
Cs = Model(Ipopt.Optimizer)  
#Declaring variables  
@variable(Cs, 350_0.000277778\<= Q\_e \<= 450_0.000277778)  
@variable(Cs, 2e5\<= PT401 \<= 5e5)  
@variable(Cs, 45e5\<= PT501 \<= 70e5)  
@variable(Cs, 25e5\<= P \<= 42.1e5)  
@variable(Cs, 125_0.000277778\<= Qp \<= 220_0.000277778)  
@variable(Cs, 0.8\<= R\_m \<= 0.96)  
@variable(Cs, 0.7\<= R\_p \<= 0.9)  
@variable(Cs, 45e5\<= PT502 \<= 56e5)

#setting the objecj=tive  
@objective(Cs, Min, (((Q\_e\*(PT501-PT401))-(Q\_e\*(PT501-P)))/(R\_m_R\_p))_(1/Qp))

#Adding constraints  
@constraint(Cs, constraint1, (((Q\_e\*(PT501-PT401))-(Q\_e\*(PT501-P)))/(R\_m_R\_p))_(1/Qp) \<= 3.5)  
@constraint(Cs, constraint2, PT502-PT501 \<= 4e5)

#Printing the prepared optimization model  
print(Cs)

#Solving the optimization problem  
JuMP.optimize!(Cs)

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [May 13, 2024, 7:52am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/4 "2024-05-13T07:52:34Z")

</div>

> [@nouha941](#):
>
> it gives me errors

what does the error say?

---

<div class="post-metadata">

**Author:** ![nouha941](https://avatars.discourse-cdn.com/v4/letter/n/3e96dc/32.png) [@nouha941](https://discourse.julialang.org/u/nouha941)\
**Post date:** [May 13, 2024, 7:53am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/5 "2024-05-13T07:53:43Z")

</div>

This is Ipopt version 3.14.14, running with linear solver MUMPS 5.6.2.

Number of nonzeros in equality constraint Jacobian…: 0  
Number of nonzeros in inequality constraint Jacobian.: 9  
Number of nonzeros in Lagrangian Hessian…: 56

Total number of variables…: 8  
variables with only lower bounds: 0  
variables with lower and upper bounds: 8  
variables with only upper bounds: 0  
Total number of equality constraints…: 0  
Total number of inequality constraints…: 2  
inequality constraints with only lower bounds: 0  
inequality constraints with lower and upper bounds: 0  
inequality constraints with only upper bounds: 2

iter objective inf\_pr inf\_du lg(mu) ||d|| lg(rg) alpha\_du alpha\_pr ls  
0 1.1465262e+07 1.15e+07 2.00e+00 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0  
1 9.3630406e+06 9.36e+06 1.28e+01 -1.0 1.28e-01 - 2.80e-02 2.49e-01f 1  
2 6.4277601e+06 6.43e+06 1.13e+01 -1.0 1.63e-01 - 4.25e-01 3.28e-01f 1  
3 5.7652555e+06 5.77e+06 2.18e+01 -1.0 6.40e-01 - 1.90e-01 8.24e-02f 1  
4 4.6708055e+06 4.67e+06 5.01e+01 -1.0 5.08e-01 - 9.90e-01 2.44e-01f 1  
5 4.5255243e+06 4.53e+06 3.14e+02 -1.0 2.58e+01 - 9.88e-01 8.09e-02h 1  
6 4.2647595e+06 4.26e+06 1.25e+03 -1.0 3.98e+04 - 2.28e-01 5.98e-02h 1  
7 3.9559026e+06 3.96e+06 3.30e+02 -1.0 2.14e+06 - 1.30e-03 7.28e-02h 1  
8 3.6923996e+06 3.69e+06 1.66e+04 -1.0 2.11e+06 - 9.64e-01 6.65e-02f 1  
9 3.6829293e+06 3.68e+06 3.43e+06 -1.0 1.21e+06 - 4.64e-01 2.64e-03h 1  
iter objective inf\_pr inf\_du lg(mu) ||d|| lg(rg) alpha\_du alpha\_pr ls  
10 3.6826617e+06 3.68e+06 3.64e+10 -1.0 1.29e+06 - 8.01e-01 7.52e-05h 1  
11r 3.6826617e+06 3.68e+06 1.00e+03 0.0 0.00e+00 - 0.00e+00 3.87e-07R 2  
12r 3.6908606e+06 3.69e+06 2.59e+03 0.0 8.06e+06 - 1.66e-01 6.94e-02f 1  
13r 3.6937542e+06 3.69e+06 3.32e+03 0.0 1.48e+06 - 5.95e-01 4.61e-01f 1  
14r 3.6977536e+06 3.70e+06 7.26e+01 0.0 4.19e+05 - 9.90e-01 1.00e+00f 1  
15r 3.6856485e+06 3.69e+06 2.51e-01 -0.7 4.34e+03 - 9.90e-01 1.00e+00f 1  
16r 3.6826775e+06 3.68e+06 2.56e-01 -3.1 7.65e+03 - 9.82e-01 1.00e+00f 1  
17r 3.6826742e+06 3.68e+06 9.76e-09 -3.1 2.24e+04 - 1.00e+00 1.00e+00h 1  
18r 3.6826589e+06 3.68e+06 1.42e-02 -6.9 9.01e+04 - 8.12e-01 1.00e+00f 1  
19r 3.6826589e+06 3.68e+06 7.64e-05 -6.9 4.68e+03 - 9.95e-01 1.00e+00h 1  
iter objective inf\_pr inf\_du lg(mu) ||d|| lg(rg) alpha\_du alpha\_pr ls  
20r 3.6826589e+06 3.68e+06 2.24e-12 -6.9 3.85e+05 - 1.00e+00 1.00e+00h 1  
21r 3.6826589e+06 3.68e+06 1.16e-06 -9.0 1.19e+05 - 9.01e-01 1.00e+00h 1

Number of Iterations…: 21

```
                               (scaled) (unscaled)

```

Objective…: 1.1119148000463026e+00 3.6826588716262570e+06  
Dual infeasibility…: 1.8194951921996108e+01 6.0261632556345068e+07  
Constraint violation…: 1.1119137432821691e+00 3.6826553716262467e+06  
Variable bound violation: 9.8364835139364004e-05 9.8364835139364004e-05  
Complementarity…: 2.0231348240894247e-08 6.7006171768904332e-02  
Overall NLP error…: 1.1119137432821691e+00 6.0261632556345068e+07

Number of objective function evaluations = 25  
Number of objective gradient evaluations = 13  
Number of equality constraint evaluations = 0  
Number of inequality constraint evaluations = 25  
Number of equality constraint Jacobian evaluations = 0  
Number of inequality constraint Jacobian evaluations = 24  
Number of Lagrangian Hessian evaluations = 22  
Total seconds in IPOPT = 0.027

EXIT: Converged to a point of local infeasibility. Problem may be infeasible.  
termination\_status(Cs) = MathOptInterface.LOCALLY\_INFEASIBLE  
LOCALLY\_INFEASIBLE::TerminationStatusCode = 5

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [May 13, 2024, 7:55am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/6 "2024-05-13T07:55:51Z")

</div>

And are you sure that that’s not the case, i.e. that the problem is feasible? Have you solved it analytically, or using some other numerical solver?

---

<div class="post-metadata">

**Author:** ![nouha941](https://avatars.discourse-cdn.com/v4/letter/n/3e96dc/32.png) [@nouha941](https://discourse.julialang.org/u/nouha941)\
**Post date:** [May 13, 2024, 8:01am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/7 "2024-05-13T08:01:23Z")

</div>

I used this equation to calculate the actual values for eight train scenarios, and it provided me with correct results. However, I haven’t tested analytical optimization (I haven’t found a suitable method for this problem).

---

<div class="post-metadata">

**Author:** ![nouha941](https://avatars.discourse-cdn.com/v4/letter/n/3e96dc/32.png) [@nouha941](https://discourse.julialang.org/u/nouha941)\
**Post date:** [May 13, 2024, 8:10am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/8 "2024-05-13T08:10:11Z")

</div>

The solver does not support an objective function of type MathOptInterface.ScalarNonlinearFunction.

---

<div class="post-metadata">

**Author:** ![blob](https://avatars.discourse-cdn.com/v4/letter/b/ebca7d/32.png) [@blob](https://discourse.julialang.org/u/blob)\
**Post date:** [May 13, 2024, 10:32am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/9 "2024-05-13T10:32:51Z")

</div>

The left-hand side of the constraint `constraint1` is the same as the objective, is this intended? When I removed `constraint1`, I got Ipopt to find a solution. Is this constraint expected to be feasible with 3.5 on the right-hand side?

On a technical note, putting the code between three backticks ``` helps with formatting 🙂

```julia
using JuMP, Ipopt
Cs = Model(Ipopt.Optimizer)
#Declaring variables
@variable(Cs, 3500.000277778<= Q_e <= 4500.000277778)
@variable(Cs, 2e5<= PT401 <= 5e5)
@variable(Cs, 45e5<= PT501 <= 70e5)
@variable(Cs, 25e5<= P <= 42.1e5)
@variable(Cs, 1250.000277778<= Qp <= 2200.000277778)
@variable(Cs, 0.8<= R_m <= 0.96)
@variable(Cs, 0.7<= R_p <= 0.9)
@variable(Cs, 45e5<= PT502 <= 56e5)

#setting the objecj=tive
@objective(Cs, Min, (((Q_e*(PT501-PT401))-(Q_e*(PT501-P)))/(R_m*R_p))*(1/Qp))

#Adding constraints
# @constraint(Cs, constraint1, (((Q_e*(PT501-PT401))-(Q_e*(PT501-P)))/(R_m*R_p))*(1/Qp) <= 3.5)
@constraint(Cs, constraint2, PT502-PT501 <= 4e5)

# #Printing the prepared optimization model
print(Cs)
#Solving the optimization problem
JuMP.optimize!(Cs)

```

---

<div class="post-metadata">

**Author:** ![nouha941](https://avatars.discourse-cdn.com/v4/letter/n/3e96dc/32.png) [@nouha941](https://discourse.julialang.org/u/nouha941)\
**Post date:** [May 13, 2024, 5:11pm UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/10 "2024-05-13T17:11:38Z")

</div>

Normally, constraint1 should be feasible. Anyway, thank you so much, really appreciate it.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 14, 2024, 5:37am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/11 "2024-05-14T05:37:59Z")

</div>

Hi @nouha941, welcome to the forum.

You should take a deeper look at your problem. You must have some typos somewhere, because the problem as written is infeasible.

Unless I’ve made a typo, I can simplify your constraint to:

```Julia
(((Q_e*(PT501-PT401))-(Q_e*(PT501-P)))/(R_m * R_p)) * (1/Qp)
 = ((Q_e * (PT501 - PT401) - Q_e * (PT501 - P)) / (R_m * R_p)) / Qp
 = (Q_e * (PT501 - PT401) - Q_e * (PT501 - P)) / (R_m * R_p) / Qp
 = (Q_e * (PT501 - PT401) - Q_e * (PT501 - P)) / (R_m * R_p * Qp)
 = Q_e * ((PT501 - PT401) - (PT501 - P)) / (R_m * R_p * Qp)
 = Q_e * (PT501 - PT401 - PT501 + P) / (R_m * R_p * Qp)
 = Q_e * (P - PT401) / (R_m * R_p * Qp)

```

This has a lower bound of

```julia
julia> 3500.000277778 * (25e5 - 5e5) / (0.96 * 0.9 * 2200.000277778)
3.6826597599520995e6

```

which is much greater than 3.5

---

<div class="post-metadata">

**Author:** ![nouha941](https://avatars.discourse-cdn.com/v4/letter/n/3e96dc/32.png) [@nouha941](https://discourse.julialang.org/u/nouha941)\
**Post date:** [May 14, 2024, 8:16am UTC](https://discourse.julialang.org/t/nonlinear-optimization-fails-with-jump-infeasible/114190/12 "2024-05-14T08:16:22Z")

</div>

Many thanks sir, I really appreciate your help
