-
Notifications
You must be signed in to change notification settings - Fork 0
/
opf.mod
executable file
·209 lines (172 loc) · 7.4 KB
/
opf.mod
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
reset;
param baseMVA;
set bus_i;
param type {bus_i};
param Pd {bus_i};
param Qd {bus_i};
param Gs {bus_i};
param Bs {bus_i};
param area {bus_i};
param Vm {bus_i};
param Va {bus_i};
param baseKV{bus_i};
param zone {bus_i};
param Vmax {bus_i};
param Vmin {bus_i};
set gen_i within bus_i;
param Pg {gen_i};
param Qg {gen_i};
param Qmax {gen_i};
param Qmin {gen_i};
param Vg {gen_i};
param mBase {gen_i};
param gen_status{gen_i};
param Pmax {gen_i};
param Pmin {gen_i};
set branch dimen 2;
param r {branch};
param x {branch};
param b {branch};
param rateA {branch};
param rateB {branch};
param rateC {branch};
param ratio {branch};
param angle {branch};
param branch_status{branch};
param startup {gen_i};
param shutdown{gen_i};
param n {gen_i};
param c0 {gen_i};
param c1 {gen_i};
param c2 {gen_i};
###
# other parameter
###
param line_G{(l,m) in branch} := r[l,m]/(r[l,m]^2+x[l,m]^2);
param line_B{(l,m) in branch} := -x[l,m]/(r[l,m]^2+x[l,m]^2);
param pst_ratio{(l,m) in branch} := 1;
param pst_angle{(l,m) in branch} := 0;
param pst_cos{(l,m) in branch} := cos(pst_angle[l,m]);
param pst_sin{(l,m) in branch} := sin(pst_angle[l,m]);
param y11_re{(l,m) in branch}:= line_G[l,m]/(pst_ratio[l,m]^2);
param y11_im{(l,m) in branch}:= (line_B[l,m]+b[l,m]/2)/(pst_ratio[l,m]^2);
param y22_re{(l,m) in branch}:= line_G[l,m];
param y22_im{(l,m) in branch}:= line_B[l,m]+b[l,m]/2;
# -ys/(rho exp +jTheta)
param y12_re{(l,m) in branch}:= (-1/pst_ratio[l,m])*( line_G[l,m]*pst_cos[l,m]-line_B[l,m]*pst_sin[l,m]);
param y12_im{(l,m) in branch}:= (-1/pst_ratio[l,m])*( line_B[l,m]*pst_cos[l,m]+line_G[l,m]*pst_sin[l,m]);
# -ys/(rho exp -jTheta)
param y21_re{(l,m) in branch}:= (-1/pst_ratio[l,m])*( line_G[l,m]*pst_cos[l,m]+line_B[l,m]*pst_sin[l,m]);
param y21_im{(l,m) in branch}:= (-1/pst_ratio[l,m])*( line_B[l,m]*pst_cos[l,m]-line_G[l,m]*pst_sin[l,m]);
###
###
# OPF formulation
###
var v_re{bus_i};
var v_im{bus_i};
var p_gen{gen in gen_i}
>= Pmin[gen]*100, <= Pmax[gen]*100
;
var q_gen{gen in gen_i}
>= Qmin[gen]*100, <= Pmax[gen]*100
;
# linear equation I=YV
# power flow equation
# s_or = v_or i_or* = v_or(y_11* v_or* + y_12* v_ex*) = y_11* v_or v_or* + y_12* v_or v_ex*
# s_ex = v_ex i_ex* = v_ex(y_21* v_or* + y_22* v_ex*) = y_21* v_ex v_or* + y_22* v_ex v_ex*
# s_or = y_11*(v_or_re^2 +v_or_im^2) + y_12* v_or v_ex*)
# s_ex = y_21* v_ex v_or* + y_22* (v_ex_re^2 +v_ex_im^2)
var v_hProd_re{i in bus_i, j in bus_i} = v_re[i]*v_re[j]+v_im[i]*v_im[j];
var v_hProd_im{i in bus_i, j in bus_i} =
if(i == j) then(
0
)else(
v_re[j]*v_im[i]-v_re[i]*v_im[j]
);
# i_or = y_11 v_or + y_12 v_ex
# i_ex = y_21 v_or + y_22 v_ex
var i_or_re{(l,m) in branch} = +y11_re[l,m]*v_re[l]-y11_im[l,m]*v_im[l]+y12_re[l,m]*v_re[m]-y12_im[l,m]*v_im[m];
var i_or_im{(l,m) in branch} = +y11_re[l,m]*v_im[l]+y11_im[l,m]*v_re[l]+y12_re[l,m]*v_im[m]+y12_im[l,m]*v_re[m];
var i_ex_re{(l,m) in branch} = +y21_re[l,m]*v_re[l]-y21_im[l,m]*v_im[l]+y22_re[l,m]*v_re[m]-y22_im[l,m]*v_im[m];
var i_ex_im{(l,m) in branch} = +y21_re[l,m]*v_im[l]+y21_im[l,m]*v_re[l]+y22_re[l,m]*v_im[m]+y22_im[l,m]*v_re[m];
# s_or = y_11* v_or v_or* + y_12* v_or v_ex*
# s_ex = y_22* v_ex v_ex* + y_21* v_ex v_or*
var p_or{(l,m) in branch} = +y11_re[l,m]*v_hProd_re[l,l]+y12_re[l,m]*v_hProd_re[l,m]+y12_im[l,m]*v_hProd_im[l,m];
var p_ex{(l,m) in branch} = +y21_re[l,m]*v_hProd_re[m,l]+y21_im[l,m]*v_hProd_im[m,l]+y22_re[l,m]*v_hProd_re[m,m];
# sur bilan bus1
# +sum{(bus1, bus2) in branch}
# +y11_re[bus1, bus2]*v_re[bus1]*v_re[bus1]
# +y11_re[bus1, bus2]*v_im[bus1]*v_im[bus1]
# +y12_re[bus1, bus2]*v_re[bus1]*v_re[bus2]
# +y12_re[bus1, bus2]*v_im[bus1]*v_im[bus2]
# +y12_im[bus1, bus2]*v_im[bus1]*v_re[bus2]
# -y12_im[bus1, bus2]*v_re[bus1]*v_im[bus2]
# sur bilan bus2
# +sum{(bus1, bus2) in branch}
# +y22_re[bus1,bus2]*v_re[bus2]*v_re[bus2]
# +y22_re[bus1,bus2]*v_im[bus2]*v_im[bus2]
# +y21_re[bus1,bus2]*v_re[bus1]*v_re[bus2]
# +y21_re[bus1,bus2]*v_im[bus1]*v_im[bus2]
# +y21_im[bus1,bus2]*v_re[bus1]*v_im[bus2]
# -y21_im[bus1,bus2]*v_im[bus1]*v_re[bus2]
subject to p_balance{bus in bus_i}:
+Pd[bus]
#+sum{(bus, m) in branch} (+y11_re[bus,m]*(v_re[bus]*v_re[bus]+v_im[bus]*v_im[bus])+y12_re[bus,m]*(v_re[bus]*v_re[m]+v_im[bus]*v_im[m])+y12_im[bus,m]*(v_im[bus]*v_re[m]-v_re[bus]*v_im[m]))
#+sum{(l, bus) in branch} (+y21_re[l,bus]*(v_re[l]*v_re[bus]+v_im[l]*v_im[bus])+y21_im[l,bus]*(v_re[l]*v_im[bus]-v_im[l]*v_re[bus])+y22_re[l,bus]*(v_re[bus]*v_re[bus]+v_im[bus]*v_im[bus]))
# sur bilan bus1
+sum{(bus1, bus2) in branch:bus==bus1}100* (
+y11_re[bus1, bus2]*v_re[bus1]*v_re[bus1]
+y11_re[bus1, bus2]*v_im[bus1]*v_im[bus1]
+y12_re[bus1, bus2]*v_re[bus1]*v_re[bus2]
+y12_re[bus1, bus2]*v_im[bus1]*v_im[bus2]
+y12_im[bus1, bus2]*v_im[bus1]*v_re[bus2]
-y12_im[bus1, bus2]*v_re[bus1]*v_im[bus2]
)
# sur bilan bus2
+sum{(bus1, bus2) in branch:bus==bus2} 100*(
+y22_re[bus1,bus2]*v_re[bus2]*v_re[bus2]
+y22_re[bus1,bus2]*v_im[bus2]*v_im[bus2]
+y21_re[bus1,bus2]*v_re[bus1]*v_re[bus2]
+y21_re[bus1,bus2]*v_im[bus1]*v_im[bus2]
+y21_im[bus1,bus2]*v_re[bus1]*v_im[bus2]
-y21_im[bus1,bus2]*v_im[bus1]*v_re[bus2]
)
=
(if bus in gen_i then p_gen[bus])/100
;
var q_or{(l,m) in branch} = -y11_im[l,m]*v_hProd_re[l,l]+y12_re[l,m]*v_hProd_im[l,m]-y12_im[l,m]*v_hProd_re[l,m];
var q_ex{(l,m) in branch} = +y21_re[l,m]*v_hProd_im[m,l]-y21_im[l,m]*v_hProd_re[m,l]-y22_im[l,m]*v_hProd_re[m,m];
subject to q_balance{bus in bus_i}:
+Qd[bus]
#+sum{(bus, m) in branch} (-y11_im[bus,m]*(v_re[bus]*v_re[bus]+v_im[bus]*v_im[bus])+y12_re[bus,m]*(v_im[bus]*v_re[m]-v_re[bus]*v_im[m])-y12_im[bus,m]*(v_re[bus]*v_re[m]+v_im[bus]*v_im[m]))
#+sum{(l, bus) in branch} (+y21_re[l,bus]*(v_re[l]*v_im[bus]-v_im[l]*v_re[bus])-y21_im[l,bus]*(v_re[l]*v_re[bus]+v_im[l]*v_im[bus])-y22_im[l,bus]*(v_re[bus]*v_re[bus]+v_im[bus]*v_im[bus]))
+sum{(bus1, bus2) in branch:bus==bus1}100*(
-y11_im[bus1,bus2]*v_re[bus1]*v_re[bus1]
-y11_im[bus1,bus2]*v_im[bus1]*v_im[bus1]
+y12_re[bus1,bus2]*v_im[bus1]*v_re[bus2]
-y12_re[bus1,bus2]*v_re[bus1]*v_im[bus2]
-y12_im[bus1,bus2]*v_re[bus1]*v_re[bus2]
-y12_im[bus1,bus2]*v_im[bus1]*v_im[bus2]
)
+sum{(bus1, bus2) in branch:bus==bus2}100*(
-y22_im[bus1,bus2]*v_re[bus2]*v_re[bus2]
-y22_im[bus1,bus2]*v_im[bus2]*v_im[bus2]
+y21_re[bus1,bus2]*v_re[bus1]*v_im[bus2]
-y21_re[bus1,bus2]*v_im[bus1]*v_re[bus2]
-y21_im[bus1,bus2]*v_re[bus1]*v_re[bus2]
-y21_im[bus1,bus2]*v_im[bus1]*v_im[bus2]
)
=
(if bus in gen_i then q_gen[bus])/100
;
minimize act_cost: sum{gen in gen_i}(c0[gen]+c1[gen]*p_gen[gen]+c2[gen]*p_gen[gen]^2);
subject to ctr_v_min{bus in bus_i}: Vmin[bus]^2 <= v_re[bus]^2+v_im[bus]^2;
subject to ctr_v_max{bus in bus_i}: Vmax[bus]^2 >= v_re[bus]^2+v_im[bus]^2;
subject to ref_bus_re{bus in bus_i:type[bus]==3}:v_re[bus]>= 0;
subject to ref_bus_im{bus in bus_i:type[bus]==3}:v_im[bus] = 0;
# PQ
#subject to ref_bus_re{bus in bus_i:type[bus]==1}:v_re[bus]>=0;
#subject to ref_bus_im{bus in bus_i:type[bus]==1}:v_im[bus]= 0;
# PV
#subject to ref_bus_re{bus in bus_i:type[bus]==2}:v_re[bus]=Vm[bus]*cos(Va[bus]);
#subject to ref_bus_im{bus in bus_i:type[bus]==2}:v_im[bus]=Vm[bus]*sin(Va[bus]);