Skip to content

Commit

Permalink
Merge pull request #14 from Thiago-NovaesB/tn/infinite_horizon
Browse files Browse the repository at this point in the history
Add infinity horizon
  • Loading branch information
Thiago-NovaesB authored Oct 8, 2023
2 parents 9f3b0da + 57ea730 commit 90994a2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HydroPowerModels"
uuid = "1bf2e10f-7293-4f36-bafb-f7584ca75eae"
authors = ["andrewrosemberg <andrewrosemberg@gmail.com>"]
version = "0.4.2"
version = "0.5.0"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
37 changes: 35 additions & 2 deletions examples/HydroValleys/case3deterministic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,35 @@ results = HydroPowerModels.simulate(m, 1);
atol=1e-2,
)

########################################
# Build Model: infinite horizon
########################################
params_cycle_probability = create_param(;
stages=12,
model_constructor_grid=DCPPowerModel,
post_method=PowerModels.build_opf,
optimizer=GLPK.Optimizer,
cycle_probability=0.6,
);
m = hydro_thermal_operation(alldata, params_cycle_probability)

########################################
# Solve
########################################
HydroPowerModels.train(m; iteration_limit=60);

########################################
# Simulation
########################################
results_cycle_probability = HydroPowerModels.simulate(m, 1);

########################################
# Test
########################################
# 1/(1-0.6) = 2.5 > 2
@test results_cycle_probability[:simulations][1][1][:objective] >
2 * results[:simulations][1][1][:objective]

########################################
# Build Model: min final volume violation
########################################
Expand All @@ -81,7 +110,9 @@ results = HydroPowerModels.simulate(m, 1);
########################################
# Test
########################################
@test results[:simulations][1][end][:reservoirs][:reservoir][1].out >= 0.4
@test isapprox(
results[:simulations][1][end][:reservoirs][:reservoir][1].out, 0.4, atol=1e-2
)

########################################
# Build Model: min vol violation
Expand All @@ -107,7 +138,9 @@ results = HydroPowerModels.simulate(m, 1);
########################################
# Test
########################################
@test results[:simulations][1][end][:reservoirs][:reservoir][1].out >= 0.2
@test isapprox(
results[:simulations][1][end][:reservoirs][:reservoir][1].out, 0.2, atol=1e-2
)

########################################
# Build Model: min turb violation
Expand Down
63 changes: 37 additions & 26 deletions src/IO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,45 +86,56 @@ end

