odow / SDDP.jl

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

Random Variable in the Objective Function #318

Closed marykh162 closed 4 years ago

marykh162 commented 4 years ago

Hi, I have a question about randomness in the objective function. The following is my model's objective function:

SDDP.parameterize(sp, support1, probability1) do ω
    @stageobjective(sp, co*z.out + ca*pp.out + cw*sta2*w.out + cr[1]*(ω.EC-v[1]) + cr[2]*(ω.transfer-v[2])+cr[3]*(ω.direct-v[3]))
    set_upper_bound(v[1], ω.EC)
    set_upper_bound(v[2], ω.transfer)
    set_upper_bound(v[3], ω.direct)
end

I was able to use SDDP.jl to solve my model. Now, I need help with visualization. I am interested to generate the ribbon plots for the following deviations:  ω.EC-v[1]    ω.transfer-v[2]    ω.direct-v[3]   But, I do not know how to deal with the random variable. I would appreciate you help with this. Thanks!

odow commented 4 years ago

I guess you want something like

simulations = SDDP.simulate(model, 100, [:v])

plt = SDDP.SpaghettiPlot(simulations)
SDDP.add_spaghetti(plt) do data
    return data[:v][1] - data[:noise_term].EC
end
SDDP.plot(plt)

# Or

using Plots
SDDP.publication_plot(simulations) do data
    return data[:v][1] - data[:noise_term].EC
end,
marykh162 commented 4 years ago

I guess you want something like

simulations = SDDP.simulate(model, 100, [:v])

plt = SDDP.SpaghettiPlot(simulations)
SDDP.add_spaghetti(plt) do data
    return data[:v][1] - data[:noise_term].EC
end
SDDP.plot(plt)

# Or

using Plots
SDDP.publication_plot(simulations) do data
    return data[:v][1] - data[:noise_term].EC
end,

Thanks for your reply. I tried this and I am getting the following error: ERROR: LoadError: type Nothing has no field EC

odow commented 4 years ago

Presumably you only use parameterize in some stages? Then you want something like this:

SDDP.add_spaghetti(plt) do data
    if data[:noise_term] === nothing
        return 0.0
    end
    return data[:v][1] - data[:noise_term].EC
end
marykh162 commented 4 years ago

Presumably you only use parameterize in some stages? Then you want something like this:

SDDP.add_spaghetti(plt) do data
    if data[:noise_term] === nothing
        return 0.0
    end
    return data[:v][1] - data[:noise_term].EC
end

Yes, I do not use parameterize in the first stage. Thank you so much! It is working now.

marykh162 commented 4 years ago

Hi again,

I have another question related to random variables in the objective function. I am trying to add a constraint which contains the same random variables as the objective function. Could you please help me with that?

Thanks!

odow commented 4 years ago

See this tutorial: https://odow.github.io/SDDP.jl/latest/tutorial/03_objective_uncertainty/

Essentially, just use ω in both places:

SDDP.parameterize(sp, Ω) do ω
    set_normalized_rhs(c, ω)
    @stageobjective(sp, ω * x)
end
odow commented 4 years ago

Is this resolved?

marykh162 commented 4 years ago

Yes, it is. Thanks a lot!

On Tue, Jun 9, 2020 at 4:39 PM Oscar Dowson notifications@github.com wrote:

Is this resolved?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/odow/SDDP.jl/issues/318*issuecomment-641596657__;Iw!!KwNVnqRv!XqrJdCnhkFomicEaa10OK2RLVnrTJzLlLONToF0jFwGtw8HZpD1ExZ-fzajLOoKRIDqE$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AOZKHKVEXDXTWYKI44CT4VDRV2T2ZANCNFSM4M3YHVSA__;!!KwNVnqRv!XqrJdCnhkFomicEaa10OK2RLVnrTJzLlLONToF0jFwGtw8HZpD1ExZ-fzajLOhFha_wf$ .

--

Maryam Khatami

Ph.D. Candidate

Department of Industrial and Systems Engineering

4050 ETB, 3131 TAMU

Texas A&M University

College Station, TX 77843