SDDP:MethodError: no method matching *(::Float64, ::SDDP.State{VariableRef})

This is a bit of a confusing error, but c_u * u is a 1x1 matrix.

julia> c_u * rand(6)
1-element Vector{Float64}:
 12.597665667602827

SDDP.jl doesn’t know how to deal with stage-objectives that are vector-valued.

Make c_u a vector first, then do c_u' * u.

using SDDP
a = fill(2.0, 10)
a[1] = 3.0
a[2] = 4.0
ini_a = ones(10)
c_a = ones(10)
c_u = [4, 3, 7, 5, 1, 7]
model = SDDP.LinearPolicyGraph(
    stages = 3,
    sense = :Min,
    lower_bound = 0.0,
) do sp, node
    @variable(sp, 0 <= a_v[i=1:10] <= a[i], SDDP.State, initial_value = ini_a[i])
    @variable(sp, 0 <= u[1:6] <= 1, Bin)
    @stageobjective(sp, sum(c_a[i] * a_v[i].out for i=1:10) + c_u' * u)
end

Edit: I’ve opened an issue to improve things: Sanitize stageobjective macro · Issue #404 · odow/SDDP.jl · GitHub

1 Like