"""
create_param(;stages::Int = 1,
model_constructor_grid = DCPPowerModel,
model_constructor_grid_backward = model_constructor_grid,
model_constructor_grid_forward = model_constructor_grid_backward,
post_method = PowerModels.build_opf,
optimizer = GLPK.Optimizer,
optimizer_backward = optimizer,
optimizer_forward = optimizer_backward,
setting = Dict("output" => Dict("branch_flows" => true,"duals" => true)),
verbose = false,
stage_hours = 1)
model_constructor_grid::Type = DCPPowerModel,
model_constructor_grid_backward::Type = model_constructor_grid,
model_constructor_grid_forward::Type = model_constructor_grid_backward,
post_method::Function = PowerModels.build_opf,
optimizer::DataType = GLPK.Optimizer,
optimizer_backward::DataType = optimizer,
optimizer_forward::DataType = optimizer_backward,
setting::Dict = Dict("output" => Dict("branch_flows" => true,"duals" => true)),
verbose::Bool = false,
stage_hours::Int = 1,
discount_factor::Float64 = 1.0,
cycle_probability::Float64 = 0.0)
Create Parameters Dictionary.
Keywords are:
- stages::Int : Number of stages.
- model_constructor_grid : Network formulation (Types from <https://github.com/lanl-ansi/PowerModels.jl>).
- optimizer : Optimizer factory (<http://www.juliaopt.org/JuMP.jl/v0.19.0/solvers/>).
- setting : PowerModels settings (<https://github.com/lanl-ansi/PowerModels.jl/blob/e28644bf85232a5322adeeb847c0d18b7ff4f235/src/core/base.jl#L6-L34>)) .
- verbose : Boolean to indicate information prints.
- stage_hours : Number of hours in each stage.
- stages::Int : Number of stages.
- model_constructor_grid : Default Network formulation (Types from <https://github.com/lanl-ansi/PowerModels.jl>).
- model_constructor_grid_backward : Network formulation used in backward (Types from <https://github.com/lanl-ansi/PowerModels.jl>).
- model_constructor_grid_forward : Network formulation used in forward (Types from <https://github.com/lanl-ansi/PowerModels.jl>).
- post_method : The post method.
- optimizer : Default optimizer factory (<http://www.juliaopt.org/JuMP.jl/v0.19.0/solvers/>).
- optimizer_backward : Optimizer factory used in backward (<http://www.juliaopt.org/JuMP.jl/v0.19.0/solvers/>).
- optimizer_forward : Optimizer factory used in forward(<http://www.juliaopt.org/JuMP.jl/v0.19.0/solvers/>).
- setting : PowerModels settings (<https://github.com/lanl-ansi/PowerModels.jl/blob/e28644bf85232a5322adeeb847c0d18b7ff4f235/src/core/base.jl#L6-L34>)) .
- verbose : Boolean to indicate information prints.
- stage_hours : Number of hours in each stage.
- discount_factor : The discount factor.
- cycle_probability : Probability of restart the horizon.
"""
function create_param(;
stages::Int=1,
model_constructor_grid=DCPPowerModel,
model_constructor_grid_backward=model_constructor_grid,
model_constructor_grid_forward=model_constructor_grid_backward,
post_method=PowerModels.build_opf,
optimizer=GLPK.Optimizer,
optimizer_backward=optimizer,
optimizer_forward=optimizer_backward,
setting=Dict("output" => Dict("branch_flows" => true, "duals" => true)),
verbose=false,
stage_hours=1,
model_constructor_grid::Type=DCPPowerModel,
model_constructor_grid_backward::Type=model_constructor_grid,
model_constructor_grid_forward::Type=model_constructor_grid_backward,
post_method::Function=PowerModels.build_opf,
optimizer::DataType=GLPK.Optimizer,
optimizer_backward::DataType=optimizer,
optimizer_forward::DataType=optimizer_backward,
setting::Dict=Dict("output" => Dict("branch_flows" => true, "duals" => true)),
verbose::Bool=false,
stage_hours::Int=1,
discount_factor::Float64=1.0,
cycle_probability::Float64=0.0,
)
params = Dict()
params["stages"] = stages
params["stage_hours"] = stage_hours
params["discount_factor"] = discount_factor
params["cycle_probability"] = cycle_probability
params["model_constructor_grid"] = model_constructor_grid
params["model_constructor_grid_backward"] = model_constructor_grid_backward
params["model_constructor_grid_forward"] = model_constructor_grid_forward
Expand Down
3 changes: 3 additions & 0 deletions src/build_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ function build_graph(params::Dict)
SDDP.add_node(graph, t)
SDDP.add_edge(graph, t - 1 => t, params["discount_factor"])
end
if params["cycle_probability"] > 0.0
SDDP.add_edge(graph, params["stages"] => 1, params["cycle_probability"])
end
return graph
end

Expand Down
14 changes: 10 additions & 4 deletions src/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,16 @@ function constraint_min_volume_violation(sp, data::Dict, last_stage::Bool)
sp,
min_volume_violation_bound[r=1:data["hydro"]["nHyd"]],
sp[:min_volume_violation][r] >=
(last_stage ?
max(data["hydro"]["Hydrogenerators"][r]["min_volume"], data["hydro"]["Hydrogenerators"][r]["final_volume"]) :
data["hydro"]["Hydrogenerators"][r]["min_volume"])
- sp[:reservoir][r].out
(
if last_stage
max(
data["hydro"]["Hydrogenerators"][r]["min_volume"],
data["hydro"]["Hydrogenerators"][r]["final_volume"],
)
else
data["hydro"]["Hydrogenerators"][r]["min_volume"]
end
) - sp[:reservoir][r].out
)
return nothing
end

0 comments on commit 90994a2

Please sign in to comment.