Biobjective hydro-thermal

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

using SDDP, HiGHS, Statistics, Test

function biobjective_example()
    model = SDDP.LinearPolicyGraph(;
        stages = 3,
        lower_bound = 0.0,
        optimizer = HiGHS.Optimizer,
    ) do subproblem, _
        @variable(subproblem, 0 <= v <= 200, SDDP.State, initial_value = 50)
        @variables(subproblem, begin
            0 <= g[i = 1:2] <= 100
            0 <= u <= 150
            s >= 0
            shortage_cost >= 0
        end)
        @expressions(subproblem, begin
            objective_1, g[1] + 10 * g[2]
            objective_2, shortage_cost
        end)
        @constraints(subproblem, begin
                inflow_constraint, v.out == v.in - u - s
                g[1] + g[2] + u == 150
                shortage_cost >= 40 - v.out
                shortage_cost >= 60 - 2 * v.out
                shortage_cost >= 80 - 4 * v.out
            end)
        # You must call this for a biobjective problem!
        SDDP.initialize_biobjective_subproblem(subproblem)
        SDDP.parameterize(subproblem, 0.0:5:50.0) do ω
            JuMP.set_normalized_rhs(inflow_constraint, ω)
            # You must call `set_biobjective_functions` from within
            # `SDDP.parameterize`.
            return SDDP.set_biobjective_functions(
                subproblem,
                objective_1,
                objective_2,
            )
        end
    end
    pareto_weights =
        SDDP.train_biobjective(model; solution_limit = 10, iteration_limit = 10)
    solutions = [(k, v) for (k, v) in pareto_weights]
    sort!(solutions; by = x -> x[1])
    @test length(solutions) == 10
    # Test for convexity! The gradient must be decreasing as we move from left
    # to right.
    gradient(a, b) = (b[2] - a[2]) / (b[1] - a[1])
    grad = Inf
    for i in 1:9
        new_grad = gradient(solutions[i], solutions[i+1])
        @test new_grad < grad
        grad = new_grad
    end
    return
end

biobjective_example()
-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-24
-------------------------------------------------------------------
problem
  nodes           : 3
  state variables : 1
  scenarios       : 1.33100e+03
  existing cuts   : false
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [9, 9]
  AffExpr in MOI.EqualTo{Float64}         : [2, 4]
  AffExpr in MOI.GreaterThan{Float64}     : [3, 5]
  VariableRef in MOI.GreaterThan{Float64} : [8, 8]
  VariableRef in MOI.LessThan{Float64}    : [5, 6]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   0.000000e+00  0.000000e+00  8.987904e-03        36   1
        10   0.000000e+00  0.000000e+00  2.858281e-02       360   1
-------------------------------------------------------------------
status         : iteration_limit
total time (s) : 2.858281e-02
total solves   : 360
best bound     :  0.000000e+00
simulation ci  :  0.000000e+00 ± 0.000000e+00
numeric issues : 0
-------------------------------------------------------------------

-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-24
-------------------------------------------------------------------
problem
  nodes           : 3
  state variables : 1
  scenarios       : 1.33100e+03
  existing cuts   : true
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [9, 9]
  AffExpr in MOI.EqualTo{Float64}         : [2, 4]
  AffExpr in MOI.GreaterThan{Float64}     : [3, 7]
  VariableRef in MOI.EqualTo{Float64}     : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [8, 8]
  VariableRef in MOI.LessThan{Float64}    : [5, 6]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   6.750000e+02  5.500000e+02  2.787828e-03       407   1
        10   4.500000e+02  5.733959e+02  6.219983e-02       731   1
-------------------------------------------------------------------
status         : iteration_limit
total time (s) : 6.219983e-02
total solves   : 731
best bound     :  5.733959e+02
simulation ci  :  5.000000e+02 ± 1.079583e+02
numeric issues : 0
-------------------------------------------------------------------

-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-24
-------------------------------------------------------------------
problem
  nodes           : 3
  state variables : 1
  scenarios       : 1.33100e+03
  existing cuts   : true
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [9, 9]
  AffExpr in MOI.EqualTo{Float64}         : [2, 4]
  AffExpr in MOI.GreaterThan{Float64}     : [3, 14]
  VariableRef in MOI.EqualTo{Float64}     : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [8, 8]
  VariableRef in MOI.LessThan{Float64}    : [5, 6]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   4.850000e+02  3.349793e+02  3.133059e-03       778   1
        10   3.550000e+02  3.468286e+02  3.127694e-02      1102   1
-------------------------------------------------------------------
status         : iteration_limit
total time (s) : 3.127694e-02
total solves   : 1102
best bound     :  3.468286e+02
simulation ci  :  3.948309e+02 ± 7.954180e+01
numeric issues : 0
-------------------------------------------------------------------

-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-24
-------------------------------------------------------------------
problem
  nodes           : 3
  state variables : 1
  scenarios       : 1.33100e+03
  existing cuts   : true
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [9, 9]
  AffExpr in MOI.EqualTo{Float64}         : [2, 4]
  AffExpr in MOI.GreaterThan{Float64}     : [3, 19]
  VariableRef in MOI.EqualTo{Float64}     : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [8, 8]
  VariableRef in MOI.LessThan{Float64}    : [5, 6]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   1.887500e+02  1.995243e+02  2.788067e-03      1149   1
        10   2.962500e+02  2.052855e+02  2.994609e-02      1473   1
-------------------------------------------------------------------
status         : iteration_limit
total time (s) : 2.994609e-02
total solves   : 1473
best bound     :  2.052855e+02
simulation ci  :  2.040201e+02 ± 3.876873e+01
numeric issues : 0
-------------------------------------------------------------------

