File size: 2,313 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
# 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_piecewise_linear_eqs!(
    model::JuMP.Model,
    g::ThermalUnit,
    formulation_prod_vars::Gar1962.ProdVars,
    formulation_pwl_costs::Gar1962.PwlCosts,
    formulation_status_vars::Gar1962.StatusVars,
    sc::UnitCommitmentScenario,
)::Nothing
    eq_prod_above_def = _init(model, :eq_prod_above_def)
    eq_segprod_limit = _init(model, :eq_segprod_limit)
    segprod = model[:segprod]
    gn = g.name

    # Gar1962.ProdVars
    prod_above = model[:prod_above]

    # Gar1962.StatusVars
    is_on = model[:is_on]

    K = length(g.cost_segments)
    for t in 1:model[:instance].time
        # Definition of production
        # Equation (43) in Kneuven et al. (2020)
        eq_prod_above_def[sc.name, gn, t] = @constraint(
            model,
            prod_above[sc.name, gn, t] ==
            sum(segprod[sc.name, gn, t, k] for k in 1:K)
        )

        for k in 1:K
            # Equation (42) in Kneuven et al. (2020)
            # Without this, solvers will add a lot of implied bound cuts to
            # have this same effect.
            # NB: when reading instance, UnitCommitment.jl already calculates
            #     difference between max power for segments k and k-1 so the
            #     value of cost_segments[k].mw[t] is the max production *for
            #     that segment*
            eq_segprod_limit[sc.name, gn, t, k] = @constraint(
                model,
                segprod[sc.name, gn, t, k] <=
                g.cost_segments[k].mw[t] * is_on[gn, t]
            )

            # Also add this as an explicit upper bound on segprod to make the
            # solver's work a bit easier
            set_upper_bound(
                segprod[sc.name, gn, t, k],
                g.cost_segments[k].mw[t],
            )

            # Objective function
            # Equation (44) in Kneuven et al. (2020)
            add_to_expression!(
                model[:obj],
                segprod[sc.name, gn, t, k],
                sc.probability * g.cost_segments[k].cost[t],
            )
        end
    end
    return
end