trouble with sum
SerenaZwww opened this issue · comments
SerenaZwww commented
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...
Oscar Dowson commented
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
@odow Exactly, thanks!