odow / SDDP.jl

A JuMP extension for Stochastic Dual Dynamic Programming
https://sddp.dev
Other
293 stars 62 forks source link

Can I define a constraint that correlates state variables from multiple nodes? #749

Closed WuSiren closed 2 months ago

WuSiren commented 2 months ago

For example, there is a state variable $x_t$ for stage $t$ in a multistage problem and this variable is required to satisfy, say $xt + x{t+1} + x_{t+2} \leq 10$. Does SDDP.jl support this kind of state transition constraints? How can I define it in the subproblem?

Thanks!

WuSiren commented 2 months ago

Let's take the hydro-thermal scheduling problem as an example, if there is one more constraint over the whole time horizon that $valumet + valume{t+1} + valume_{t+2} \leq 400, t \in [1, T-2]$ (please ignore its practical meaning), how should we modify the following code?

using SDDP

graph = SDDP.LinearGraph(3)

function subproblem_builder(subproblem::Model, node::Int)
    # State variables
    @variable(subproblem, 0 <= volume <= 200, SDDP.State, initial_value = 200)
    # Control variables
    @variables(subproblem, begin
        thermal_generation >= 0
        hydro_generation >= 0
        hydro_spill >= 0
    end)
    # Random variables
    @variable(subproblem, inflow)
    Ω = [0.0, 50.0, 100.0]
    P = [1 / 3, 1 / 3, 1 / 3]
    SDDP.parameterize(subproblem, Ω, P) do ω
        return JuMP.fix(inflow, ω)
    end
    # Transition function and constraints
    @constraints(
        subproblem,
        begin
            volume.out == volume.in - hydro_generation - hydro_spill + inflow
            demand_constraint, hydro_generation + thermal_generation == 150
        end
    )
    # Stage-objective
    fuel_cost = [50, 100, 150]
    @stageobjective(subproblem, fuel_cost[node] * thermal_generation)
    return subproblem
end

Thank you again, Professor!

odow commented 2 months ago

See https://sddp.dev/stable/guides/access_previous_variables/

WuSiren commented 2 months ago

Thank you! The documentation is really readable and comprehensive.