SDDP: type Array has no field out

Hello,

I’m using SDDP to solve my problem. Now I want to print the result of stage variable level, which is an array with 4 components. For loop structure is used to show the result:

model = SDDP.LinearPolicyGraph(
    stages = numtime,
    sense = :Min,
    lower_bound = 0.0,
    optimizer = Ipopt.Optimizer,
) do sp, node
    # State variables
    @variable(
        sp, 
        min_level[i] <= level[i = 1:4] <= max_level[i], 
        SDDP.State, 
        initial_value = initial_level[i]
    )
...
end
...
# Show results
for stage in simulations[1]
    println("level = $(stage[:level].out)")
end

But when I run the code, it tells me type Array has no field out

If I write println("level = $(stage[:level])"), I get the following result:

level = SDDP.State{Float64}[SDDP.State{Float64}(273.0, 273.6889607972534), SDDP.State{Float64}(225.0, 225.08061916277788), SDDP.State{Float64}(267.0, 267.3945072693355), SDDP.State{Float64}(267.0, 267.5107715473515)]

How can I get the out_state result of level like this one:

flow = [5.7101953228017096e-5, 2.6717931469687598e-5, 4.8417835777304285e-5, 3.3381189977914406e-5]

You need [x.out for x in stage[:level]].

level = SDDP.State{Float64}[SDDP.State{Float64}(273.0, 273.6889607972534), SDDP.State{Float64}(225.0, 225.08061916277788), SDDP.State{Float64}(267.0, 267.3945072693355), SDDP.State{Float64}(267.0, 267.5107715473515)]

Let’s break this down:

  • The Julia syntax. T[ ... stuff ... ] means an Array of stuff with element type T.
  • So SDDP.State{Float64}[ ... ] means you have an array, with element type SDDP.State{Float64}
  • So you have an array of state variables, not a state variable that is an array (if that makes sense)
  • [x.out for x in stage[:level]] says "create a new array, which is built by looping over each x in stage[:level], and returning x.out.