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

using DataStructures
using JSON

function _migrate(json)
    version = json["Parameters"]["Version"]
    if version === nothing
        error(
            "The provided input file cannot be loaded because it does not " *
            "specify what version of UnitCommitment.jl it was written for. " *
            "Please modify the \"Parameters\" section of the file and include " *
            "a \"Version\" entry. For example: {\"Parameters\":{\"Version\":\"0.3\"}}",
        )
    end
    version = VersionNumber(version)
    version >= v"0.3" || _migrate_to_v03(json)
    version >= v"0.4" || _migrate_to_v04(json)
    return
end

function _migrate_to_v03(json)
    # Migrate reserves
    if json["Reserves"] !== nothing &&
       json["Reserves"]["Spinning (MW)"] !== nothing
        amount = json["Reserves"]["Spinning (MW)"]
        json["Reserves"] = DefaultOrderedDict(nothing)
        json["Reserves"]["r1"] = DefaultOrderedDict(nothing)
        json["Reserves"]["r1"]["Type"] = "spinning"
        json["Reserves"]["r1"]["Amount (MW)"] = amount
        for (gen_name, gen) in json["Generators"]
            if gen["Provides spinning reserves?"] == true
                gen["Reserve eligibility"] = ["r1"]
            end
        end
    end
end

function _migrate_to_v04(json)
    # Migrate thermal units
    if json["Generators"] !== nothing
        for (gen_name, gen) in json["Generators"]
            if gen["Type"] === nothing
                gen["Type"] = "Thermal"
            end
        end
    end
end