Non-linear optimization with Ipopt

Hi everyone I am new to Juila and working on non-linear optimization problem with Ipopt solver. Here are my code and my third constraint is 0.0653 * (2 * x[2])^-2 <= 30. However, I am getting [0, 0] and it seems like Ipopt cant solve x^-2. Any insight would be helpful.
Thank you

using JuMP, Ipopt

m = Model(Ipopt. Optimizer)

@ variable(m, x[1:2])

@ NLobjective(m, Min, pi*(x[1] + x[2])^2)

@ NLconstraint(m, x[1]>=.254)

@ NLconstraint(m, 0.020<=x[2]<=0.125)

@ NLconstraint(m, 0.0653 * (2* x[2])^-2 <= 30)


JuMP.optimize!(m)

println(" Optimal Objective function value =", JuMP.objective_value(m))

println(" Optimal solution =", JuMP.value.(x))
1 Like

Hi @bada5150, welcome to the forum.

There are a few things going on:

You must always check whether the solver found a solution before querying value. See Solutions · JuMP. In this case, solution_summary(m) would tell you:

julia> solution_summary(m)
* Solver : Ipopt

* Status
  Result count       : 1
  Termination status : INVALID_MODEL
  Message from the solver:
  "Invalid_Number_Detected"

* Candidate solution (result #1)
  Primal status      : UNKNOWN_RESULT_STATUS
  Dual status        : UNKNOWN_RESULT_STATUS
  Objective value    : 0.00000e+00
  Dual objective value : 0.00000e+00

* Work counters
  Solve time (sec)   : 1.16706e-03
  Barrier iterations : 0

Ipopt found an invalid number because it tried x[2] = 0 as a solution, which is undefined because of the x[2]^-2.

Ipopt tried this value because the default starting point is x = 0, and no bounds were specified.

Instead of writing bounds as @NLconstraint(m, 0.020<=x[2]<=0.125), you should instead declare them when creating the variable: @variable(m, 0.020 <= x <= 0.125).

As another minor point, the @NL interface is now legacy. You can use the regular @objective and @constraint macros. See Nonlinear Modeling · JuMP.

Here is how I would write your model:

using JuMP, Ipopt
model = Model(Ipopt.Optimizer)
l = [0.254, 0.020]
u = [Inf, 0.125]
@variable(model, l[i] <= x[i in 1:2] <= u[i])
@objective(model, Min, pi * (x[1] + x[2])^2)
@constraint(model, 0.0653 * (2 * x[2])^-2 <= 30)
optimize!(model)
@assert is_solved_and_feasible(model)
println("Optimal Objective function value =", objective_value(model))
println("Optimal solution =", value.(x))

It returns:

julia> println("Optimal Objective function value =", objective_value(model))
Optimal Objective function value =0.24162137335214304

julia> println("Optimal solution =", value.(x))
Optimal solution =[0.2539999914381088, 0.02332738162717634]
1 Like