I’ll illustrate the problem with the following simple example:
import JuMP
l = ones(4)
model= JuMP.Model()
JuMP.@variable(model, x)
JuMP.@variable(model, y1)
JuMP.@variable(model, y2)
epxr = [
JuMP.@expression(model, y1 - 1),
JuMP.@expression(model, y2 - 2)]
In my objective function I want to have the scalar product of l
and expr
.
This does not work:
JuMP.@objective(model, Min, x * 3 + l[2:3]' * epxr))
MethodError: no method matching add_to_expression!(::GenericAffExpr{Float64,VariableRef}, ::Adjoint{Float64,Array{Float64,1}}, ::Array{GenericAffExpr{Float64,VariableRef},1})
FYI: If you would remove the term x * 3
it would work.
This does work:
JuMP.@objective(model, Min, x * 3 + sum(l[2:3] .* epxr))
This does too:
exp2 = l[2:3]' * epxr
JuMP.@objective(model, Min, x * 3 + exp2)
Why?