-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-24
-------------------------------------------------------------------
problem
  nodes           : 3
  state variables : 1
  scenarios       : 1.33100e+03
  existing cuts   : true
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [9, 9]
  AffExpr in MOI.EqualTo{Float64}         : [2, 4]
  AffExpr in MOI.GreaterThan{Float64}     : [3, 25]
  VariableRef in MOI.EqualTo{Float64}     : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [8, 8]
  VariableRef in MOI.LessThan{Float64}    : [5, 6]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   3.737500e+02  4.626061e+02  3.342152e-03      1520   1
        10   2.450000e+02  4.658509e+02  3.395200e-02      1844   1
-------------------------------------------------------------------
status         : iteration_limit
total time (s) : 3.395200e-02
total solves   : 1844
best bound     :  4.658509e+02
simulation ci  :  3.907376e+02 ± 9.045105e+01
numeric issues : 0
-------------------------------------------------------------------

-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-24
-------------------------------------------------------------------
problem
  nodes           : 3
  state variables : 1
  scenarios       : 1.33100e+03
  existing cuts   : true
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [9, 9]
  AffExpr in MOI.EqualTo{Float64}         : [2, 4]
  AffExpr in MOI.GreaterThan{Float64}     : [3, 33]
  VariableRef in MOI.EqualTo{Float64}     : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [8, 8]
  VariableRef in MOI.LessThan{Float64}    : [5, 6]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   1.675000e+02  1.129545e+02  3.429174e-03      1891   1
        10   1.362500e+02  1.129771e+02  3.066206e-02      2215   1
-------------------------------------------------------------------
status         : iteration_limit
total time (s) : 3.066206e-02
total solves   : 2215
best bound     :  1.129771e+02
simulation ci  :  1.176375e+02 ± 1.334615e+01
numeric issues : 0
-------------------------------------------------------------------

-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-24
-------------------------------------------------------------------
problem
  nodes           : 3
  state variables : 1
  scenarios       : 1.33100e+03
  existing cuts   : true
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [9, 9]
  AffExpr in MOI.EqualTo{Float64}         : [2, 4]
  AffExpr in MOI.GreaterThan{Float64}     : [3, 36]
  VariableRef in MOI.EqualTo{Float64}     : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [8, 8]
  VariableRef in MOI.LessThan{Float64}    : [5, 6]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   2.562500e+02  2.788373e+02  3.242016e-03      2262   1
        10   2.375000e+02  2.795671e+02  3.343606e-02      2586   1
-------------------------------------------------------------------
status         : iteration_limit
total time (s) : 3.343606e-02
total solves   : 2586
best bound     :  2.795671e+02
simulation ci  :  2.375000e+02 ± 3.099032e+01
numeric issues : 0
-------------------------------------------------------------------

-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-24
-------------------------------------------------------------------
problem
  nodes           : 3
  state variables : 1
  scenarios       : 1.33100e+03
  existing cuts   : true
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [9, 9]
  AffExpr in MOI.EqualTo{Float64}         : [2, 4]
  AffExpr in MOI.GreaterThan{Float64}     : [3, 41]
  VariableRef in MOI.EqualTo{Float64}     : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [8, 8]
  VariableRef in MOI.LessThan{Float64}    : [5, 6]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   3.812500e+02  4.072952e+02  3.648043e-03      2633   1
        10   5.818750e+02  4.080500e+02  3.555894e-02      2957   1
-------------------------------------------------------------------
status         : iteration_limit
total time (s) : 3.555894e-02
total solves   : 2957
best bound     :  4.080500e+02
simulation ci  :  4.235323e+02 ± 1.029245e+02
numeric issues : 0
-------------------------------------------------------------------

-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-24
-------------------------------------------------------------------
problem
  nodes           : 3
  state variables : 1
  scenarios       : 1.33100e+03
  existing cuts   : true
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [9, 9]
  AffExpr in MOI.EqualTo{Float64}         : [2, 4]
  AffExpr in MOI.GreaterThan{Float64}     : [3, 47]
  VariableRef in MOI.EqualTo{Float64}     : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [8, 8]
  VariableRef in MOI.LessThan{Float64}    : [5, 6]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   8.525000e+02  5.197742e+02  3.473997e-03      3004   1
        10   4.493750e+02  5.211793e+02  3.642893e-02      3328   1
-------------------------------------------------------------------
status         : iteration_limit
total time (s) : 3.642893e-02
total solves   : 3328
best bound     :  5.211793e+02
simulation ci  :  5.268125e+02 ± 1.227709e+02
numeric issues : 0
-------------------------------------------------------------------

-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-24
-------------------------------------------------------------------
problem
  nodes           : 3
  state variables : 1
  scenarios       : 1.33100e+03
  existing cuts   : true
options
  solver          : serial mode
  risk measure    : SDDP.Expectation()
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [9, 9]
  AffExpr in MOI.EqualTo{Float64}         : [2, 4]
  AffExpr in MOI.GreaterThan{Float64}     : [3, 53]
  VariableRef in MOI.EqualTo{Float64}     : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [8, 8]
  VariableRef in MOI.LessThan{Float64}    : [5, 6]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
         1   3.437500e+01  5.937500e+01  3.152847e-03      3375   1
        10   3.750000e+01  5.938557e+01  3.139281e-02      3699   1
-------------------------------------------------------------------
status         : iteration_limit
total time (s) : 3.139281e-02
total solves   : 3699
best bound     :  5.938557e+01
simulation ci  :  5.906250e+01 ± 1.352595e+01
numeric issues : 0
-------------------------------------------------------------------