Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trouble with sum #731

Closed
SerenaZwww opened this issue Feb 9, 2024 · 2 comments
Closed

trouble with sum #731

SerenaZwww opened this issue Feb 9, 2024 · 2 comments

Comments

@SerenaZwww
Copy link

SerenaZwww commented Feb 9, 2024

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
Copy link
Owner

odow commented Feb 10, 2024

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
Copy link
Author

SerenaZwww commented Feb 10, 2024

@odow Exactly, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants