# How to define multiple random variables in SDDP

**URL:** https://discourse.julialang.org/t/how-to-define-multiple-random-variables-in-sddp/94231
**Category:** Optimization (Mathematical)
**Tags:** question, jump
**Created:** [February 7, 2023, 7:21pm UTC](https://discourse.julialang.org/t/how-to-define-multiple-random-variables-in-sddp/94231 "2023-02-07T19:21:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Sorooshsa](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@Sorooshsa](https://discourse.julialang.org/u/Sorooshsa)
#### Post date: [February 7, 2023, 7:21pm UTC](https://discourse.julialang.org/t/how-to-define-multiple-random-variables-in-sddp/94231/1 "2023-02-07T19:21:00Z")

</div>

Hi everyone,  
I have a small stochastic hydropower problem. As you may know, water inflows are considered random variables in most hydropower problems, just like my problem.  
There is a well-structured example here:

[https://odow.github.io/SDDP.jl/stable/tutorial/first\_steps/#An-introduction-to-SDDP.jl](https://odow.github.io/SDDP.jl/stable/tutorial/first_steps/#An-introduction-to-SDDP.jl)

In this example, there is only one reservoir, so we have only one random inflow variable.  
Now imagine we have two consecutive reservoirs that are connected. The output of the first reservoir is the input of the second reservoir.  
Just like the example in the link, we have state variables (but two variables) for the water level in the reservoirs and two decision variables for hydro and thermal generation for each reservoir.

Now my question is how we can define random variables in this structure. Defining the second random variable is exactly like the first random variable? What if there is a relation between the random variables (for example huge inflow in one reservoir means a huge inflow in the other reservoir)

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [February 7, 2023, 7:51pm UTC](https://discourse.julialang.org/t/how-to-define-multiple-random-variables-in-sddp/94231/2 "2023-02-07T19:51:01Z")

</div>

See [Add multi-dimensional noise terms · SDDP.jl](https://odow.github.io/SDDP.jl/stable/guides/add_multidimensional_noise/)

Here’s another example: [Newsvendor · SDDP.jl](https://odow.github.io/SDDP.jl/stable/examples/objective_state_newsvendor/)

---

<div class="post-metadata">

### Author: ![Sorooshsa](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@Sorooshsa](https://discourse.julialang.org/u/Sorooshsa)
#### Post date: [February 8, 2023, 6:39pm UTC](https://discourse.julialang.org/t/how-to-define-multiple-random-variables-in-sddp/94231/3 "2023-02-08T18:39:58Z")

</div>

Thank you.  
I managed to develop my model in Julia.  
Now, I have another question.  
How can I evaluate my decision rule when I have a two-dimensional term?  
And also, I do not theoretically understand the difference between evaluation and simulation in SDDP.jl.  
Do you have any web references to help me understand?

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [February 8, 2023, 6:44pm UTC](https://discourse.julialang.org/t/how-to-define-multiple-random-variables-in-sddp/94231/4 "2023-02-08T18:44:17Z")

</div>

The secret is that there is no multidimensional noise term. It’s just a single vector of outcomes with a corresponding vector of probabilities.

In this example:

```julia
julia> model = SDDP.LinearPolicyGraph(
               stages=3, lower_bound = 0, optimizer = HiGHS.Optimizer
               ) do subproblem, t
           @variable(subproblem, x, SDDP.State, initial_value = 0.0)
           support = [(value = v, coefficient = c) for v in [1, 2] for c in [3, 4, 5]]
           probability = [v * c for v in [0.5, 0.5] for c in [0.3, 0.5, 0.2]]
           SDDP.parameterize(subproblem, support, probability) do ω
               JuMP.fix(x.out, ω.value)
               @stageobjective(subproblem, ω.coefficient * x.out)
               println("ω is: ", ω)
           end
       end;

```

you’d use something like

```julia
rule = SDDP.DecisionRule(model; node = 1)
solution = SDDP.evaluate(
    rule;
    incoming_state = Dict(:x => 0.0),
    noise = (value = 1, coefficient = 3),
)

```

> I do not theoretically understand the difference between evaluation and simulation in SDDP.jl.

There’s no real difference. Simulation is just a sequence of evaluating the decision rules.

---

<div class="post-metadata">

### Author: ![Sorooshsa](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@Sorooshsa](https://discourse.julialang.org/u/Sorooshsa)
#### Post date: [February 8, 2023, 6:50pm UTC](https://discourse.julialang.org/t/how-to-define-multiple-random-variables-in-sddp/94231/5 "2023-02-08T18:50:48Z")

</div>

Thank you.  
And if we have multiple (e.g., two state variables X1 and X2), how should we write the incoming\_state in SDDP.evaluate?

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [February 8, 2023, 6:52pm UTC](https://discourse.julialang.org/t/how-to-define-multiple-random-variables-in-sddp/94231/6 "2023-02-08T18:52:25Z")

</div>

`incoming_state = Dict(:X1 => 0.0, :X2 => 0.0),`

I usually find it more convenient to just call `SDDP.simulate` and then post-process the results, rather than trying to evaluate individual decisions rules.
