簡體   English   中英

目標 function `GenericQuadExpr{Float64,VariableRef}[0 0 0; 0 0 0; JuMP 不支持 0 0 0]`

[英]The objective function `GenericQuadExpr{Float64,VariableRef}[0 0 0; 0 0 0; 0 0 0]` is not supported by JuMP

如何在包含目標 function 中的數組的跳轉中優化 function?

我在跳轉中有以下約束優化問題:

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)

我想最小化 p' Q_mat p,其中 p 是 N+1 的向量。 但我收到以下錯誤:

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

如果不支持此目標 function,如何進行優化?

你需要指出p是一個向量:

julia> N = 3
3

julia> Q = rand(N,N)
3×3 Array{Float64,2}:
 0.340114  0.0884307  0.634788
 0.472685  0.782036   0.977641
 0.797464  0.608125   0.741983

julia> m = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> @variable(m, pp)
pp

julia> @variable(m, p[1:N])
3-element Array{VariableRef,1}:
 p[1]
 p[2]
 p[3]

julia> pp'*Q*pp
3×3 Array{GenericQuadExpr{Float64,VariableRef},2}:
 0.3401136703186225 pp²  0.08843073433149629 pp²  0.6347879182799103 pp²
 0.4726848249844562 pp²  0.7820361890132028 pp²   0.9776406368494128 pp²
 0.7974640186429511 pp²  0.6081254843767614 pp²   0.7419832389329017 pp²

julia> @objective(m, Min, p'*Q*p)
0.3401136703186225 p[1]² + 0.5611155593159525 p[1]*p[2] + 1.4322519369228615 p[1]*p[3] + 0.7820361890132028 p[2]² + 1.5857661212261742 p[2]*p[3] + 0.7419832389329017 p[3]²

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM