File size: 5,130 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
function _add_power_trajectory_eqs!(
    model::JuMP.Model,
    g::ThermalUnit,
    formulation_prod_vars::Gar1962.ProdVars,
    formulation_power_trajectories::ArrCon2004.PowerTrajectories,
    formulation_status_vars::Gar1962.StatusVars,
    sc::UnitCommitmentScenario,
)::Nothing
    if isempty(g.startup_curve) || isempty(g.shutdown_curve)
        return
    end

    T_del = model[:instance].time
    if haskey(model, :eq_ramp_up) && haskey(model, :eq_ramp_down)
        for t in 1:T_del
            key = (sc.name, g.name, t)
            if haskey(model[:eq_ramp_up], key)
                delete(model, model[:eq_ramp_up][key])
                delete!(model[:eq_ramp_up], key)
            end
            if haskey(model[:eq_ramp_down], key)
                delete(model, model[:eq_ramp_down][key])
                delete!(model[:eq_ramp_down], key)
            end
        end
    end

    T  = model[:instance].time
    UD = length(g.startup_curve)
    DD = length(g.shutdown_curve)
    P_U = g.startup_curve
    P_D = g.shutdown_curve
    if haskey(model, :segprod)
        for t in 1:T_del
            su_min = isempty(P_U) ? 0.0 : minimum(P_U)
            if su_min < g.min_power[t]
                key1 = (sc.name, g.name, t, 1)
                if haskey(model[:segprod], key1)
                    set_lower_bound(model[:segprod][key1], su_min - g.min_power[t])
                end
            end
        end
    end
    RU  = g.ramp_up_limit
    RD  = g.ramp_down_limit
    gn  = g.name

    is_on     = model[:is_on]
    switch_on = model[:switch_on]
    switch_off= model[:switch_off]

    eq_startup_lb  = _init(model, :eq_arr_startup_lb)
    eq_startup_ub  = _init(model, :eq_arr_startup_ub)
    eq_shutdown_lb = _init(model, :eq_arr_shutdown_lb)
    eq_shutdown_ub = _init(model, :eq_arr_shutdown_ub)
    eq_ramp_up   = _init(model, :eq_arr_ramp_up)
    eq_ramp_down = _init(model, :eq_arr_ramp_down)
    eq_overlap_logic = _init(model, :eq_overlap_logic)
    eq_overlap_su_lb = _init(model, :eq_overlap_su_lb)
    eq_overlap_sd_lb = _init(model, :eq_overlap_sd_lb)

    for t in 1:T
        Pmax = g.max_power[t]
        Pmin = g.min_power[t]
        p_t   = _actual_power(model, g, sc, t)
        su_prod = sum(
            P_U[i] * switch_on[gn, t - i + 1]
            for i in 1:UD if t - i + 1 >= 1;
            init = 0.0
        )
        # Σ y(k-i+1)
        su_sum = sum(
            switch_on[gn, t - i + 1]
            for i in 1:UD if t - i + 1 >= 1;
            init = 0
        )
        # Σ P_D(i)·z(k+DD-i+1)
        sd_prod = sum(
            P_D[i] * switch_off[gn, t + DD - i + 1]
            for i in 1:DD if t + DD - i + 1 <= T;
            init = 0.0
        )
        # Σ z(k+i)
        sd_sum = sum(
            switch_off[gn, t + i]
            for i in 1:DD if t + i <= T;
            init = 0
        )

        # [1] 启动下限
        eq_startup_lb[sc.name, gn, t] = @constraint(
            model,
            p_t >= Pmin * (is_on[gn, t] - su_sum - sd_sum) + su_prod
        )

        # [2] 停止下限
        eq_shutdown_lb[sc.name, gn, t] = @constraint(
            model,
            p_t >= Pmin * (is_on[gn, t] - su_sum - sd_sum) + sd_prod
        )

        # [3] 启动上限
        eq_startup_ub[sc.name, gn, t] = @constraint(
            model,
            p_t <= su_prod + Pmax * (is_on[gn, t] - su_sum)
        )

        # [4] 停止上限
        eq_shutdown_ub[sc.name, gn, t] = @constraint(
            model,
            p_t <= sd_prod + Pmax * (is_on[gn, t] - sd_sum)
        )
        
        # [10] 
        eq_overlap_logic[sc.name, gn, t] = @constraint(
            model,
            switch_on[gn, t] + sum(
                switch_off[gn, t + j]
                for j in 0:(UD + DD - 2) if t + j <= T;
                init = 0
            ) <= 1
        )

        # [11] & [12] 
        eq_overlap_su_lb[sc.name, gn, t] = @constraint(
            model,
            p_t >= P_U[UD] * (su_sum + sd_sum - 1)
        )

        eq_overlap_sd_lb[sc.name, gn, t] = @constraint(
            model,
            p_t >= P_D[1] * (su_sum + sd_sum - 1)
        )

        # [5]
        if t == 1
            g.initial_status > 0 || continue
            p_prev = g.initial_power
        else
            p_prev = _actual_power(model, g, sc, t - 1)
        end
        eq_ramp_up[sc.name, gn, t] = @constraint(
            model,
            p_t - p_prev <= Pmax * su_sum + RU * (is_on[gn, t] - su_sum)
        )

        # [6]
        if t > 1
            p_prev_rd = _actual_power(model, g, sc, t - 1)
            sd_sum_prev = sum(
                switch_off[gn, (t-1) + i]
                for i in 1:DD if (t-1) + i <= T;
                init = 0
            )
            eq_ramp_down[sc.name, gn, t] = @constraint(
                model,
                p_prev_rd - p_t <= Pmax * sd_sum_prev + RD * (is_on[gn, t-1] - sd_sum_prev)
            )
        end

        reserve_t = _total_reserves(model, g, sc)[t]
        @constraint(
            model,
            reserve_t <= Pmax * (is_on[gn, t] - su_sum - sd_sum)
        )
    end        
    return
end