@@ -12,11 +12,11 @@ function parse_mp_power_data(filename, N, corrective_action_ratio)
1212 ;
1313 data... ,
1414 refarray = [(i,t) for i in data. ref_buses, t in 1 : N],
15- barray = [(;b, i = i, t = t) for (i, b) in enumerate( data. branch) , t in 1 : N ],
16- busarray = [(;b, i = i, t = t) for (i, b) in enumerate( data. bus) , t in 1 : N ],
17- arcarray = [(;a, i = i, t = t) for (i, a) in enumerate( data. arc) , t in 1 : N ],
18- genarray = [(;g, i = i, t = t) for (i, g) in enumerate( data. gen) , t in 1 : N ],
19- storarray = isempty(data. storage) ? empty_data = empty_stor : [(;s, i = i, t = t) for (i, s) in enumerate( data. storage) , t in 1 : N],
15+ barray = [(;b, t = t) for b in data. branch, t in 1 : N ],
16+ busarray = [(;b, t = t) for b in data. bus, t in 1 : N ],
17+ arcarray = [(;a, t = t) for a in data. arc, t in 1 : N ],
18+ genarray = [(;g, t = t) for g in data. gen, t in 1 : N ],
19+ storarray = isempty(data. storage) ? empty_data = empty_stor : [(;s, t = t) for s in data. storage, t in 1 : N],
2020 Δp = corrective_action_ratio .* (data. pmax .- data. pmin)
2121 )
2222
@@ -30,6 +30,7 @@ function update_load_data(busarray, curve)
3030 b = busarray[x, t]
3131 busarray[x, t] = (
3232 b= ExaPowerIO. BusData(
33+ b. b. i,
3334 b. b. bus_i,
3435 b. b. type,
3536 b. b. pd* curve[t],
@@ -43,7 +44,7 @@ function update_load_data(busarray, curve)
4344 b. b. zone,
4445 b. b. vmax,
4546 b. b. vmin,
46- ), i = b . i, t= t
47+ ), t= t
4748 )
4849 end
4950 end
@@ -55,6 +56,7 @@ function update_load_data(busarray, pd, qd, baseMVA)
5556 b = busarray[idx[1 ], idx[2 ]]
5657 busarray[idx[1 ], idx[2 ]] = (
5758 b= ExaPowerIO. BusData(
59+ b. b. i,
5860 b. b. bus_i,
5961 b. b. type,
6062 pd_t / baseMVA,
@@ -69,7 +71,6 @@ function update_load_data(busarray, pd, qd, baseMVA)
6971 b. b. vmax,
7072 b. b. vmin,
7173 ),
72- i= b. i,
7374 t= idx[2 ],
7475 )
7576 end
@@ -86,24 +87,24 @@ function build_base_mpopf(core, data, N)
8687 p = variable(core, size(data. arc, 1 ), N; lvar = repeat(- data. rate_a, 1 , N), uvar = repeat(data. rate_a, 1 , N))
8788 q = variable(core, size(data. arc, 1 ), N; lvar = repeat(- data. rate_a, 1 , N), uvar = repeat(data. rate_a, 1 , N))
8889
89- o = objective(core, gen_cost(g, pg[i, t]) for (g, i , t) in data. genarray)
90+ o = objective(core, gen_cost(g, pg[g . i, t]) for (g, t) in data. genarray)
9091
9192
9293 c_from_thermal_limit = constraint(
9394 core,
94- c_thermal_limit(b, p[b. f_idx, t], q[b. f_idx, t]) for (b, i, t) in data. barray;
95+ c_thermal_limit(b, p[b. f_idx, t], q[b. f_idx, t]) for (b, t) in data. barray;
9596 lcon = fill(- Inf , size(data. barray))
9697 )
9798
9899 c_to_thermal_limit = constraint(
99100 core,
100- c_thermal_limit(b, p[b. t_idx, t], q[b. t_idx, t]) for (b, i, t) in data. barray;
101+ c_thermal_limit(b, p[b. t_idx, t], q[b. t_idx, t]) for (b, t) in data. barray;
101102 lcon = fill(- Inf , size(data. barray))
102103 )
103104
104105 c_ramp_rate = constraint(
105106 core,
106- c_ramp(pg[i, t- 1 ], pg[i, t]) for (g, i , t) in data. genarray[:, 2 : N];
107+ c_ramp(pg[g . i, t- 1 ], pg[g . i, t]) for (g, t) in data. genarray[:, 2 : N];
107108 lcon = repeat(- data. Δp, 1 , N- 1 ),
108109 ucon = repeat( data. Δp, 1 , N- 1 )
109110 )
@@ -137,25 +138,25 @@ function add_mpopf_cons(core, data, N, Nbus, vars, cons, form)
137138 uvar = repeat(data. vmax, 1 , N),
138139 )
139140
140- c_ref_angle = constraint(core, c_ref_angle_polar(va[i,t]) for (i,t) in data. refarray)
141+ c_ref_angle = constraint(core, c_ref_angle_polar(va[i, t]) for (i, t) in data. refarray)
141142
142- c_to_active_power_flow = constraint(core, c_to_active_power_flow_polar(b, p[b. f_idx, t], vm[b. f_bus, t], vm[b. t_bus, t], va[b. f_bus, t], va[b. t_bus, t]) for (b, i, t) in data. barray)
143+ c_to_active_power_flow = constraint(core, c_to_active_power_flow_polar(b, p[b. f_idx, t], vm[b. f_bus, t], vm[b. t_bus, t], va[b. f_bus, t], va[b. t_bus, t]) for (b, t) in data. barray)
143144
144- c_to_reactive_power_flow = constraint(core, c_to_reactive_power_flow_polar(b, q[b. f_idx, t], vm[b. f_bus, t], vm[b. t_bus, t], va[b. f_bus, t], va[b. t_bus, t]) for (b, i, t) in data. barray)
145+ c_to_reactive_power_flow = constraint(core, c_to_reactive_power_flow_polar(b, q[b. f_idx, t], vm[b. f_bus, t], vm[b. t_bus, t], va[b. f_bus, t], va[b. t_bus, t]) for (b, t) in data. barray)
145146
146- c_from_active_power_flow = constraint(core, c_from_active_power_flow_polar(b, p[b. t_idx, t], vm[b. f_bus, t], vm[b. t_bus, t], va[b. f_bus, t], va[b. t_bus, t]) for (b, i, t) in data. barray)
147+ c_from_active_power_flow = constraint(core, c_from_active_power_flow_polar(b, p[b. t_idx, t], vm[b. f_bus, t], vm[b. t_bus, t], va[b. f_bus, t], va[b. t_bus, t]) for (b, t) in data. barray)
147148
148- c_from_reactive_power_flow = constraint(core, c_from_reactive_power_flow_polar(b, q[b. t_idx, t], vm[b. f_bus, t], vm[b. t_bus, t], va[b. f_bus, t], va[b. t_bus, t]) for (b, i, t) in data. barray)
149+ c_from_reactive_power_flow = constraint(core, c_from_reactive_power_flow_polar(b, q[b. t_idx, t], vm[b. f_bus, t], vm[b. t_bus, t], va[b. f_bus, t], va[b. t_bus, t]) for (b, t) in data. barray)
149150
150151 c_phase_angle_diff = constraint(
151152 core,
152- c_phase_angle_diff_polar(b, va[b. f_bus, t], va[b. t_bus, t]) for (b, i, t) in data. barray;
153+ c_phase_angle_diff_polar(b, va[b. f_bus, t], va[b. t_bus, t]) for (b, t) in data. barray;
153154 lcon = repeat(data. angmin, 1 , N),
154155 ucon = repeat(data. angmax, 1 , N),
155156 )
156157
157- c_active_power_balance = constraint(core, c_active_power_balance_demand_polar(b, vm[i, t]) for (b, i , t) in data. busarray)
158- c_reactive_power_balance = constraint(core, c_reactive_power_balance_demand_polar(b, vm[i, t]) for (b, i , t) in data. busarray)
158+ c_active_power_balance = constraint(core, c_active_power_balance_demand_polar(b, vm[b . i, t]) for (b, t) in data. busarray)
159+ c_reactive_power_balance = constraint(core, c_reactive_power_balance_demand_polar(b, vm[b . i, t]) for (b, t) in data. busarray)
159160
160161 cons = (;cons... ,
161162 c_ref_angle = c_ref_angle,
@@ -176,27 +177,27 @@ function add_mpopf_cons(core, data, N, Nbus, vars, cons, form)
176177
177178 c_ref_angle = constraint(core, c_ref_angle_rect(vr[i, t], vim[i, t]) for (i, t) in data. refarray)
178179
179- c_to_active_power_flow = constraint(core, c_to_active_power_flow_rect(b, p[b. f_idx, t], vr[b. f_bus, t], vr[b. t_bus, t], vim[b. f_bus, t], vim[b. t_bus, t]) for (b, i, t) in data. barray)
180+ c_to_active_power_flow = constraint(core, c_to_active_power_flow_rect(b, p[b. f_idx, t], vr[b. f_bus, t], vr[b. t_bus, t], vim[b. f_bus, t], vim[b. t_bus, t]) for (b, t) in data. barray)
180181
181- c_to_reactive_power_flow = constraint(core, c_to_reactive_power_flow_rect(b, q[b. f_idx, t], vr[b. f_bus, t], vr[b. t_bus, t], vim[b. f_bus, t], vim[b. t_bus, t]) for (b, i, t) in data. barray)
182+ c_to_reactive_power_flow = constraint(core, c_to_reactive_power_flow_rect(b, q[b. f_idx, t], vr[b. f_bus, t], vr[b. t_bus, t], vim[b. f_bus, t], vim[b. t_bus, t]) for (b, t) in data. barray)
182183
183- c_from_active_power_flow = constraint(core, c_from_active_power_flow_rect(b, p[b. t_idx, t], vr[b. f_bus, t], vr[b. t_bus, t], vim[b. f_bus, t], vim[b. t_bus, t]) for (b, i, t) in data. barray)
184+ c_from_active_power_flow = constraint(core, c_from_active_power_flow_rect(b, p[b. t_idx, t], vr[b. f_bus, t], vr[b. t_bus, t], vim[b. f_bus, t], vim[b. t_bus, t]) for (b, t) in data. barray)
184185
185- c_from_reactive_power_flow = constraint(core, c_from_reactive_power_flow_rect(b, q[b. t_idx, t], vr[b. f_bus, t], vr[b. t_bus, t], vim[b. f_bus, t], vim[b. t_bus, t]) for (b, i, t) in data. barray)
186+ c_from_reactive_power_flow = constraint(core, c_from_reactive_power_flow_rect(b, q[b. t_idx, t], vr[b. f_bus, t], vr[b. t_bus, t], vim[b. f_bus, t], vim[b. t_bus, t]) for (b, t) in data. barray)
186187
187188 c_phase_angle_diff = constraint(
188189 core,
189- c_phase_angle_diff_rect(b, vr[b. f_bus, t], vr[b. t_bus, t], vim[b. f_bus, t], vim[b. t_bus, t]) for (b, i, t) in data. barray;
190+ c_phase_angle_diff_rect(b, vr[b. f_bus, t], vr[b. t_bus, t], vim[b. f_bus, t], vim[b. t_bus, t]) for (b, t) in data. barray;
190191 lcon = repeat(data. angmin, 1 , N),
191192 ucon = repeat(data. angmax, 1 , N),
192193 )
193194
194- c_active_power_balance = constraint(core, c_active_power_balance_demand_rect(b, vr[i, t], vim[i, t]) for (b, i , t) in data. busarray)
195- c_reactive_power_balance = constraint(core, c_reactive_power_balance_demand_rect(b, vr[i, t], vim[i, t]) for (b, i , t) in data. busarray)
195+ c_active_power_balance = constraint(core, c_active_power_balance_demand_rect(b, vr[b . i, t], vim[b . i, t]) for (b, t) in data. busarray)
196+ c_reactive_power_balance = constraint(core, c_reactive_power_balance_demand_rect(b, vr[b . i, t], vim[b . i, t]) for (b, t) in data. busarray)
196197
197198 c_voltage_magnitude = constraint(
198- core, c_voltage_magnitude_rect(vr[i, t], vim[i, t])
199- for (b, i, t) in data. busarray;
199+ core, c_voltage_magnitude_rect(vr[b . i, t], vim[b . i, t])
200+ for (b, t) in data. busarray;
200201 lcon = repeat(data. vmin, 1 , N). ^ 2 ,
201202 ucon = repeat(data. vmax, 1 , N). ^ 2
202203 )
@@ -215,11 +216,11 @@ function add_mpopf_cons(core, data, N, Nbus, vars, cons, form)
215216
216217 end
217218
218- c_active_power_balance_arcs = constraint!(core, c_active_power_balance, a. bus + Nbus* (t- 1 ) => p[i, t] for (a, i , t) in data. arcarray)
219- c_reactive_power_balance_arcs = constraint!(core, c_reactive_power_balance, a. bus + Nbus* (t- 1 ) => q[i, t] for (a, i , t) in data. arcarray)
219+ c_active_power_balance_arcs = constraint!(core, c_active_power_balance, a. bus + Nbus* (t- 1 ) => p[a . i, t] for (a, t) in data. arcarray)
220+ c_reactive_power_balance_arcs = constraint!(core, c_reactive_power_balance, a. bus + Nbus* (t- 1 ) => q[a . i, t] for (a, t) in data. arcarray)
220221
221- c_active_power_balance_gen = constraint!(core, c_active_power_balance, g. bus + Nbus* (t- 1 ) => - pg[i, t] for (g, i , t) in data. genarray)
222- c_reactive_power_balance_gen = constraint!(core, c_reactive_power_balance, g. bus + Nbus* (t- 1 ) => - qg[i, t] for (g, i , t) in data. genarray)
222+ c_active_power_balance_gen = constraint!(core, c_active_power_balance, g. bus + Nbus* (t- 1 ) => - pg[g . i, t] for (g, t) in data. genarray)
223+ c_reactive_power_balance_gen = constraint!(core, c_reactive_power_balance, g. bus + Nbus* (t- 1 ) => - qg[g . i, t] for (g, t) in data. genarray)
223224
224225 return vars, cons
225226end
@@ -279,20 +280,20 @@ function build_mpopf_stor_main(core, data, N, Nbus, vars, cons, form)
279280 c_active_power_balance = cons. c_active_power_balance
280281 c_reactive_power_balance = cons. c_reactive_power_balance
281282
282- c_active_power_balance_stor = constraint!(core, c_active_power_balance, s. storage_bus + Nbus* (t- 1 ) => pst[i, t] for (s, i , t) in data. storarray)
283- c_reactive_power_balance_stor = constraint!(core, c_reactive_power_balance, s. storage_bus + Nbus* (t- 1 ) => qst[i, t] for (s, i , t) in data. storarray)
283+ c_active_power_balance_stor = constraint!(core, c_active_power_balance, s. storage_bus + Nbus* (t- 1 ) => pst[s . i, t] for (s, t) in data. storarray)
284+ c_reactive_power_balance_stor = constraint!(core, c_reactive_power_balance, s. storage_bus + Nbus* (t- 1 ) => qst[s . i, t] for (s, t) in data. storarray)
284285
285- c_reactive_storage_power = constraint(core, c_reactive_stor_power(s, qst[i, t], qint[i, t], I2[i, t]) for (s, i , t) in data. storarray)
286+ c_reactive_storage_power = constraint(core, c_reactive_stor_power(s, qst[s . i, t], qint[s . i, t], I2[s . i, t]) for (s, t) in data. storarray)
286287
287- c_storage_transfer_thermal_limit = constraint(core, c_transfer_lim(s, pst[i, t], qst[i, t]) for (s, i , t) in data. storarray; lcon = fill(- Inf , size(data. storarray)))
288+ c_storage_transfer_thermal_limit = constraint(core, c_transfer_lim(s, pst[s . i, t], qst[s . i, t]) for (s, t) in data. storarray; lcon = fill(- Inf , size(data. storarray)))
288289
289290 if form == :polar
290291 vm = vars. vm
291- c_ohms = constraint(core, c_ohms_polar(pst[i, t], qst[i, t], vm[s. storage_bus, t], I2[i, t]) for (s, i , t) in data. storarray)
292+ c_ohms = constraint(core, c_ohms_polar(pst[s . i, t], qst[s . i, t], vm[s. storage_bus, t], I2[s . i, t]) for (s, t) in data. storarray)
292293 elseif form == :rect
293294 vr = vars. vr
294295 vim = vars. vim
295- c_ohms = constraint(core, c_ohms_rect(pst[i, t], qst[i, t], vr[s. storage_bus, t], vim[s. storage_bus, t], I2[i, t]) for (s, i , t) in data. storarray)
296+ c_ohms = constraint(core, c_ohms_rect(pst[s . i, t], qst[s . i, t], vr[s. storage_bus, t], vim[s. storage_bus, t], I2[s . i, t]) for (s, t) in data. storarray)
296297 end
297298
298299 cons = (;cons... , c_reactive_storage_power = c_reactive_storage_power, c_storage_transfer_thermal_limit = c_storage_transfer_thermal_limit, c_ohms= c_ohms)
@@ -309,19 +310,19 @@ function add_piecewise_cons(core, data, N, vars, cons, storage_complementarity_c
309310 I2 = vars. I2
310311 E = vars. E
311312
312- c_active_storage_power = constraint(core, c_active_stor_power(s, pst[i, t], pstd[i, t], pstc[i, t], I2[i, t]) for (s, i , t) in data. storarray)
313+ c_active_storage_power = constraint(core, c_active_stor_power(s, pst[s . i, t], pstd[s . i, t], pstc[s . i, t], I2[s . i, t]) for (s, t) in data. storarray)
313314
314- c_storage_state = constraint(core, c_stor_state(s, E[i, t], E[i, t - 1 ], pstc[i, t], pstd[i, t]) for (s, i , t) in data. storarray[:, 2 : N])
315+ c_storage_state = constraint(core, c_stor_state(s, E[s . i, t], E[s . i, t - 1 ], pstc[s . i, t], pstd[s . i, t]) for (s, t) in data. storarray[:, 2 : N])
315316
316- c_storage_state_init = constraint(core, c_stor_state(s, E[i, t], s. energy, pstc[i, t], pstd[i, t]) for (s, i , t) in data. storarray[:, 1 ])
317+ c_storage_state_init = constraint(core, c_stor_state(s, E[s . i, t], s. energy, pstc[s . i, t], pstd[s . i, t]) for (s, t) in data. storarray[:, 1 ])
317318
318- c_discharge_thermal_limit = constraint(core, c_discharge_lim(pstd[i, t], pstc[i, t]) for (s, i , t) in data. storarray; lcon = - repeat(data. srating, 1 , N), ucon = repeat(data. srating, 1 , N))
319+ c_discharge_thermal_limit = constraint(core, c_discharge_lim(pstd[s . i, t], pstc[s . i, t]) for (s, t) in data. storarray; lcon = - repeat(data. srating, 1 , N), ucon = repeat(data. srating, 1 , N))
319320
320- c_discharge_positivity = constraint(core, pstd[i, t] for (s, i , t) in data. storarray; ucon = fill(Inf , size(data. storarray)))
321+ c_discharge_positivity = constraint(core, pstd[s . i, t] for (s, t) in data. storarray; ucon = fill(Inf , size(data. storarray)))
321322
322323 # Complimentarity constraint
323324 if storage_complementarity_constraint
324- c_complementarity = constraint(core, c_comp(pstc[i, t], pstd[i, t]) for (s, i , t) in data. storarray)
325+ c_complementarity = constraint(core, c_comp(pstc[s . i, t], pstd[s . i, t]) for (s, t) in data. storarray)
325326 cons = (;cons... , c_complementarity = c_complementarity)
326327 end
327328
@@ -341,13 +342,13 @@ function add_smooth_cons(core, data, N, vars, cons, discharge_func)
341342 I2 = vars. I2
342343 E = vars. E
343344
344- c_active_storage_power = constraint(core, c_active_storage_power_smooth(s, pst[i, t], pstd[i, t], I2[i, t]) for (s, i , t) in data. storarray)
345+ c_active_storage_power = constraint(core, c_active_storage_power_smooth(s, pst[s . i, t], pstd[s . i, t], I2[s . i, t]) for (s, t) in data. storarray)
345346
346- c_storage_state = constraint(core, c_storage_state_smooth(s, E[i, t], E[i, t - 1 ], discharge_func, pstd[i, t]) for (s, i , t) in data. storarray[:, 2 : N])
347+ c_storage_state = constraint(core, c_storage_state_smooth(s, E[s . i, t], E[s . i, t - 1 ], discharge_func, pstd[s . i, t]) for (s, t) in data. storarray[:, 2 : N])
347348
348- c_storage_state_init = constraint(core, c_storage_state_smooth(s, E[i, t], s. energy, discharge_func, pstd[i, t]) for (s, i , t) in data. storarray[:, 1 ])
349+ c_storage_state_init = constraint(core, c_storage_state_smooth(s, E[s . i, t], s. energy, discharge_func, pstd[s . i, t]) for (s, t) in data. storarray[:, 1 ])
349350
350- c_discharge_thermal_limit = constraint(core, c_discharge_limit_smooth(pstd[i, t]) for (s, i , t) in data. storarray; lcon = - repeat(data. srating, 1 , N), ucon = repeat(data. srating, 1 , N))
351+ c_discharge_thermal_limit = constraint(core, c_discharge_limit_smooth(pstd[s . i, t]) for (s, t) in data. storarray; lcon = - repeat(data. srating, 1 , N), ucon = repeat(data. srating, 1 , N))
351352
352353 cons = (;cons... ,
353354 c_active_storage_power = c_active_storage_power,
0 commit comments