How to optimize a function in jump that contains an array in the objective function?
I have the following constraint optimization problem in jump:
m = Model(optimizer_with_attributes(Mosek.Optimizer, "QUIET" => false, "INTPNT_CO_TOL_DFEAS" => 1e-7))
N = 2
function Q_r(i::Number, l::Number, r::Number, tau::Float64)
if i >= r && l >= r
return 2 * fac1(r, i, l) * fac2(r, i, l, tau)
else
return 0.0
end
end
function Q(i::Number, l::Number, tau::Number)
elem = 0
for r in 0:N
println(penalties[r + 1], Q_r(i, l, r, tau))
elem += penalties[r + 1] * Q_r(i, l, r, tau)
end
return elem
end
Q_mat = Array{Float64, 2}(undef, N+1, N+1)
for i in 1:N+1
for j in 1:N+1
Q_mat[i, j] = Q(i, j, 0.0)
end
end
@variable(m, p)
@objective(m, Min, p'*Q_mat*p)
I want to minimize p’Q_matp, where p is a vector of N+1. But I’m getting the following error:
ERROR: LoadError: The objective function `GenericQuadExpr{Float64,VariableRef}[0 0 0; 0 0 0; 0 0 0]` is not supported by JuMP.
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] set_objective_function(::Model, ::Array{GenericQuadExpr{Float64,VariableRef},2}) at /Users/prikshetsharma/.julia/packages/JuMP/qhoVb/src/objective.jl:123
[3] set_objective(::Model, ::MathOptInterface.OptimizationSense, ::Array{GenericQuadExpr{Float64,VariableRef},2}) at /Users/prikshetsharma/.julia/packages/JuMP/qhoVb/src/objective.jl:128
[4] top-level scope at /Users/prikshetsharma/.julia/packages/JuMP/qhoVb/src/macros.jl:831
[5] top-level scope at /Users/prikshetsharma/Documents/clotorch/src/clotorch/flight/trajectory.jl:107
[6] include(::Function, ::Module, ::String) at ./Base.jl:380
[7] include(::Module, ::String) at ./Base.jl:368
[8] exec_options(::Base.JLOptions) at ./client.jl:296
[9] _start() at ./client.jl:506
in expression starting at /Users/prikshetsharma/Documents/clotorch/src/clotorch/flight/trajectory.jl:107
How to do the optimization if this objective function isn’t supported?