File size: 6,237 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# 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.

doc = """UnitCommitment.jl Benchmark Runner

Usage:
  run.jl [-s ARG]... [-m ARG]... [-c ARG]... [-f ARG]... [options]

Examples:

    1. Benchmark all solvers, methods and formulations:

        julia run.jl

    2. Benchmark formulations "default" and "ArrCon200" using Gurobi:

        julia run.jl -s gurobi -f default -f ArrCon2000

    3. Benchmark a few test cases, using all solvers, methods and formulations:

        julia run.jl -c or-lib/20_0_1_w -c matpower/case1888rte/2017-02-01

    4. Solve 4 test cases in parallel, with 2 threads available per worker:

        JULIA_NUM_THREADS=2 julia --procs 4 run.jl

Options:
  -h --help             Show this screen.
  -s --solver=ARG       Mixed-integer linear solver (e.g. gurobi)
  -c --case=ARG         Unit commitment test case (e.g. or-lib/20_0_1_w)
  -m --method=ARG       Solution method (e.g. default)
  -f --formulation=ARG  Formulation (e.g. ArrCon2000)
  --time-limit=ARG      Time limit in seconds [default: 3600]
  --gap=ARG             Relative MIP gap tolerance [default: 0.001]
  --trials=ARG          Number of trials [default: 5]
"""

using Distributed
using Pkg
Pkg.activate(".")
@everywhere using Pkg
@everywhere Pkg.activate(".")

Pkg.instantiate() # added on 15/04/2025 to ensure DocOpt is available
using DocOpt
args = docopt(doc)

@everywhere using UnitCommitment
@everywhere UnitCommitment._setup_logger()

using UnitCommitment
using Gurobi
using Logging
using JuMP

import UnitCommitment:
    ArrCon2000,
    CarArr2006,
    DamKucRajAta2016,
    Formulation,
    Gar1962,
    KnuOstWat2018,
    MorLatRam2013,
    PanGua2016,
    XavQiuWanThi2019

# Benchmark test cases
# -----------------------------------------------------------------------------
cases = [
    "pglib-uc/ca/2014-09-01_reserves_0",
    "pglib-uc/ca/2014-09-01_reserves_1",
    "pglib-uc/ca/2015-03-01_reserves_0",
    "pglib-uc/ca/2015-06-01_reserves_0",
    "pglib-uc/ca/Scenario400_reserves_1",
    "pglib-uc/ferc/2015-01-01_lw",
    "pglib-uc/ferc/2015-05-01_lw",
    "pglib-uc/ferc/2015-07-01_hw",
    "pglib-uc/ferc/2015-10-01_lw",
    "pglib-uc/ferc/2015-12-01_lw",
    "pglib-uc/rts_gmlc/2020-04-03",
    "pglib-uc/rts_gmlc/2020-09-20",
    "pglib-uc/rts_gmlc/2020-10-27",
    "pglib-uc/rts_gmlc/2020-11-25",
    "pglib-uc/rts_gmlc/2020-12-23",
    "or-lib/20_0_1_w",
    "or-lib/20_0_5_w",
    "or-lib/50_0_2_w",
    "or-lib/75_0_2_w",
    "or-lib/100_0_1_w",
    "or-lib/100_0_4_w",
    "or-lib/100_0_5_w",
    "or-lib/200_0_3_w",
    "or-lib/200_0_7_w",
    "or-lib/200_0_9_w",
    "tejada19/UC_24h_290g",
    "tejada19/UC_24h_623g",
    "tejada19/UC_24h_959g",
    "tejada19/UC_24h_1577g",
    "tejada19/UC_24h_1888g",
    "tejada19/UC_168h_72g",
    "tejada19/UC_168h_86g",
    "tejada19/UC_168h_130g",
    "tejada19/UC_168h_131g",
    "tejada19/UC_168h_199g",
    "matpower/case1888rte/2017-02-01",
    "matpower/case1951rte/2017-02-01",
    "matpower/case2848rte/2017-02-01",
    "matpower/case3012wp/2017-02-01",
    "matpower/case3375wp/2017-02-01",
    "matpower/case6468rte/2017-02-01",
    "matpower/case6515rte/2017-02-01",
]

# Formulations
# -----------------------------------------------------------------------------
formulations = Dict(
    "default" => Formulation(),
    "ArrCon2000" => Formulation(ramping = ArrCon2000.Ramping()),
    "CarArr2006" => Formulation(pwl_costs = CarArr2006.PwlCosts()),
    "DamKucRajAta2016" => Formulation(ramping = DamKucRajAta2016.Ramping()),
    "Gar1962" => Formulation(pwl_costs = Gar1962.PwlCosts()),
    "KnuOstWat2018" => Formulation(pwl_costs = KnuOstWat2018.PwlCosts()),
    "MorLatRam2013" => Formulation(ramping = MorLatRam2013.Ramping()),
    "PanGua2016" => Formulation(ramping = PanGua2016.Ramping()),
)

# Solution methods
# -----------------------------------------------------------------------------
const gap_limit = parse(Float64, args["--gap"])
const time_limit = parse(Float64, args["--time-limit"])
methods = Dict(
    "default" => XavQiuWanThi2019.Method(
        time_limit = time_limit,
        gap_limit = gap_limit,
    ),
)

# MIP solvers
# -----------------------------------------------------------------------------
optimizers = Dict(
    "gurobi" => optimizer_with_attributes(
        Gurobi.Optimizer,
        "Threads" => Threads.nthreads(),
    ),
)

# Parse command line arguments
# -----------------------------------------------------------------------------
if !isempty(args["--case"])
    cases = args["--case"]
end
if !isempty(args["--formulation"])
    formulations = filter(p -> p.first in args["--formulation"], formulations)
end
if !isempty(args["--method"])
    methods = filter(p -> p.first in args["--method"], methods)
end
if !isempty(args["--solver"])
    optimizers = filter(p -> p.first in args["--solver"], optimizers)
end
const ntrials = parse(Int, args["--trials"])

# Print benchmark settings
# -----------------------------------------------------------------------------
function printlist(d::Dict)
    for key in keys(d)
        @info "  - $key"
    end
end

function printlist(d::Vector)
    for key in d
        @info "  - $key"
    end
end

@info "Computational environment:"
@info "  - CPU: $(Sys.cpu_info()[1].model)"
@info "  - Logical CPU cores: $(length(Sys.cpu_info()))"
@info "  - System memory: $(round(Sys.total_memory() / 2^30, digits=2)) GiB"
@info "  - Available workers: $(nworkers())"
@info "  - Available threads per worker: $(Threads.nthreads())"

@info "Parameters:"
@info "  - Number of trials: $ntrials"
@info "  - Time limit (s): $time_limit"
@info "  - Relative MIP gap tolerance: $gap_limit"

@info "Solvers:"
printlist(optimizers)

@info "Methods:"
printlist(methods)

@info "Formulations:"
printlist(formulations)

@info "Cases:"
printlist(cases)

# Run benchmarks
# -----------------------------------------------------------------------------
UnitCommitment._run_benchmarks(
    cases = cases,
    formulations = formulations,
    methods = methods,
    optimizers = optimizers,
    trials = 1:ntrials,
)