File size: 4,635 Bytes
43c68a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details.

function _add_production_vars!(
    model::JuMP.Model,
    g::ThermalUnit,
    formulation_prod_vars::Gar1962.ProdVars,
    sc::UnitCommitmentScenario,
)::Nothing
    prod_above = _init(model, :prod_above)
    segprod = _init(model, :segprod)
    for t in 1:model[:instance].time
        for k in 1:length(g.cost_segments)
            segprod[sc.name, g.name, t, k] = @variable(model, lower_bound = 0, base_name =  "segprod_$(sc.name)_$(g.name)_$(t)_$(k)")
        end
        prod_above[sc.name, g.name, t] = @variable(model, lower_bound = 0, base_name =  "prod_above_$(sc.name)_$(g.name)_$(t)")
    end
    return
end

function _add_production_limit_eqs!(
    model::JuMP.Model,
    g::ThermalUnit,
    formulation_prod_vars::Gar1962.ProdVars,
    # [1]
    formulation_power_trajectories::Nothing,
    sc::UnitCommitmentScenario,
)::Nothing
    eq_prod_limit = _init(model, :eq_prod_limit)
    is_on = model[:is_on]
    prod_above = model[:prod_above]
    reserve = _total_reserves(model, g, sc)
    gn = g.name
    for t in 1:model[:instance].time
        # Objective function terms for production costs
        # Part of (69) of Kneuven et al. (2020) as C^R_g * u_g(t) term

        # Production limit
        # Equation (18) in Kneuven et al. (2020)
        #   as \bar{p}_g(t) \le \bar{P}_g u_g(t)
        # amk: this is a weaker version of (20) and (21) in Kneuven et al. (2020)
        #      but keeping it here in case those are not present
        power_diff = max(g.max_power[t], 0.0) - max(g.min_power[t], 0.0)
        if power_diff < 1e-7
            power_diff = 0.0
        end
        eq_prod_limit[sc.name, gn, t] = @constraint(
            model,
            prod_above[sc.name, gn, t] + reserve[t] <=
            power_diff * is_on[gn, t]
        )
    end
    return
end

# [2]
function _add_production_limit_eqs!(
    model::JuMP.Model,
    g::ThermalUnit,
    formulation_prod_vars::Gar1962.ProdVars,
    formulation_power_trajectories::ArrCon2004.PowerTrajectories,
    sc::UnitCommitmentScenario
)::Nothing
    if isempty(g.startup_curve) || isempty(g.shutdown_curve)
        eq_prod_limit = _init(model, :eq_prod_limit)
        is_on         = model[:is_on]
        prod_above    = model[:prod_above]
        reserve       = _total_reserves(model, g, sc)
        gn            = g.name
        for t in 1:model[:instance].time
            power_diff = max(g.max_power[t], 0.0) - max(g.min_power[t], 0.0)
            power_diff < 1e-7 && (power_diff = 0.0)
            eq_prod_limit[sc.name, gn, t] = @constraint(
                model,
                prod_above[sc.name, gn, t] + reserve[t] <=
                power_diff * is_on[gn, t]
            )
        end
        return
    end
    prod_above = model[:prod_above]
    for t in 1:model[:instance].time
        set_lower_bound(prod_above[sc.name, g.name, t], -g.min_power[t])
    end

    eq_prod_limit = _init(model, :eq_prod_limit)
    is_on         = model[:is_on]
    switch_on     = model[:switch_on]
    switch_off    = model[:switch_off]
    reserve       = _total_reserves(model, g, sc)
    gn            = g.name
    T             = model[:instance].time

    UD = length(g.startup_curve)
    DD = length(g.shutdown_curve)
    P_U = g.startup_curve
    P_D = g.shutdown_curve

    for t in 1:T
        Pmin = g.min_power[t]
        Pmax = g.max_power[t]
        power_diff = max(Pmax, 0.0) - max(Pmin, 0.0)
        power_diff < 1e-7 && (power_diff = 0.0)

        # Σ y(t-i+1)
        sum_y = @expression(model,
            sum(switch_on[gn, t-i+1] for i in 1:UD if t-i+1 >= 1; init=0))

        # Σ z(t+i)
        sum_z = @expression(model,
            sum(switch_off[gn, t+i] for i in 1:DD if t+i <= T; init=0))

        # Σ (P_U[i]-Pmin)·y(t-i+1)
        su_above = @expression(model,
            sum((P_U[i] - Pmin) * switch_on[gn, t-i+1]
                for i in 1:UD if t-i+1 >= 1; init=0.0))

        # Σ (P_D[i]-Pmin)·z(t+DD-i+1)
        sd_above = @expression(model,
            sum((P_D[i] - Pmin) * switch_off[gn, t+DD-i+1]
                for i in 1:DD if t+DD-i+1 >= 1 && t+DD-i+1 <= T; init=0.0))

        # [3]约束(3)(4)
        eq_prod_limit[sc.name, gn, t] = @constraint(
            model,
            prod_above[sc.name, gn, t] + reserve[t] <=
                su_above +
                sd_above +
                power_diff * (is_on[gn, t] - sum_y - sum_z)
        )
    end
    return
end