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]