1
1
# stuff that is universal to all power models
2
2
3
- export
3
+ export
4
4
GenericPowerModel,
5
5
setdata, setsolver, solve
6
6
7
-
8
7
type PowerDataSets
9
8
ref_bus
10
9
buses
@@ -26,8 +25,6 @@ abstract AbstractPowerModel
26
25
abstract AbstractPowerFormulation
27
26
abstract AbstractConicPowerFormulation <: AbstractPowerFormulation
28
27
29
-
30
-
31
28
type GenericPowerModel{T<: AbstractPowerFormulation } <: AbstractPowerModel
32
29
model:: Model
33
30
data:: Dict{AbstractString,Any}
@@ -36,7 +33,6 @@ type GenericPowerModel{T<:AbstractPowerFormulation} <: AbstractPowerModel
36
33
solution:: Dict{AbstractString,Any}
37
34
end
38
35
39
-
40
36
# default generic constructor
41
37
function GenericPowerModel {T} (data:: Dict{AbstractString,Any} , vars:: T ; setting = Dict {AbstractString,Any} (), solver = JuMP. UnsetSolver ())
42
38
data, sets = process_raw_data (data)
@@ -52,7 +48,6 @@ function GenericPowerModel{T}(data::Dict{AbstractString,Any}, vars::T; setting =
52
48
return pm
53
49
end
54
50
55
-
56
51
function process_raw_data (data:: Dict{AbstractString,Any} )
57
52
make_per_unit (data)
58
53
unify_transformer_taps (data)
@@ -64,8 +59,6 @@ function process_raw_data(data::Dict{AbstractString,Any})
64
59
return data, sets
65
60
end
66
61
67
-
68
-
69
62
#
70
63
# Just seems too hard to maintain with the default constructor
71
64
#
79
72
80
73
# end
81
74
82
-
83
75
# TODO Ask Miles, why do we need to put JuMP. here? using at top level should bring it in
84
76
function JuMP. setsolver (pm:: GenericPowerModel , solver:: MathProgBase.AbstractMathProgSolver )
85
77
setsolver (pm. model, solver)
@@ -97,7 +89,6 @@ function JuMP.solve(pm::GenericPowerModel)
97
89
return status, solve_time
98
90
end
99
91
100
-
101
92
function run_generic_model (file, model_constructor, solver, post_method; solution_builder = get_solution, kwargs... )
102
93
data = PowerModels. parse_file (file)
103
94
@@ -110,8 +101,7 @@ function run_generic_model(file, model_constructor, solver, post_method; solutio
110
101
return build_solution (pm, status, solve_time; solution_builder = solution_builder)
111
102
end
112
103
113
-
114
- function build_sets (data :: Dict{AbstractString,Any} )
104
+ function build_sets (data:: Dict{AbstractString,Any} )
115
105
bus_lookup = [ Int (bus[" index" ]) => bus for bus in data[" bus" ] ]
116
106
gen_lookup = [ Int (gen[" index" ]) => gen for gen in data[" gen" ] ]
117
107
for gencost in data[" gencost" ]
@@ -120,15 +110,14 @@ function build_sets(data :: Dict{AbstractString,Any})
120
110
end
121
111
branch_lookup = [ Int (branch[" index" ]) => branch for branch in data[" branch" ] ]
122
112
123
- # filter turned off stuff
113
+ # filter turned off stuff
124
114
bus_lookup = filter ((i, bus) -> bus[" bus_type" ] != 4 , bus_lookup)
125
115
gen_lookup = filter ((i, gen) -> gen[" gen_status" ] == 1 && gen[" gen_bus" ] in keys (bus_lookup), gen_lookup)
126
116
branch_lookup = filter ((i, branch) -> branch[" br_status" ] == 1 && branch[" f_bus" ] in keys (bus_lookup) && branch[" t_bus" ] in keys (bus_lookup), branch_lookup)
127
117
128
-
129
118
arcs_from = [(i,branch[" f_bus" ],branch[" t_bus" ]) for (i,branch) in branch_lookup]
130
119
arcs_to = [(i,branch[" t_bus" ],branch[" f_bus" ]) for (i,branch) in branch_lookup]
131
- arcs = [arcs_from; arcs_to]
120
+ arcs = [arcs_from; arcs_to]
132
121
133
122
bus_gens = [i => [] for (i,bus) in bus_lookup]
134
123
for (i,gen) in gen_lookup
@@ -156,16 +145,15 @@ function build_sets(data :: Dict{AbstractString,Any})
156
145
157
146
158
147
buspair_indexes = collect (Set ([(i,j) for (l,i,j) in arcs_from]))
159
- buspairs = buspair_parameters (buspair_indexes, branch_lookup, bus_lookup)
148
+ buspairs = buspair_parameters (buspair_indexes, branch_lookup, bus_lookup)
160
149
161
150
return PowerDataSets (ref_bus, bus_lookup, bus_idxs, gen_lookup, gen_idxs, branch_lookup, branch_idxs, bus_gens, arcs_from, arcs_to, arcs, bus_branches, buspairs, buspair_indexes)
162
151
end
163
152
164
-
165
153
# compute bus pair level structures
166
154
function buspair_parameters (buspair_indexes, branches, buses)
167
- bp_angmin = [bp => - Inf for bp in buspair_indexes]
168
- bp_angmax = [bp => Inf for bp in buspair_indexes]
155
+ bp_angmin = [bp => - Inf for bp in buspair_indexes]
156
+ bp_angmax = [bp => Inf for bp in buspair_indexes]
169
157
bp_line = [bp => Inf for bp in buspair_indexes]
170
158
171
159
for (l,branch) in branches
@@ -178,8 +166,8 @@ function buspair_parameters(buspair_indexes, branches, buses)
178
166
end
179
167
180
168
buspairs = [(i,j) => Dict (
181
- " line" => bp_line[(i,j)],
182
- " angmin" => bp_angmin[(i,j)],
169
+ " line" => bp_line[(i,j)],
170
+ " angmin" => bp_angmin[(i,j)],
183
171
" angmax" => bp_angmax[(i,j)],
184
172
" rate_a" => branches[bp_line[(i,j)]][" rate_a" ],
185
173
" tap" => branches[bp_line[(i,j)]][" tap" ],
@@ -191,9 +179,6 @@ function buspair_parameters(buspair_indexes, branches, buses)
191
179
return buspairs
192
180
end
193
181
194
-
195
-
196
-
197
182
not_pu = Set ([" rate_a" ," rate_b" ," rate_c" ," bs" ," gs" ," pd" ," qd" ," pg" ," qg" ," pmax" ," pmin" ," qmax" ," qmin" ])
198
183
not_rad = Set ([" angmax" ," angmin" ," shift" ," va" ])
199
184
@@ -209,7 +194,7 @@ function make_per_unit(mva_base::Number, data::Dict{AbstractString,Any})
209
194
if k == " gencost"
210
195
for cost_model in data[k]
211
196
if cost_model[" model" ] != 2
212
- println ( " WARNING: Skipping generator cost model of tpye other than 2" )
197
+ warn ( " Skipping generator cost model of type other than 2" )
213
198
continue
214
199
end
215
200
degree = length (cost_model[" cost" ])
@@ -255,10 +240,8 @@ function unify_transformer_taps(data::Dict{AbstractString,Any})
255
240
end
256
241
end
257
242
258
-
259
-
260
243
# NOTE, this function assumes all values are p.u. and angles are in radians
261
- function add_branch_parameters (data :: Dict{AbstractString,Any} )
244
+ function add_branch_parameters (data:: Dict{AbstractString,Any} )
262
245
min_theta_delta = calc_min_phase_angle (data)
263
246
max_theta_delta = calc_max_phase_angle (data)
264
247
@@ -278,7 +261,7 @@ function add_branch_parameters(data :: Dict{AbstractString,Any})
278
261
end
279
262
end
280
263
281
- function standardize_cost_order (data :: Dict{AbstractString,Any} )
264
+ function standardize_cost_order (data:: Dict{AbstractString,Any} )
282
265
for gencost in data[" gencost" ]
283
266
if gencost[" model" ] == 2 && length (gencost[" cost" ]) < 3
284
267
println (" std gen cost: " ,gencost[" cost" ])
@@ -289,26 +272,18 @@ function standardize_cost_order(data :: Dict{AbstractString,Any})
289
272
end
290
273
end
291
274
292
-
293
- function calc_max_phase_angle (data :: Dict{AbstractString,Any} )
275
+ function calc_max_phase_angle (data:: Dict{AbstractString,Any} )
294
276
bus_count = length (data[" bus" ])
295
277
angle_max = [branch[" angmax" ] for branch in data[" branch" ]]
296
278
sort! (angle_max, rev= true )
297
279
298
280
return sum (angle_max[1 : bus_count- 1 ])
299
281
end
300
282
301
- function calc_min_phase_angle (data :: Dict{AbstractString,Any} )
283
+ function calc_min_phase_angle (data:: Dict{AbstractString,Any} )
302
284
bus_count = length (data[" bus" ])
303
285
angle_min = [branch[" angmin" ] for branch in data[" branch" ]]
304
286
sort! (angle_min)
305
287
306
288
return sum (angle_min[1 : bus_count- 1 ])
307
289
end
308
-
309
-
310
-
311
-
312
-
313
-
314
-
0 commit comments