-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBT.jl
374 lines (315 loc) · 16.6 KB
/
BT.jl
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
Slmax=ELcap*Branchdata[:,6]/baseMVA;
function FBBT!(bounds)
ep=1e-10;
Theta_min = bounds.Theta_min
V_min = bounds.V_min
RE_min = bounds.RE_min
LE_min = bounds.LE_min
CR_min = bounds.CR_min
SR_min = bounds.SR_min
Theta_max = bounds.Theta_max
V_max = bounds.V_max
RE_max = bounds.RE_max
LE_max = bounds.LE_max
CR_max = bounds.CR_max
SR_max = bounds.SR_max
for iter = 1:5
for i in 1:Num_Eline
# PLe_R[i] = GE_tt[i]*Ui[Branchdata[i,2]]+GE_tf[i]*RE[i]-BE_tf[i]*LE[i]
# PLe_S[i] = GE_ff[i]*Ui[Branchdata[i,1]]+GE_ft[i]*RE[i]+BE_ft[i]*LE[i]
# QLe_S[i] = -BE_ff[i]*Ui[Branchdata[i,1]]-BE_ft[i]*RE[i]+GE_ft[i]*LE[i]
# QLe_R[i] = -BE_tt[i]*Ui[Branchdata[i,2]]-BE_tf[i]*RE[i]-GE_tf[i]*LE[i]
# GE_tf GE_ft BE_ff BE_tt negative
LE_min[i]=max(LE_min[i],((GE_tt[i]*V_min[Branchdata[i,2]]^2+GE_tf[i]*RE_max[i]-Slmax[i])/BE_tf[i])-ep,
((-GE_ff[i]*V_max[Branchdata[i,1]]^2-GE_ft[i]*RE_min[i]-Slmax[i])/BE_ft[i])-ep,
(-BE_ff[i]*V_min[Branchdata[i,1]]^2-BE_ft[i]*RE_max[i]-Slmax[i])/(-GE_ft[i])-ep,
( BE_tt[i]*V_max[Branchdata[i,2]]^2+BE_tf[i]*RE_min[i]-Slmax[i])/(-GE_tf[i])-ep)
LE_max[i]=min(LE_max[i],((GE_tt[i]*V_max[Branchdata[i,2]]^2+GE_tf[i]*RE_min[i]+Slmax[i])/BE_tf[i])+ep,
((-GE_ff[i]*V_min[Branchdata[i,1]]^2-GE_ft[i]*RE_max[i]+Slmax[i])/BE_ft[i])+ep,
(-BE_ff[i]*V_max[Branchdata[i,1]]^2-BE_ft[i]*RE_min[i]+Slmax[i])/(-GE_ft[i])+ep,
( BE_tt[i]*V_min[Branchdata[i,2]]^2+BE_tf[i]*RE_max[i]+Slmax[i])/(-GE_tf[i])+ep)
RE_min[i]=max(RE_min[i],((GE_tt[i]*V_min[Branchdata[i,2]]^2-BE_tf[i]*LE_max[i]-Slmax[i])/(-GE_tf[i]))-ep,
((GE_ff[i]*V_min[Branchdata[i,1]]^2+BE_ft[i]*LE_min[i]-Slmax[i])/(-GE_ft[i]))-ep,
((-BE_ff[i]*V_min[Branchdata[i,1]]^2+GE_ft[i]*LE_max[i]-Slmax[i])/BE_ft[i])-ep,
((-BE_tt[i]*V_min[Branchdata[i,2]]^2-GE_tf[i]*LE_min[i]-Slmax[i])/BE_tf[i])-ep)
RE_max[i]=min(RE_max[i],((GE_tt[i]*V_max[Branchdata[i,2]]^2-BE_tf[i]*LE_min[i]+Slmax[i])/(-GE_tf[i]))+ep,
((GE_ff[i]*V_max[Branchdata[i,1]]^2+BE_ft[i]*LE_max[i]+Slmax[i])/(-GE_ft[i]))+ep,
((-BE_ff[i]*V_max[Branchdata[i,1]]^2+GE_ft[i]*LE_min[i]+Slmax[i])/BE_ft[i])+ep,
((-BE_tt[i]*V_max[Branchdata[i,2]]^2-GE_tf[i]*LE_max[i]+Slmax[i])/BE_tf[i])+ep)
# PLe_R[i] = GE_tt[i]*Ui[Branchdata[i,2]]+GE_tf[i]*RE[i]-BE_tf[i]*LE[i]
# PLe_S[i] = GE_ff[i]*Ui[Branchdata[i,1]]+GE_ft[i]*RE[i]+BE_ft[i]*LE[i]
# QLe_S[i] = -BE_ff[i]*Ui[Branchdata[i,1]]-BE_ft[i]*RE[i]+GE_ft[i]*LE[i]
# QLe_R[i] = -BE_tt[i]*Ui[Branchdata[i,2]]-BE_tf[i]*RE[i]-GE_tf[i]*LE[i]
# GE_tf GE_ft BE_ff BE_tt negative
Ui1_min = max(0, ((-GE_ft[i]*RE_min[i]-BE_ft[i]*LE_max[i]-Slmax[i])/GE_ff[i]),
(BE_ft[i]*RE_min[i]-GE_ft[i]*LE_min[i]-Slmax[i])/(-BE_ff[i]))
Ui1_max = min(((-GE_ft[i]*RE_max[i]-BE_ft[i]*LE_min[i]+Slmax[i])/GE_ff[i]),
(BE_ft[i]*RE_max[i]-GE_ft[i]*LE_max[i]+Slmax[i])/(-BE_ff[i]))
Ui2_min = max(0, ((-GE_tf[i]*RE_min[i]+BE_tf[i]*LE_min[i]-Slmax[i])/GE_tt[i]),
(BE_tf[i]*RE_min[i]+GE_tf[i]*LE_max[i]-Slmax[i])/(-BE_tt[i]))
Ui2_max = min(((-GE_tf[i]*RE_max[i]+BE_tf[i]*LE_max[i]+Slmax[i])/GE_tt[i]),
(BE_tf[i]*RE_max[i]+GE_tf[i]*LE_min[i]+Slmax[i])/(-BE_tt[i]))
if Ui1_max <0 || Ui1_max<Ui1_min
println("i ",i)
println("Ui1_max:", Ui1_max)
break
end
V_min[Branchdata[i,1]] = max(V_min[Branchdata[i,1]], sqrt(Ui1_min)-ep)
V_max[Branchdata[i,1]] = min(V_max[Branchdata[i,1]], sqrt(Ui1_max)+ep)
V_min[Branchdata[i,2]] = max(V_min[Branchdata[i,2]], sqrt(Ui1_min)-ep)
V_max[Branchdata[i,2]] = min(V_max[Branchdata[i,2]], sqrt(Ui1_max)+ep)
#CR = cos(Theta)
CR_min[i] = max(CR_min[i], min(cos(Theta_min[i]), cos(Theta_max[i]))-ep)
CR_max[i] = min(CR_max[i], 1)
if Theta_min[i] >=0 || Theta_max[i]<=0
CR_max[i] = min(CR_max[i], max(cos(Theta_min[i]), cos(Theta_max[i]))+ep)
end
#Theta = acos(CR)
if Theta_max[i]<=0
Theta_min[i] = max(Theta_min[i], -acos(CR_min[i])-ep)
Theta_max[i] = min(Theta_max[i], -acos(CR_max[i])+ep)
elseif Theta_min[i] >=0
Theta_min[i] = max(Theta_min[i], acos(CR_max[i])-ep)
Theta_max[i] = min(Theta_max[i], acos(CR_min[i])+ep)
else
Theta_min[i] = max(Theta_min[i], -acos(CR_min[i])-ep)
Theta_max[i] = min(Theta_max[i], acos(CR_min[i])+ep)
end
#SR = LE/Vi/Vj
SR_min[i]=max(SR_min[i], min(LE_min[i]/(V_min[Branchdata[i,1]]*V_min[Branchdata[i,2]]), LE_min[i]/(V_max[Branchdata[i,1]]*V_max[Branchdata[i,2]]))-ep)
SR_max[i]=min(SR_max[i], max(LE_max[i]/(V_min[Branchdata[i,1]]*V_min[Branchdata[i,2]]), LE_max[i]/(V_max[Branchdata[i,1]]*V_max[Branchdata[i,2]]))+ep)
#SR = sin(Theta)
SR_min[i] = max(SR_min[i], sin(Theta_min[i])-ep)
SR_max[i] = min(SR_max[i], sin(Theta_max[i])+ep)
#Theta = asin(SR)
Theta_min[i] = max(Theta_min[i], asin(SR_min[i])-ep)
Theta_max[i] = min(Theta_max[i], asin(SR_max[i])+ep)
#RE = CR*Vi*Vj
RE_min[i] = max(RE_min[i], CR_min[i]*V_min[Branchdata[i,1]]*V_min[Branchdata[i,2]]-ep)
RE_max[i] = min(RE_max[i], CR_max[i]*V_max[Branchdata[i,1]]*V_max[Branchdata[i,2]]+ep)
#LE = SR*Vi*Vj
if SR_max[i]<=0
LE_min[i] = max(LE_min[i], SR_min[i]*V_max[Branchdata[i,1]]*V_max[Branchdata[i,2]]-ep)
LE_max[i] = min(LE_max[i], SR_max[i]*V_min[Branchdata[i,1]]*V_min[Branchdata[i,2]]+ep)
elseif SR_min[i]>=0
LE_min[i] = max(LE_min[i], SR_min[i]*V_min[Branchdata[i,1]]*V_min[Branchdata[i,2]]-ep)
LE_max[i] = min(LE_max[i], SR_max[i]*V_max[Branchdata[i,1]]*V_max[Branchdata[i,2]]+ep)
else
LE_min[i] = max(LE_min[i], SR_min[i]*V_max[Branchdata[i,1]]*V_max[Branchdata[i,2]]-ep)
LE_max[i] = min(LE_max[i], SR_max[i]*V_max[Branchdata[i,1]]*V_max[Branchdata[i,2]]+ep)
end
#RE^2+LE^2 == UiUj
if LE_max[i] >= 0 && LE_min[i] <= 0
ss_min = min(RE_min[i]^2, RE_max[i]^2) + 0
else
ss_min = min(RE_min[i]^2, RE_max[i]^2) + min(LE_min[i]^2, LE_max[i]^2)
end
ss_max = max(RE_min[i]^2, RE_max[i]^2) + max(LE_min[i]^2, LE_max[i]^2)
Ui1_min = ss_min/V_max[Branchdata[i,2]]/V_max[Branchdata[i,2]]
Ui1_max = ss_max/V_min[Branchdata[i,2]]/V_min[Branchdata[i,2]]
Ui2_min = ss_min/V_max[Branchdata[i,1]]/V_max[Branchdata[i,1]]
Ui2_max = ss_max/V_min[Branchdata[i,1]]/V_min[Branchdata[i,1]]
V_min[Branchdata[i,1]] = max(V_min[Branchdata[i,1]], sqrt(Ui1_min)-ep)
V_max[Branchdata[i,1]] = min(V_max[Branchdata[i,1]], sqrt(Ui1_max)+ep)
V_min[Branchdata[i,2]] = max(V_min[Branchdata[i,2]], sqrt(Ui1_min)-ep)
V_max[Branchdata[i,2]] = min(V_max[Branchdata[i,2]], sqrt(Ui1_max)+ep)
#Theta = atan(LE/RE)
if RE_min[i] >= 1e-4
at_min = min(LE_min[i]/RE_max[i], LE_min[i]/RE_min[i], LE_max[i]/RE_max[i], LE_max[i]/RE_min[i])
at_max = max(LE_min[i]/RE_max[i], LE_min[i]/RE_min[i], LE_max[i]/RE_max[i], LE_max[i]/RE_min[i])
Theta_min[i] = max(Theta_min[i], atan(at_min)-ep)
Theta_max[i] = min(Theta_max[i], atan(at_max)+ep)
end
end
end
return bounds;
end
function OBBT!(bounds, UB)
for iter=1:2
FBBT!(bounds);
println("FBBT bounds.V_min bounds.V_max: ", bounds.V_min, bounds.V_max)
println("FBBT bounds.Theta_min bounds.Theta_max: ", bounds.Theta_min, bounds.Theta_max)
println("FBBT bounds.RE_min bounds.RE_max: ", bounds.RE_min, bounds.RE_max)
println("FBBT bounds.LE_min bounds.LE_max: ", bounds.LE_min, bounds.LE_max)
println("FBBT bounds.CR_min bounds.CR_max: ", bounds.CR_min, bounds.CR_max)
println("FBBT bounds.SR_min bounds.SR_max: ", bounds.SR_min, bounds.SR_max)
@everywhere epsilon = 1e-4
@eval @everywhere bounds = $bounds
@eval @everywhere UB = $UB
@everywhere function local_V(i)
ob = relax(bounds,RT,K);
@constraint(ob,sum(Linedata_candidate[j,6]*ob[:XL][j] for j in 1:Num_Cline)+(1/100)*sum(ob[:Pg][j] for j in 1:Num_gen)<=UB);
set_optimizer_attribute(ob, "CPX_PARAM_TILIM", 120)#Time limit
set_optimizer_attribute(ob, "CPX_PARAM_SCRIND", false)#NO solver print
set_optimizer_attribute(ob, "CPX_PARAM_PARALLELMODE", 0)#parallel mode switch
@objective(ob, Min, ob[:Vi][i])
optimize!(ob);
min_value = max(objective_bound(ob) - epsilon, bounds.V_min[i])
println(i, " max")
@objective(ob, Max, ob[:Vi][i])
optimize!(ob);
max_value = min(objective_bound(ob) + epsilon, bounds.V_max[i])
@objective(ob, Min, ob[:Ui][i])
optimize!(ob);
min_value = max(sqrt(objective_bound(ob)) - epsilon, min_value)
@objective(ob, Max, ob[:Ui][i])
optimize!(ob);
max_value = min(sqrt(objective_bound(ob)) + epsilon, max_value)
return [min_value, max_value]
end
res = pmap(local_V, 1:Num_bus)
red = ones(Num_bus)
for i=1:Num_bus
if (bounds.V_max[i]-bounds.V_min[i])>=1e-4
min_value = res[i][1]
max_value = res[i][2]
red[i] = (max_value-min_value)/(bounds.V_max[i]-bounds.V_min[i])
bounds.V_min[i] = min_value
bounds.V_max[i] = max_value
end
end
println("OBBT bounds.V_min bounds.V_max: ", mean(red))
println(bounds.V_min, bounds.V_max)
@eval @everywhere bounds = $bounds
@everywhere function local_Theta(i)
ob = relax(bounds,RT,K);
@constraint(ob,sum(Linedata_candidate[j,6]*ob[:XL][j] for j in 1:Num_Cline)+(1/100)*sum(ob[:Pg][j] for j in 1:Num_gen)<=UB);
set_optimizer_attribute(ob, "CPX_PARAM_TILIM", 120)#Time limit
set_optimizer_attribute(ob, "CPX_PARAM_SCRIND", false)#NO solver print
set_optimizer_attribute(ob, "CPX_PARAM_PARALLELMODE", 0)#parallel mode switch
@objective(ob, Min, ob[:Theta][i])
optimize!(ob);
min_value = max(objective_bound(ob) - epsilon, bounds.Theta_min[i])
@objective(ob, Max, ob[:Theta][i])
optimize!(ob);
max_value = min(objective_bound(ob) + epsilon, bounds.Theta_max[i])
return [min_value, max_value]
end
res = pmap(local_Theta, 1:Num_Eline)
red = ones(Num_Eline)
for i=1:Num_Eline
if (bounds.Theta_max[i]- bounds.Theta_min[i])>=1e-4
min_value = res[i][1]
max_value = res[i][2]
red[i] = (max_value-min_value)/(bounds.Theta_max[i]- bounds.Theta_min[i])
bounds.Theta_min[i] = min_value
bounds.Theta_max[i] = max_value
end
end
println("OBBT bounds.Theta_min bounds.Theta_max: ", mean(red))
println(bounds.Theta_min, bounds.Theta_max)
@eval @everywhere bounds = $bounds
@everywhere function local_RE(i)
ob = relax(bounds,RT,K);
@constraint(ob,sum(Linedata_candidate[j,6]*ob[:XL][j] for j in 1:Num_Cline)+(1/100)*sum(ob[:Pg][j] for j in 1:Num_gen)<=UB);
set_optimizer_attribute(ob, "CPX_PARAM_TILIM", 120)#Time limit
set_optimizer_attribute(ob, "CPX_PARAM_SCRIND", false)#NO solver print
set_optimizer_attribute(ob, "CPX_PARAM_PARALLELMODE", 0)#parallel mode switch
@objective(ob, Min, ob[:RE][i])
optimize!(ob);
min_value = max(objective_bound(ob) - epsilon, bounds.RE_min[i])
@objective(ob, Max, ob[:RE][i])
optimize!(ob);
max_value = min(objective_bound(ob) + epsilon, bounds.RE_max[i])
return [min_value, max_value]
end
res = pmap(local_RE, 1:Num_Eline)
red = ones(Num_Eline)
for i=1:Num_Eline
if (bounds.RE_max[i]- bounds.RE_min[i])>=1e-4
min_value = res[i][1]
max_value = res[i][2]
red[i] = (max_value-min_value)/(bounds.RE_max[i]- bounds.RE_min[i])
bounds.RE_min[i] = min_value
bounds.RE_max[i] = max_value
end
end
println("OBBT bounds.RE_min bounds.RE_max: ", mean(red))
println(bounds.RE_min, bounds.RE_max)
@eval @everywhere bounds = $bounds
@everywhere function local_LE(i)
ob = relax(bounds,RT,K);
@constraint(ob,sum(Linedata_candidate[j,6]*ob[:XL][j] for j in 1:Num_Cline)+(1/100)*sum(ob[:Pg][j] for j in 1:Num_gen)<=UB);
set_optimizer_attribute(ob, "CPX_PARAM_TILIM", 120)#Time limit
set_optimizer_attribute(ob, "CPX_PARAM_SCRIND", false)#NO solver print
set_optimizer_attribute(ob, "CPX_PARAM_PARALLELMODE", 0)#parallel mode switch
@objective(ob, Min, ob[:LE][i])
optimize!(ob);
min_value = max(objective_bound(ob) - epsilon, bounds.LE_min[i])
@objective(ob, Max, ob[:LE][i])
optimize!(ob);
max_value = min(objective_bound(ob) + epsilon, bounds.LE_max[i])
return [min_value, max_value]
end
res = pmap(local_LE, 1:Num_Eline)
red = ones(Num_Eline)
for i=1:Num_Eline
if (bounds.LE_max[i]- bounds.LE_min[i])>=1e-4
min_value = res[i][1]
max_value = res[i][2]
red[i] = (max_value-min_value)/(bounds.LE_max[i]- bounds.LE_min[i])
bounds.LE_min[i] = min_value
bounds.LE_max[i] = max_value
end
end
println("OBBT bounds.LE_min bounds.LE_max: ", mean(red))
println(bounds.LE_min, bounds.LE_max)
@eval @everywhere bounds = $bounds
@everywhere function local_CR(i)
ob = relax(bounds,RT,K);
@constraint(ob,sum(Linedata_candidate[j,6]*ob[:XL][j] for j in 1:Num_Cline)+(1/100)*sum(ob[:Pg][j] for j in 1:Num_gen)<=UB);
set_optimizer_attribute(ob, "CPX_PARAM_TILIM", 120)#Time limit
set_optimizer_attribute(ob, "CPX_PARAM_SCRIND", false)#NO solver print
set_optimizer_attribute(ob, "CPX_PARAM_PARALLELMODE", 0)#parallel mode switch
@objective(ob, Min, ob[:CR][i])
optimize!(ob);
min_value = max(objective_bound(ob) - epsilon, bounds.CR_min[i])
@objective(ob, Max, ob[:CR][i])
optimize!(ob);
max_value = min(objective_bound(ob) + epsilon, bounds.CR_max[i])
return [min_value, max_value]
end
res = pmap(local_CR, 1:Num_Eline)
red = ones(Num_Eline)
for i=1:Num_Eline
if (bounds.CR_max[i]- bounds.CR_min[i])>=1e-4
min_value = res[i][1]
max_value = res[i][2]
red[i] = (max_value-min_value)/(bounds.CR_max[i]- bounds.CR_min[i])
bounds.CR_min[i] = min_value
bounds.CR_max[i] = max_value
end
end
println("OBBT bounds.CR_min bounds.CR_max: ", mean(red))
println(bounds.CR_min, bounds.CR_max)
@eval @everywhere bounds = $bounds
@everywhere function local_SR(i)
ob = relax(bounds,RT,K);
@constraint(ob,sum(Linedata_candidate[j,6]*ob[:XL][j] for j in 1:Num_Cline)+(1/100)*sum(ob[:Pg][j] for j in 1:Num_gen)<=UB);
set_optimizer_attribute(ob, "CPX_PARAM_TILIM", 120)#Time limit
set_optimizer_attribute(ob, "CPX_PARAM_SCRIND", false)#NO solver print
set_optimizer_attribute(ob, "CPX_PARAM_PARALLELMODE", 0)#parallel mode switch
@objective(ob, Min, ob[:SR][i])
optimize!(ob);
min_value = max(objective_bound(ob) - epsilon, bounds.SR_min[i])
@objective(ob, Max, ob[:SR][i])
optimize!(ob);
max_value = min(objective_bound(ob) + epsilon, bounds.SR_max[i])
return [min_value, max_value]
end
res = pmap(local_SR, 1:Num_Eline)
red = ones(Num_Eline)
for i=1:Num_Eline
if (bounds.SR_max[i]- bounds.SR_min[i])>=1e-4
min_value = res[i][1]
max_value = res[i][2]
red[i] = (max_value-min_value)/(bounds.SR_max[i]- bounds.SR_min[i])
bounds.SR_min[i] = min_value
bounds.SR_max[i] = max_value
end
end
println("OBBT bounds.SR_min bounds.SR_max: ", mean(red))
println(bounds.SR_min, bounds.SR_max)
end
return bounds;
end