@@ -55,6 +55,9 @@ function post_tnep{T}(pm::GenericPowerModel{T})
55
55
end
56
56
57
57
58
+
59
+ # #### TNEP specific base and solution code
60
+
58
61
type TNEPDataSets
59
62
branches
60
63
branch_indexes
69
72
# ### create some tnep specific sets
70
73
function build_ne_sets (data:: Dict{AbstractString,Any} )
71
74
bus_lookup = Dict ([(Int (bus[" index" ]), bus) for bus in data[" bus" ]])
72
- # gen_lookup = Dict([(Int(gen["index"]), gen) for gen in data["gen"]])
73
- # for gencost in data["gencost"]
74
- # i = Int(gencost["index"])
75
- # gen_lookup[i] = merge(gen_lookup[i], gencost)
76
- # end
77
75
branch_lookup = Dict ([(Int (branch[" index" ]), branch) for branch in data[" branch_ne" ]])
78
76
79
77
# filter turned off stuff
80
78
bus_lookup = filter ((i, bus) -> bus[" bus_type" ] != 4 , bus_lookup)
81
- # gen_lookup = filter((i, gen) -> gen["gen_status"] == 1 && gen["gen_bus"] in keys(bus_lookup), gen_lookup)
82
79
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)
83
80
84
81
arcs_from = [(i,branch[" f_bus" ],branch[" t_bus" ]) for (i,branch) in branch_lookup]
85
82
arcs_to = [(i,branch[" t_bus" ],branch[" f_bus" ]) for (i,branch) in branch_lookup]
86
83
arcs = [arcs_from; arcs_to]
87
84
88
- # bus_gens = Dict([(i, []) for (i,bus) in bus_lookup])
89
- # for (i,gen) in gen_lookup
90
- # push!(bus_gens[gen["gen_bus"]], i)
91
- # end
92
-
93
85
bus_branches = Dict ([(i, []) for (i,bus) in bus_lookup])
94
86
for (l,i,j) in arcs_from
95
87
push! (bus_branches[i], (l,i,j))
96
88
push! (bus_branches[j], (l,j,i))
97
89
end
98
90
99
- # ref_bus = [i for (i,bus) in bus_lookup | bus["bus_type"] == 3][1]
100
- # ref_bus = Union{}
101
- # for (k,v) in bus_lookup
102
- # if v["bus_type"] == 3
103
- # ref_bus = k
104
- # break
105
- # end
106
- # end
107
-
108
91
bus_idxs = collect (keys (bus_lookup))
109
92
# gen_idxs = collect(keys(gen_lookup))
110
93
branch_idxs = collect (keys (branch_lookup))
@@ -115,7 +98,6 @@ function build_ne_sets(data::Dict{AbstractString,Any})
115
98
return TNEPDataSets (branch_lookup, branch_idxs, arcs_from, arcs_to, arcs, bus_branches, buspairs, buspair_indexes)
116
99
end
117
100
118
-
119
101
function process_raw_mp_ne_data (data:: Dict{AbstractString,Any} )
120
102
# TODO , see if there is a clean way of reusing 'process_raw_mp_data'
121
103
# would be fine, except for on/off phase angle calc
@@ -141,10 +123,6 @@ function process_raw_mp_ne_data(data::Dict{AbstractString,Any})
141
123
return data, sets, ext
142
124
end
143
125
144
-
145
-
146
-
147
-
148
126
function get_tnep_solution {T} (pm:: GenericPowerModel{T} )
149
127
sol = Dict {AbstractString,Any} ()
150
128
add_bus_voltage_setpoint (sol, pm)
@@ -155,6 +133,23 @@ function get_tnep_solution{T}(pm::GenericPowerModel{T})
155
133
return sol
156
134
end
157
135
136
+ function add_branch_ne_setpoint {T} (sol, pm:: GenericPowerModel{T} )
137
+ add_setpoint (sol, pm, " branch_ne" , " index" , " built" , :line_ne ; default_value = (item) -> 1 )
138
+ end
139
+
140
+ function add_branch_flow_setpoint_ne {T} (sol, pm:: GenericPowerModel{T} )
141
+ # check the line flows were requested
142
+ if haskey (pm. setting, " output" ) && haskey (pm. setting[" output" ], " line_flows" ) && pm. setting[" output" ][" line_flows" ] == true
143
+ mva_base = pm. data[" baseMVA" ]
144
+
145
+ add_setpoint (sol, pm, " branch_ne" , " index" , " p_from" , :p_ne ; scale = (x,item) -> x* mva_base, extract_var = (var,idx,item) -> var[(idx, item[" f_bus" ], item[" t_bus" ])])
146
+ add_setpoint (sol, pm, " branch_ne" , " index" , " q_from" , :q_ne ; scale = (x,item) -> x* mva_base, extract_var = (var,idx,item) -> var[(idx, item[" f_bus" ], item[" t_bus" ])])
147
+ add_setpoint (sol, pm, " branch_ne" , " index" , " p_to" , :p_ne ; scale = (x,item) -> x* mva_base, extract_var = (var,idx,item) -> var[(idx, item[" t_bus" ], item[" f_bus" ])])
148
+ add_setpoint (sol, pm, " branch_ne" , " index" , " q_to" , :q_ne ; scale = (x,item) -> x* mva_base, extract_var = (var,idx,item) -> var[(idx, item[" t_bus" ], item[" f_bus" ])])
149
+ end
150
+ end
151
+
152
+
158
153
# ### TNEP specific variables
159
154
160
155
# # Variables associated with building new lines
@@ -192,39 +187,26 @@ function variable_complex_voltage_product_ne{T}(pm::GenericPowerModel{T})
192
187
wr_min, wr_max, wi_min, wi_max = compute_voltage_product_bounds (pm. ext[:ne ]. buspairs, pm. ext[:ne ]. buspair_indexes)
193
188
bi_bp = Dict ([(i, (b[" f_bus" ], b[" t_bus" ])) for (i,b) in pm. ext[:ne ]. branches])
194
189
@variable (pm. model, min (0 , wr_min[bi_bp[b]]) <= wr_ne[b in pm. ext[:ne ]. branch_indexes] <= max (0 , wr_max[bi_bp[b]]), start = getstart (pm. ext[:ne ]. buspairs, bi_bp[b], " wr_start" , 1.0 ))
195
- @variable (pm. model, min (0 , wi_min[bi_bp[b]]) <= wi_ne[b in pm. ext[:ne ]. branch_indexes] <= max (0 , wi_max[bi_bp[b]]), start = getstart (pm. ext[:ne ]. buspairs, bi_bp[b], " wr_start " ))
190
+ @variable (pm. model, min (0 , wi_min[bi_bp[b]]) <= wi_ne[b in pm. ext[:ne ]. branch_indexes] <= max (0 , wi_max[bi_bp[b]]), start = getstart (pm. ext[:ne ]. buspairs, bi_bp[b], " wi_start " ))
196
191
return wr_ne, wi_ne
197
192
end
198
193
199
- function variable_active_line_flow_ne {T} (pm:: GenericPowerModel{T} ; bounded = true )
200
- if bounded
201
- @variable (pm. model, - pm. ext[:ne ]. branches[l][" rate_a" ] <= p_ne[(l,i,j) in pm. ext[:ne ]. arcs] <= pm. ext[:ne ]. branches[l][" rate_a" ], start = getstart (pm. ext[:ne ]. branches, l, " p_start" ))
202
- else
203
- @variable (pm. model, p[(l,i,j) in pm. ext[:ne ]. arcs], start = getstart (pm. ext[:ne ]. branches, l, " p_start" ))
204
- end
194
+ function variable_active_line_flow_ne {T} (pm:: GenericPowerModel{T} )
195
+ @variable (pm. model, - pm. ext[:ne ]. branches[l][" rate_a" ] <= p_ne[(l,i,j) in pm. ext[:ne ]. arcs] <= pm. ext[:ne ]. branches[l][" rate_a" ], start = getstart (pm. ext[:ne ]. branches, l, " p_start" ))
205
196
return p_ne
206
197
end
207
198
208
- function variable_active_line_flow_ne {T <: StandardDCPForm} (pm:: GenericPowerModel{T} ; bounded = true )
209
- if bounded
210
- @variable (pm. model, - pm. ext[:ne ]. branches[l][" rate_a" ] <= p_ne[(l,i,j) in pm. ext[:ne ]. arcs_from] <= pm. ext[:ne ]. branches[l][" rate_a" ], start = getstart (pm. ext[:ne ]. branches, l, " p_start" ))
211
- else
212
- @variable (pm. model, p_ne[(l,i,j) in pm. ext[:ne ]. arcs_from], start = getstart (pm. ext[:ne ]. branches, l, " p_start" ))
213
- end
214
-
199
+ function variable_active_line_flow_ne {T <: StandardDCPForm} (pm:: GenericPowerModel{T} )
200
+ @variable (pm. model, - pm. ext[:ne ]. branches[l][" rate_a" ] <= p_ne[(l,i,j) in pm. ext[:ne ]. arcs_from] <= pm. ext[:ne ]. branches[l][" rate_a" ], start = getstart (pm. ext[:ne ]. branches, l, " p_start" ))
201
+
215
202
p_ne_expr = Dict ([((l,i,j), 1.0 * p_ne[(l,i,j)]) for (l,i,j) in pm. ext[:ne ]. arcs_from])
216
203
p_ne_expr = merge (p_ne_expr, Dict ([((l,j,i), - 1.0 * p_ne[(l,i,j)]) for (l,i,j) in pm. ext[:ne ]. arcs_from]))
217
204
218
205
pm. model. ext[:p_ne_expr ] = p_ne_expr
219
206
end
220
207
221
-
222
- function variable_reactive_line_flow_ne {T} (pm:: GenericPowerModel{T} ; bounded = true )
223
- if bounded
224
- @variable (pm. model, - pm. ext[:ne ]. branches[l][" rate_a" ] <= q_ne[(l,i,j) in pm. ext[:ne ]. arcs] <= pm. ext[:ne ]. branches[l][" rate_a" ], start = getstart (pm. ext[:ne ]. branches, l, " q_start" ))
225
- else
226
- @variable (pm. model, q_ne[(l,i,j) in pm. ext[:ne ]. arcs], start = getstart (pm. ext[:ne ]. branches, l, " q_start" ))
227
- end
208
+ function variable_reactive_line_flow_ne {T} (pm:: GenericPowerModel{T} )
209
+ @variable (pm. model, - pm. ext[:ne ]. branches[l][" rate_a" ] <= q_ne[(l,i,j) in pm. ext[:ne ]. arcs] <= pm. ext[:ne ]. branches[l][" rate_a" ], start = getstart (pm. ext[:ne ]. branches, l, " q_start" ))
228
210
return q_ne
229
211
end
230
212
@@ -233,7 +215,6 @@ function variable_reactive_line_flow_ne{T <: AbstractDCPForm}(pm::GenericPowerMo
233
215
end
234
216
235
217
236
-
237
218
# ### TNEP specific objectives
238
219
239
220
# ## Cost of building lines
@@ -243,6 +224,7 @@ function objective_tnep_cost{T}(pm::GenericPowerModel{T})
243
224
return @objective (pm. model, Min, sum{ branches[i][" construction_cost" ]* line_ne[i], (i,branch) in branches} )
244
225
end
245
226
227
+
246
228
# ### TNEP specific constraints
247
229
248
230
function constraint_active_ohms_yt_ne {T <: AbstractACPForm} (pm:: GenericPowerModel{T} , branch)
648
630
649
631
650
632
651
- # #### TNEP specific solution extractors
652
- function add_branch_ne_setpoint {T} (sol, pm:: GenericPowerModel{T} )
653
- add_setpoint (sol, pm, " branch_ne" , " index" , " built" , :line_ne ; default_value = (item) -> 1 )
654
- end
655
-
656
- function add_branch_flow_setpoint_ne {T} (sol, pm:: GenericPowerModel{T} )
657
- # check the line flows were requested
658
- if haskey (pm. setting, " output" ) && haskey (pm. setting[" output" ], " line_flows" ) && pm. setting[" output" ][" line_flows" ] == true
659
- mva_base = pm. data[" baseMVA" ]
660
-
661
- add_setpoint (sol, pm, " branch_ne" , " index" , " p_from" , :p_ne ; scale = (x,item) -> x* mva_base, extract_var = (var,idx,item) -> var[(idx, item[" f_bus" ], item[" t_bus" ])])
662
- add_setpoint (sol, pm, " branch_ne" , " index" , " q_from" , :q_ne ; scale = (x,item) -> x* mva_base, extract_var = (var,idx,item) -> var[(idx, item[" f_bus" ], item[" t_bus" ])])
663
- add_setpoint (sol, pm, " branch_ne" , " index" , " p_to" , :p_ne ; scale = (x,item) -> x* mva_base, extract_var = (var,idx,item) -> var[(idx, item[" t_bus" ], item[" f_bus" ])])
664
- add_setpoint (sol, pm, " branch_ne" , " index" , " q_to" , :q_ne ; scale = (x,item) -> x* mva_base, extract_var = (var,idx,item) -> var[(idx, item[" t_bus" ], item[" f_bus" ])])
665
- end
666
- end
667
-
668
-
669
633
0 commit comments