Hi,
I’m testing the StochasticPrograms.jl package (Awesome work by the way!) on a simple renewables energy sizing use case. I have difficulty figuring out how to use uncertain parameters in the 2nd stage with array inputs.
All the examples I found declare single numbers.
What is the right way to declare uncertain parameters that are indexed both with a symbol and time index?
Here is where I’m at after reading parts of the documentation. It leads to an error but that’s probably that I’m not using the syntax right:
using StochasticPrograms, Cbc
horizon = 2
@scenario ResScenario = begin
solar::Vector{Float64}
wind_offshore::Vector{Float64}
wind_onshore::Vector{Float64}
@zero begin
return ResScenario([0., 0.], [0., 0.], [0., 0.])
end
end
res_model = @stochastic_model begin
@stage 1 begin
@parameters begin
sources = [:solar, :wind_offshore, :wind_onshore]
capex = Dict(
:solar => 100,
:wind_offshore => 150,
:wind_onshore => 120)
end
@decision(model, capacity[s in sources] >= 0)
@objective(model, Min,
sum(capex[s] * capacity[s] for s in sources))
end
@stage 2 begin
@parameters begin
time = 1:horizon
sources = [:solar, :wind_offshore, :wind_onshore]
import_cost = 10_000
demand = 10
end
@uncertain profile::ResScenario
@variable(model, imports[t = time] >= 0)
@variable(model, curtailed[t = time] >= 0)
@objective(model, Min, sum(import_cost * imports[t] for t in time ))
@expression(model, generation[t = time],
sum(getproperty(profile, s)[t] * capacity[s] for s in sources))
@constraint(model, supply_demand_balance[t = time],
generation[t] + imports[t] - curtailed[t] == demand)
end
end
ξ₁ = ResScenario([0.5, 0.5], [0.1, 0.1], [0.5, 0.5], probability = 1/3)
ξ₂ = ResScenario([0.1, 0.1], [0.3, 0.3], [0.5, 0.5], probability = 1/3)
ξ₃ = ResScenario([0., 0.], [0.7, 0.7], [0.3, 0.3], probability = 1/3)
res = instantiate(res_model, [ξ₁,ξ₂,ξ₃], optimizer = Cbc.Optimizer)
optimize!(res)
objective_value(res)
optimal_decision(res)
Thanks!