Asset management with modifications

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

A modified version of the Asset Management Problem Taken from the book J.R. Birge, F. Louveaux, Introduction to Stochastic Programming, Springer Series in Operations Research and Financial Engineering, Springer New York, New York, NY, 2011

using SDDP, HiGHS, Testfunction asset_management_stagewise(; cut_type)    w_s = [1.25, 1.06]    w_b = [1.14, 1.12]    Phi = [-1, 5]    Psi = [0.02, 0.0]    model = SDDP.MarkovianPolicyGraph(;        sense = :Max,        transition_matrices = Array{Float64,2}[            [1.0]',            [0.5 0.5],            [0.5 0.5; 0.5 0.5],            [0.5 0.5; 0.5 0.5],        ],        upper_bound = 1000.0,        optimizer = HiGHS.Optimizer,    ) do subproblem, node        t, i = node        @variable(subproblem, xs >= 0, SDDP.State, initial_value = 0)        @variable(subproblem, xb >= 0, SDDP.State, initial_value = 0)        if t == 1            @constraint(subproblem, xs.out + xb.out == 55 + xs.in + xb.in)            @stageobjective(subproblem, 0)        elseif t == 2 || t == 3            @variable(subproblem, phi)            @constraint(                subproblem,                w_s[i] * xs.in + w_b[i] * xb.in + phi == xs.out + xb.out            )            SDDP.parameterize(subproblem, [1, 2], [0.6, 0.4]) do ω                fix(phi, Phi[ω])                @stageobjective(subproblem, Psi[ω] * xs.out)            end        else            @variable(subproblem, u >= 0)            @variable(subproblem, v >= 0)            @constraint(                subproblem,                w_s[i] * xs.in + w_b[i] * xb.in + u - v == 80,            )            @stageobjective(subproblem, -4u + v)        end    end    SDDP.train(        model;        cut_type = cut_type,        log_frequency = 10,        risk_measure = (node) -> begin            if node[1] != 3                SDDP.Expectation()            else                SDDP.EAVaR(; lambda = 0.5, beta = 0.5)            end        end,    )    @test SDDP.calculate_bound(model)  1.278 atol = 1e-3    returnendasset_management_stagewise(; cut_type = SDDP.SINGLE_CUT)asset_management_stagewise(; cut_type = SDDP.MULTI_CUT)
-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-26
-------------------------------------------------------------------
problem
  nodes           : 7
  state variables : 2
  scenarios       : 3.20000e+01
  existing cuts   : false
options
  solver          : serial mode
  risk measure    : #9
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [5, 7]
  AffExpr in MOI.EqualTo{Float64}         : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [2, 5]
  VariableRef in MOI.LessThan{Float64}    : [1, 1]
numerical stability report
  matrix range     [1e+00, 1e+00]
  objective range  [2e-02, 4e+00]
  bounds range     [1e+03, 1e+03]
  rhs range        [6e+01, 8e+01]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
        10  -7.690656e+00  2.366592e+00  9.819484e-02       278   1
        20   1.266135e+00  1.306623e+00  1.051810e-01       428   1
        30   2.252026e-01  1.280382e+00  1.124198e-01       578   1
        40  -1.051817e+00  1.278410e+00  1.243939e-01       856   1
        50   7.320288e+00  1.278410e+00  1.315598e-01      1006   1
        56   1.111084e+01  1.278410e+00  1.361990e-01      1096   1
-------------------------------------------------------------------
status         : simulation_stopping
total time (s) : 1.361990e-01
total solves   : 1096
best bound     :  1.278410e+00
numeric issues : 0
-------------------------------------------------------------------

-------------------------------------------------------------------
         SDDP.jl (c) Oscar Dowson and contributors, 2017-26
-------------------------------------------------------------------
problem
  nodes           : 7
  state variables : 2
  scenarios       : 3.20000e+01
  existing cuts   : false
options
  solver          : serial mode
  risk measure    : #9
  sampling scheme : SDDP.InSampleMonteCarlo
subproblem structure
  VariableRef                             : [5, 7]
  AffExpr in MOI.EqualTo{Float64}         : [1, 1]
  VariableRef in MOI.GreaterThan{Float64} : [2, 5]
  VariableRef in MOI.LessThan{Float64}    : [1, 1]
numerical stability report
  matrix range     [1e+00, 1e+00]
  objective range  [2e-02, 4e+00]
  bounds range     [1e+03, 1e+03]
  rhs range        [6e+01, 8e+01]
-------------------------------------------------------------------
 iteration    simulation      bound        time (s)     solves  pid
-------------------------------------------------------------------
        10   2.007061e+00  1.281639e+00  1.611710e-02       278   1
        20   1.426676e+01  1.278410e+00  2.623296e-02       428   1
        30   1.522212e+00  1.278410e+00  4.234505e-02       706   1
        40  -4.523775e+01  1.278410e+00  5.470514e-02       856   1
-------------------------------------------------------------------
status         : simulation_stopping
total time (s) : 5.470514e-02
total solves   : 856
best bound     :  1.278410e+00
numeric issues : 0
-------------------------------------------------------------------