FAST: the hydro-thermal problem

This tutorial was generated using Literate.jl. Download the source as a .jl file. Download the source as a .ipynb file.

An implementation of the Hydro-thermal example from FAST

using SDDP, HiGHS, Test

function fast_hydro_thermal()
    model = SDDP.LinearPolicyGraph(;
        stages = 2,
        upper_bound = 0.0,
        sense = :Max,
        optimizer = HiGHS.Optimizer,
    ) do sp, t
        @variable(sp, 0 <= x <= 8, SDDP.State, initial_value = 0.0)
        @variables(sp, begin
            y >= 0
            p >= 0
            ξ
        end)
        @constraints(sp, begin
            p + y >= 6
            x.out <= x.in - y + ξ
        end)
        RAINFALL = (t == 1 ? [6] : [2, 10])
        SDDP.parameterize(sp, RAINFALL) do ω
            return JuMP.fix(ξ, ω)
        end
        @stageobjective(sp, -5 * p)
    end

    det = SDDP.deterministic_equivalent(model, HiGHS.Optimizer)
    set_silent(det)
    JuMP.optimize!(det)
    @test JuMP.objective_sense(det) == MOI.MAX_SENSE
    @test JuMP.objective_value(det) == -10
    SDDP.train(model)
    @test SDDP.calculate_bound(model) == -10
    return
end

fast_hydro_thermal()
-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-23
-------------------------------------------------------------------
problem
  nodes           : 2
  state variables : 1
  scenarios       : 2.00000e+00
  existing cuts   : false
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [6, 6]
  AffExpr in MOI.GreaterThan{Float64}     : [1, 1]
  AffExpr in MOI.LessThan{Float64}        : [1, 1]
  VariableRef in MOI.EqualTo{Float64}     : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [3, 4]
  VariableRef in MOI.LessThan{Float64}    : [2, 2]
numerical stability report
  matrix range     [1e+00, 1e+00]
  objective range  [1e+00, 5e+00]
  bounds range     [8e+00, 8e+00]
  rhs range        [6e+00, 6e+00]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   0.000000e+00 -1.000000e+01  2.954006e-03         5   1
        20   0.000000e+00 -1.000000e+01  1.531601e-02       104   1
-------------------------------------------------------------------
status         : simulation_stopping
total time (s) : 1.531601e-02
total solves   : 104
best bound     : -1.000000e+01
simulation ci  : -9.000000e+00 ± 4.474009e+00
numeric issues : 0
-------------------------------------------------------------------