File size: 1,931 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
# 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.

"""
    fix!(model::JuMP.Model, solution::AbstractDict)::Nothing

Fix the value of all binary variables to the ones specified by the given
solution. Useful for computing LMPs.
"""
function fix!(model::JuMP.Model, solution::AbstractDict)::Nothing
    instance, T = model[:instance], model[:instance].time
    "Thermal production (MW)" ∈ keys(solution) ?
    solution = Dict("s1" => solution) : nothing
    is_on = model[:is_on]
    prod_above = model[:prod_above]
    reserve = model[:reserve]
    for sc in instance.scenarios
        for g in sc.thermal_units
            for t in 1:T
                is_on_value = round(solution[sc.name]["Is on"][g.name][t])
                prod_value = round(
                    solution[sc.name]["Thermal production (MW)"][g.name][t],
                    digits = 5,
                )
                JuMP.fix(is_on[g.name, t], is_on_value, force = true)
                JuMP.fix(
                    prod_above[sc.name, g.name, t],
                    prod_value - is_on_value * g.min_power[t],
                    force = true,
                )
            end
        end
        for r in sc.reserves
            r.type == "spinning" || continue
            for g in r.thermal_units
                for t in 1:T
                    reserve_value = round(
                        solution[sc.name]["Spinning reserve (MW)"][r.name][g.name][t],
                        digits = 5,
                    )
                    JuMP.fix(
                        reserve[sc.name, r.name, g.name, t],
                        reserve_value,
                        force = true,
                    )
                end
            end
        end
    end
    return
end