0001 function t_opf_constr(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 if nargin < 1
0037 quiet = 0;
0038 end
0039
0040 num_tests = 101;
0041
0042 t_begin(num_tests, quiet);
0043
0044 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0045 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0046 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0047 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0048 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0049 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0050 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0051 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0052 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0053
0054 casefile = 't_case9_opf';
0055 if quiet
0056 verbose = 0;
0057 else
0058 verbose = 0;
0059 end
0060
0061 t0 = 'constr OPF : ';
0062 mpopt = mpoption('OUT_ALL', 0, 'VERBOSE', verbose, 'OPF_ALG', 300);
0063 mpopt = mpoption(mpopt, 'OPF_VIOLATION', 1e-6, 'CONSTR_TOL_X', 1e-5, 'CONSTR_TOL_F', 1e-5, 'CONSTR_MAX_IT', 300);
0064
0065
0066 if have_fcn('constr')
0067 s = warning('query', 'all');
0068 warning('off', 'all');
0069
0070
0071 ib_data = [1:BUS_AREA BASE_KV:VMIN];
0072 ib_voltage = [VM VA];
0073 ib_lam = [LAM_P LAM_Q];
0074 ib_mu = [MU_VMAX MU_VMIN];
0075 ig_data = [GEN_BUS QMAX QMIN MBASE:APF];
0076 ig_disp = [PG QG VG];
0077 ig_mu = (MU_PMAX:MU_QMIN);
0078 ibr_data = (1:ANGMAX);
0079 ibr_flow = (PF:QT);
0080 ibr_mu = [MU_SF MU_ST];
0081 ibr_angmu = [MU_ANGMIN MU_ANGMAX];
0082
0083
0084 load soln9_opf;
0085
0086
0087 t = t0;
0088 [bus, gen, branch, f, success] = opf(casefile, mpopt);
0089 t_ok(success, [t 'success']);
0090 t_is(f, f_soln, 3, [t 'f']);
0091 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0092 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0093 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0094 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0095 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0096 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0097 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0098 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0099 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0100 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0101
0102
0103 t = [t0 '(single-block PWL) : '];
0104 mpc = loadcase(casefile);
0105 mpc.gencost(3, NCOST) = 2;
0106 r = runopf(mpc, mpopt);
0107 t_ok(success, [t 'success']);
0108 t_is(f, f_soln, 3, [t 'f']);
0109 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0110 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0111 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0112 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0113 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0114 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0115 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0116 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0117 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0118 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0119 xr = [r.var.val.Va;r.var.val.Vm;r.var.val.Pg;r.var.val.Qg;0;r.var.val.y];
0120 t_is(r.x, xr, 8, [t 'check on raw x returned from OPF']);
0121
0122
0123 load soln9_opf_Plim;
0124
0125
0126 t = [t0 '(P line lim) : '];
0127 mpopt1 = mpoption(mpopt, 'OPF_FLOW_LIM', 1);
0128 [bus, gen, branch, f, success] = opf(casefile, mpopt1);
0129 t_ok(success, [t 'success']);
0130 t_is(f, f_soln, 3, [t 'f']);
0131 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0132 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0133 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0134 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0135 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0136 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0137 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0138 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0139 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0140 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0141
0142
0143 mpc = loadcase(casefile);
0144 mpc.gencost = [
0145 2 1500 0 3 0.11 5 0;
0146 2 2000 0 3 0.085 1.2 0;
0147 2 3000 0 3 0.1225 1 0;
0148 ];
0149 [bus_soln, gen_soln, branch_soln, f_soln, success] = opf(mpc, mpopt);
0150 branch_soln = branch_soln(:,1:MU_ST);
0151
0152 A = sparse(0,0);
0153 l = [];
0154 u = [];
0155 nb = size(mpc.bus, 1);
0156 ng = size(mpc.gen, 1);
0157 thbas = 1; thend = thbas+nb-1;
0158 vbas = thend+1; vend = vbas+nb-1;
0159 pgbas = vend+1; pgend = pgbas+ng-1;
0160 qgbas = pgend+1; qgend = qgbas+ng-1;
0161 nxyz = 2*nb + 2*ng;
0162 N = sparse((1:ng)', (pgbas:pgend)', mpc.baseMVA * ones(ng,1), ng, nxyz);
0163 fparm = ones(ng,1) * [ 1 0 0 1 ];
0164 [junk, ix] = sort(mpc.gen(:, 1));
0165 H = 2 * spdiags(mpc.gencost(ix, 5), 0, ng, ng);
0166 Cw = mpc.gencost(ix, 6);
0167 mpc.gencost(:, 5:7) = 0;
0168
0169
0170 t = [t0 'w/quadratic generalized gen cost : '];
0171 [r, success] = opf(mpc, A, l, u, mpopt, N, fparm, H, Cw);
0172 [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0173 t_ok(success, [t 'success']);
0174 t_is(f, f_soln, 3, [t 'f']);
0175 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0176 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0177 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0178 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0179 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0180 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0181 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0182 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0183 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0184 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0185 t_is(r.cost.usr, f, 12, [t 'user cost']);
0186
0187
0188
0189
0190
0191 load soln9_opf_extras1;
0192 A = sparse([1;1;2;2],[10;25;10;25],[-1;1;1;1],2,25);
0193 u = [Inf; Inf];
0194 l = [-1; 1];
0195
0196 N = sparse(1, 25, 1, 1, 25);
0197 fparm = [1 0 0 1];
0198 H = sparse(1,1);
0199 Cw = 100;
0200
0201 t = [t0 'w/extra constraints & costs 1 : '];
0202 [r, success] = opf(casefile, A, l, u, mpopt, N, fparm, H, Cw);
0203 [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0204 t_ok(success, [t 'success']);
0205 t_is(f, f_soln, 3, [t 'f']);
0206 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0207 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0208 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 2, [t 'bus lambda']);
0209 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0210 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0211 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0212 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0213 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0214 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0215 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0216 t_is(r.var.val.z, 0.0254185, 6, [t 'user variable']);
0217 t_is(r.cost.usr, 2.54185, 4, [t 'user cost']);
0218
0219
0220 mpc = loadcase('t_case9_opfv2');
0221
0222 mpc.branch(1, ANGMAX) = 360;
0223 mpc.branch(9, ANGMIN) = -360;
0224
0225
0226 load soln9_opf_PQcap;
0227
0228
0229 t = [t0 'w/capability curves : '];
0230 [bus, gen, branch, f, success] = opf(mpc, mpopt);
0231 t_ok(success, [t 'success']);
0232 t_is(f, f_soln, 3, [t 'f']);
0233 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0234 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0235 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0236 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0237 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0238 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0239 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0240 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0241 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0242 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0243
0244
0245 mpc = loadcase('t_case9_opfv2');
0246
0247 mpc.gen(2:3, [PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX]) = zeros(2,6);
0248
0249
0250 load soln9_opf_ang;
0251
0252
0253 t = [t0 'w/angle difference limits : '];
0254
0255 mpc.bus(:, [VM VA]) = bus_soln(:, [VM VA]);
0256 mpc.gen(:, [PG QG VG]) = gen_soln(:, [PG QG VG]);
0257 [bus, gen, branch, f, success] = opf(mpc, mpopt);
0258 t_ok(success, [t 'success']);
0259 t_is(f, f_soln, 3, [t 'f']);
0260 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0261 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0262 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 0, [t 'bus lambda']);
0263 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), -2, [t 'bus mu']);
0264 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0265 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0266 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 0, [t 'gen mu']);
0267 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0268 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0269 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 0, [t 'branch mu']);
0270 t_is(branch(:,ibr_angmu ), branch_soln(:,ibr_angmu ), -1, [t 'branch angle mu']);
0271
0272
0273
0274 load soln9_opf;
0275
0276
0277 t = [t0 'w/ignored angle difference limits : '];
0278 mpopt1 = mpoption(mpopt, 'OPF_IGNORE_ANG_LIM', 1);
0279 [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt1);
0280
0281 branch(1, ANGMAX) = 360;
0282 branch(9, ANGMIN) = -360;
0283 t_ok(success, [t 'success']);
0284 t_is(f, f_soln, 3, [t 'f']);
0285 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0286 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0287 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0288 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0289 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0290 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0291 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0292 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0293 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0294 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0295
0296 warning(s);
0297 else
0298 t_skip(num_tests, 'constr not available');
0299 end
0300
0301 t_end;