odow / SDDP.jl

A JuMP extension for Stochastic Dual Dynamic Programming
https://sddp.dev
Other
293 stars 62 forks source link

trouble with sum #731

Closed SerenaZwww closed 7 months ago

SerenaZwww commented 7 months ago

I'm new to Julia and this package, so my question may be stupid... but I just can't figure it out...

I have a state variable with three indexes, say s_{i,j,k}. I add it by:

set1 = [1, 2, 3]
set2 = [0, 1, 2]
set3 = [0, 1, 2]
initial_state(i, j, k) = 0
 @variable(
            subproblem,
            0 <= s[i = set1, j = set2, k = set3] <= 1,
            SDDP.State,
            initial_value = initial_state(i, j, k)
        )

I want to add the constraint: $$ \sum{j} \sum{k} s_{i,j,k}=1, \forall i $$ And I tried to achieve it by:

@constraints(
        subproblem,
        begin
            [i in set1],
            sum(s[i, :, :]) == 1
        end
)

But there is something wrong...

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

Does anyone know why...

odow commented 7 months ago

Hi @SerenaZwww, I guess you figured this out, but you need

sum(s[i, j, k].out for j in set2, k in set3) == 1
SerenaZwww commented 7 months ago

@odow Exactly, thanks!