odow / SDDP.jl

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

How to make so an stochastic variable behaves in a deterministic way in certain stages #491

Closed Misoto3 closed 2 years ago

Misoto3 commented 2 years ago

Hi Oscar,

Im trying to run a model in which I have 10 samples for every stage of a stochastic variable and I want that for certain stages in the model, the uncertainty takes for example sample 4, and mantains the realizations of the stochastic variable only for the components of that sample (4) in t+1, t+2, etc. In short, I want to make so that in certain stages the variable is stochastic and in other set of stages the variable is deterministic in a sense.

For an concrete example, if I hace that for every stage the samples are: Sample stage1 stage2 stage3 stage4 stage5 stage6 stage7 stage8 stage9 stage10 1 3 4 6 5 7 8 9 12 1 0 2 1 3 5 6 2 3 7 11 3 4 3 2 7 9 12 3 4 5 6 2 3 4 5 2 3 1 9 6 4 10 4 2

And I want that stages 4, 5 and 6 behave in this way, I want the model to do the following:

  1. For stages 1 to 3, the variable is stochastic and can take any of the samples corresponding to stages 1, 2 and 3.
  2. For stages 4 to 6, the variable chooses a sample randomly, for example 4 (could be 1, 2, 3 or 4 in the simulations), and mantains that sample realizations for stages 5 and 6. In this case the variable would take values 1, 9 and 6 for stages 4, 5 and 6 respectively.
  3. For stages 7 to 10, the variable is stochastic and can take any of the samples corresponding to stages 7, 8, 9 and 10.

If something is not clear, please feel free to ask, best regards, Matías Soto

odow commented 2 years ago

Use a custom policy graph: https://odow.github.io/SDDP.jl/latest/tutorial/basic/04_markov_uncertainty/ https://odow.github.io/SDDP.jl/latest/guides/create_a_general_policy_graph/

data = [
    3 4 6 5 7 8 9 12 1 0
    1 3 5 6 2 3 7 11 3 4
    2 7 9 12 3 4 5 6 2 3
    5 2 3 1 9 6 4 10 4 2
]
I = zeros(4, 4)
for i in 1:4
    I[i, i] = 1.0
end
SDDP.MarkovianPolicyGraph(
    [
        fill(0.25, 1, 4),  # Stage 0 -> 1
        fill(0.25, 4, 4),  # Stage 1 -> 2
        fill(0.25, 4, 4),  # Stage 2 -> 3
        fill(0.25, 4, 4),  # Stage 3 -> 4
        I,                 # Stage 4 -> 5
        I,                 # Stage 5 -> 6
        fill(0.25, 4, 4),  # Stage 6 -> 7
        fill(0.25, 4, 4),  # Stage 7 -> 8
        fill(0.25, 4, 4),  # Stage 8 -> 9
        fill(0.25, 4, 4),  # Stage 9 -> 10
    ]
) do sp, node
    t, row = node
    sample = data[t, row]
end
odow commented 2 years ago

Closing due to lack of follow-up. If you have further questions, please re-open the issue.