-
Notifications
You must be signed in to change notification settings - Fork 0
/
opf2.mod
164 lines (131 loc) · 4.91 KB
/
opf2.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
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};
var q_gen{gen in gen_i};
subject to lb_p_gen{gen in gen_i}: p_gen[gen] >= Pmin[gen]*100;
subject to ub_p_gen{gen in gen_i}: p_gen[gen] <= Pmax[gen]*100;
subject to lb_q_gen{gen in gen_i}: q_gen[gen] >= Qmin[gen]*100;
subject to ub_q_gen{gen in gen_i}: q_gen[gen] <= Qmax[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 i_or_re{(l,m) in branch};
var i_or_im{(l,m) in branch};
var i_ex_re{(l,m) in branch};
var i_ex_im{(l,m) in branch};
# i_or = y_11 v_or + y_12 v_ex
# i_ex = y_21 v_or + y_22 v_ex
subject to ctr_i_or_re{(l,m) in branch}: i_or_re[l,m] = 100*(+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]);
subject to ctr_i_ex_re{(l,m) in branch}: i_ex_re[l,m] = 100*(+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]);
subject to ctr_i_or_im{(l,m) in branch}: i_or_im[l,m] = 100*(+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]);
subject to ctr_i_ex_im{(l,m) in branch}: i_ex_im[l,m] = 100*(+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]);
var i_re{bus in bus_i};
var i_im{bus in bus_i};
# s_or = v_or i_or*
# s_ex = v_ex i_ex*
# v.i*=s
subject to ctr_i_re{bus in bus_i}:
+i_re[bus]*v_re[bus]
+i_im[bus]*v_im[bus]
=
+(+Pd[bus]-(if bus in gen_i then p_gen[bus])/100)
;
subject to ctr_i_im{bus in bus_i}:
+i_re[bus]*v_im[bus]
-i_im[bus]*v_re[bus]
=
+(+Qd[bus]-(if bus in gen_i then q_gen[bus])/100)
;
# (Sd*-S_gen*)/v_or* = (Sd*-S_gen*)/|v_or|² v_or
subject to i_balance_re{bus in bus_i}:
+i_re[bus]
+sum{(bus1, bus2) in branch:bus==bus1}i_or_re[bus1, bus2]
+sum{(bus1, bus2) in branch:bus==bus2}i_ex_re[bus1, bus2]
=
0
;
subject to i_balance_im{bus in bus_i}:
+i_im[bus]
+sum{(bus1, bus2) in branch:bus==bus1}i_or_im[bus1, bus2]
+sum{(bus1, bus2) in branch:bus==bus2}i_ex_im[bus1, bus2]
=
0
;
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]*v_re[bus]+v_im[bus]*v_im[bus];
subject to ctr_v_max{bus in bus_i}: Vmax[bus]^2 >= v_re[bus]*v_re[bus]+v_im[bus]*v_im[bus];
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]);