In your function functs_BK1
, you have defined f
to be an array of Float64
values, while the @NLexpression
macro must build up the desired expression from JuMP variables as its third argument. As stated in the JuMP documentation for Nonlinear Expressions, all nonlinear expressions must be defined inside of the @NLexpression
macro, and AffExpr
and QuadExpr
objects cannot currently be used inside of the @NLexpression
macro.
The following set of commands results in finding a solution via the solve
operation:
julia> using JuMP
julia> using Ipopt
julia> m = Model(solver=IpoptSolver(print_level=0))
Feasibility problem with:
* 0 linear constraints
* 0 variables
Solver is Ipopt
julia> @variable(m, x[i=1:2])
2-element Array{JuMP.Variable,1}:
x[1]
x[2]
julia> function bounds_BK1()
return ([-5.0;-5.0],[10.0;10.0])
end
bounds_BK1 (generic function with 1 method)
julia> @NLexpression(m, F1, x[1]^2 + x[2]^2)
JuMP.NonlinearExpression(Feasibility problem with:
* 0 linear constraints
* 2 variables
Solver is Ipopt,1)
julia> @NLexpression(m, F2, (x[1]-5.0)^2 + (x[2]-5.0)^2)
JuMP.NonlinearExpression(Feasibility problem with:
* 0 linear constraints
* 2 variables
Solver is Ipopt,2)
julia> @constraint(m, x .>= bounds_BK1()[1])
2-element Array{JuMP.ConstraintRef{JuMP.Model,JuMP.GenericRangeConstraint{JuMP.GenericAffExpr{Float64,JuMP.Variable}}},1}:
x[1] ≥ -5
x[2] ≥ -5
julia> @constraint(m, x .<= bounds_BK1()[2])
2-element Array{JuMP.ConstraintRef{JuMP.Model,JuMP.GenericRangeConstraint{JuMP.GenericAffExpr{Float64,JuMP.Variable}}},1}:
x[1] ≤ 10
x[2] ≤ 10
julia> s = solve(m)
******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
Ipopt is released as open source code under the Eclipse Public License (EPL).
For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************
:Optimal
julia> getvalue(x)
2-element Array{Float64,1}:
0.261454
0.261454
I do not believe that it is currently possible for you to build up an array of expressions within your functs_BK1
that would later be passed to @NLexpression
. At present, one needs to pass the scalar expressions of JuMP variables directly in as arguments to @NLexpression
.