0001 function t_opf_fmincon(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin < 1
0013 quiet = 0;
0014 end
0015
0016
0017 options = {
0018 {0, 0},
0019 {0, 1},
0020 {1, 0},
0021 {1, 1},
0022 };
0023
0024 num_tests = 216;
0025
0026 t_begin(length(options)*num_tests, quiet);
0027
0028 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0029 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0030 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0031 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0032 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0033 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0034 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0035 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0036 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0037
0038 casefile = 't_case9_opf';
0039 if quiet
0040 verbose = 0;
0041 else
0042 verbose = 0;
0043 end
0044
0045 mpopt = mpoption('opf.violation', 1e-6);
0046 mpopt = mpoption(mpopt, 'out.all', 0, 'verbose', verbose, 'opf.ac.solver', 'FMINCON');
0047 mpopt = mpoption(mpopt, 'fmincon.tol_x', 1e-7, 'fmincon.tol_f', 1e-9);
0048
0049
0050 vstr = have_fcn('matlab', 'vstr');
0051 if strcmp(vstr, '7.6') || strcmp(vstr, '7.7') || ...
0052 strcmp(vstr, '7.8') || strcmp(vstr, '7.9')
0053 mpopt = mpoption(mpopt, 'fmincon.alg', 1);
0054 end
0055
0056 for k = 1:length(options)
0057 if options{k}{1}, bal = 'I'; else, bal = 'S'; end
0058 if options{k}{2}, crd = 'c'; else, crd = 'p'; end
0059 t0 = sprintf('fmincon OPF (%s,%s) : ', bal, crd);
0060
0061 if ~have_fcn('fmincon')
0062 t_skip(num_tests, 'fmincon not available');
0063 continue;
0064 end
0065
0066 mpopt = mpoption(mpopt, 'opf.current_balance', options{k}{1}, ...
0067 'opf.v_cartesian', options{k}{2} );
0068
0069
0070 ib_data = [1:BUS_AREA BASE_KV:VMIN];
0071 ib_voltage = [VM VA];
0072 ib_lam = [LAM_P LAM_Q];
0073 ib_mu = [MU_VMAX MU_VMIN];
0074 ig_data = [GEN_BUS QMAX QMIN MBASE:APF];
0075 ig_disp = [PG QG VG];
0076 ig_mu = (MU_PMAX:MU_QMIN);
0077 ibr_data = (1:ANGMAX);
0078 ibr_flow = (PF:QT);
0079 ibr_mu = [MU_SF MU_ST];
0080 ibr_angmu = [MU_ANGMIN MU_ANGMAX];
0081
0082
0083 load soln9_opf;
0084
0085
0086 for s = 0:3
0087 mpopt = mpoption(mpopt, 'opf.start', s);
0088 t = sprintf('%s(start=%d): ', t0, s);
0089 [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);
0090 t_ok(success, [t 'success']);
0091 t_is(f, f_soln, 3, [t 'f']);
0092 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0093 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0094 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0095 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0096 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0097 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0098 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0099 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0100 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0101 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0102 end
0103 mpopt = mpoption(mpopt, 'opf.start', 0);
0104
0105
0106 t = [t0 '(single-block PWL) : '];
0107 mpc = loadcase(casefile);
0108 mpc.gencost(2, NCOST) = 2;
0109 [r, success] = runopf(mpc, mpopt);
0110 [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0111 t_ok(success, [t 'success']);
0112 t_is(f, f_soln, 3, [t 'f']);
0113 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0114 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0115 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0116 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0117 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0118 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0119 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0120 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0121 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0122 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0123 if mpopt.opf.v_cartesian
0124 xr = [r.var.val.Vr;r.var.val.Vi;r.var.val.Pg;r.var.val.Qg;0;r.var.val.y];
0125 else
0126 xr = [r.var.val.Va;r.var.val.Vm;r.var.val.Pg;r.var.val.Qg;0;r.var.val.y];
0127 end
0128 t_is(r.x, xr, 8, [t 'raw x returned from OPF']);
0129
0130
0131 load soln9_opf_Plim;
0132
0133
0134 t = [t0 '(P line lim) : '];
0135 mpopt1 = mpoption(mpopt, 'opf.flow_lim', 'P');
0136 [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt1);
0137 t_ok(success, [t 'success']);
0138 t_is(f, f_soln, 3, [t 'f']);
0139 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0140 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0141 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0142 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0143 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0144 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0145 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0146 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0147 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0148 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0149
0150 t = [t0 '(P^2 line lim) : '];
0151 mpopt1 = mpoption(mpopt, 'opf.flow_lim', '2');
0152 [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt1);
0153 t_ok(success, [t 'success']);
0154 t_is(f, f_soln, 3, [t 'f']);
0155 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0156 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0157 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0158 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0159 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0160 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0161 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0162 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0163 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0164 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0165
0166
0167 mpc = loadcase(casefile);
0168 mpc.gencost = [
0169 2 1500 0 3 0.11 5 0;
0170 2 2000 0 3 0.085 1.2 0;
0171 2 3000 0 3 0.1225 1 0;
0172 ];
0173 [baseMVA, bus_soln, gen_soln, gencost, branch_soln, f_soln, success, et] = runopf(mpc, mpopt);
0174 branch_soln = branch_soln(:,1:MU_ST);
0175
0176 A = sparse(0,0);
0177 l = [];
0178 u = [];
0179 nb = size(mpc.bus, 1);
0180 ng = size(mpc.gen, 1);
0181 thbas = 1; thend = thbas+nb-1;
0182 vbas = thend+1; vend = vbas+nb-1;
0183 pgbas = vend+1; pgend = pgbas+ng-1;
0184 qgbas = pgend+1; qgend = qgbas+ng-1;
0185 nxyz = 2*nb + 2*ng;
0186 N = sparse((1:ng)', (pgbas:pgend)', mpc.baseMVA * ones(ng,1), ng, nxyz);
0187 fparm = [ 1 0 0 1;
0188 1 -100 100 1;
0189 1 -10 10 1 ];
0190 H = 2 * spdiags(mpc.gencost(:, 5), 0, ng, ng);
0191 Cw = mpc.gencost(:, 6);
0192 mpc.gencost(:, 5:7) = 0;
0193
0194
0195 t = [t0 'w/quadratic generalized gen cost : '];
0196 [r, success] = opf(mpc, A, l, u, mpopt, N, fparm, H, Cw);
0197 [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0198 t_ok(success, [t 'success']);
0199 t_is(f, f_soln, 3, [t 'f']);
0200 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0201 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0202 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0203 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0204 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0205 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0206 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0207 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0208 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0209 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0210 t_is(r.cost.usr, f, 12, [t 'user cost']);
0211
0212
0213 if mpopt.opf.v_cartesian
0214 t_skip(17, 'legacy cost example n/a to cartesian V case')
0215 else
0216 load soln9_opf;
0217 mpc = loadcase(casefile);
0218 mpc.N = sparse((1:nb)', (vbas:vend)', ones(nb,1), nb, nxyz);
0219 mpc.fparm = ones(nb,1) * [ 2 1.08 0.02 1e8 ];
0220 mpc.Cw = ones(nb, 1);
0221 t = [t0 'w/legacy cost, in deadzone : '];
0222 r = runopf(mpc, mpopt);
0223 [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0224 t_ok(r.success, [t 'success']);
0225 t_is(f, f_soln, 3, [t 'f']);
0226 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0227 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0228 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0229 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0230 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0231 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0232 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0233 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0234 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0235 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0236 t_is(r.cost.usr, 0, 12, [t 'user cost']);
0237
0238 t = [t0 'w/legacy cost, not in deadzone : '];
0239 mpc.fparm = ones(nb,1) * [ 2 1.08 0.01 1e8 ];
0240 r = runopf(mpc, mpopt);
0241 [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0242 t_ok(r.success, [t 'success']);
0243 t_is(f, 9009.0890, 3, [t 'f']);
0244 t_is([min(bus(:, VM)) mean(bus(:, VM)) max(bus(:, VM))], ...
0245 [1.066624, 1.083980, 1.091698], 5, [t 'bus voltage']);
0246 t_is(r.cost.usr, 1673.065465, 4, [t 'user cost']);
0247 end
0248
0249
0250
0251
0252
0253 if mpopt.opf.v_cartesian
0254 t_skip(14, 'lin constraint/cost example n/a to cartesian V case')
0255 else
0256 load soln9_opf_extras1;
0257 A = sparse([1;1;2;2],[10;25;10;25],[-1;1;1;1],2,25);
0258 u = [Inf; Inf];
0259 l = [-1; 1];
0260
0261 N = sparse(1, 25, 1, 1, 25);
0262 fparm = [1 0 0 1];
0263 H = sparse(1,1);
0264 Cw = 100;
0265
0266 t = [t0 'w/extra constraints & costs 1 : '];
0267 [r, success] = opf(casefile, A, l, u, mpopt, N, fparm, H, Cw);
0268 [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0269 t_ok(success, [t 'success']);
0270 t_is(f, f_soln, 3, [t 'f']);
0271 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0272 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0273 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 2, [t 'bus lambda']);
0274 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0275 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0276 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0277 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0278 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0279 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0280 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0281 t_is(r.var.val.z, 0.025419, 6, [t 'user variable']);
0282 t_is(r.cost.usr, 2.5419, 4, [t 'user cost']);
0283 end
0284
0285
0286 mpc = loadcase('t_case9_opfv2');
0287
0288 mpc.branch(1, ANGMAX) = 360;
0289 mpc.branch(9, ANGMIN) = -360;
0290
0291
0292 load soln9_opf_PQcap;
0293
0294
0295 t = [t0 'w/capability curves : '];
0296 [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0297 t_ok(success, [t 'success']);
0298 t_is(f, f_soln, 3, [t 'f']);
0299 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0300 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0301 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0302 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0303 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0304 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0305 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0306 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0307 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0308 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0309
0310
0311 mpc = loadcase('t_case9_opfv2');
0312
0313 mpc.gen(2:3, [PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX]) = zeros(2,6);
0314
0315
0316 load soln9_opf_ang;
0317
0318
0319 t = [t0 'w/angle difference limits : '];
0320 [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0321 t_ok(success, [t 'success']);
0322 t_is(f, f_soln, 3, [t 'f']);
0323 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0324 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0325 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0326 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 1, [t 'bus mu']);
0327 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0328 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0329 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0330 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0331 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0332 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0333 t_is(branch(:,ibr_angmu ), branch_soln(:,ibr_angmu ), 2, [t 'branch angle mu']);
0334
0335
0336
0337 load soln9_opf;
0338
0339
0340 t = [t0 'w/ignored angle difference limits : '];
0341 mpopt1 = mpoption(mpopt, 'opf.ignore_angle_lim', 1);
0342 [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt1);
0343
0344 branch(1, ANGMAX) = 360;
0345 branch(9, ANGMIN) = -360;
0346 t_ok(success, [t 'success']);
0347 t_is(f, f_soln, 3, [t 'f']);
0348 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0349 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0350 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0351 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0352 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0353 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0354 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0355 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0356 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0357 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0358
0359
0360
0361 t = [t0 'w/angle difference limit = 0 : '];
0362 mpc = loadcase(casefile);
0363 b = 5;
0364 mpc.branch(b, ANGMAX) = 0;
0365 r = runopf(mpc, mpopt);
0366 t_ok(success, [t 'success']);
0367 diff = r.bus(r.branch(b, F_BUS), VA) - r.bus(r.branch(b, T_BUS), VA);
0368 t_is(diff, 0, 5, [t 'angle diff']);
0369
0370
0371 t = [t0 'ref bus ~= 1, ref ang ~= 0 : '];
0372 mpc = loadcase(casefile);
0373 mpc.bus([1;3], BUS_TYPE) = [PV; REF];
0374 bus_soln([1;3], BUS_TYPE) = bus_soln([3;1], BUS_TYPE);
0375 mpc.bus(3, VA) = 3.3014277;
0376 r = runopf(mpc, mpopt);
0377 [success, f, bus, gen, branch] = deal(r.success, r.f, r.bus, r.gen, r.branch);
0378 t_ok(success, [t 'success']);
0379 t_is(f, f_soln, 3, [t 'f']);
0380 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0381 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0382 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0383 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0384 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0385 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0386 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0387 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0388 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0389 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0390
0391
0392
0393 load soln9_opf_vg;
0394
0395
0396
0397 t = [t0 'w/opf.use_vg = 1 : '];
0398 mpc = loadcase(casefile);
0399 mpc.gen = mpc.gen([1 2 1 3], :);
0400 mpc.gencost = mpc.gencost([1 2 1 3], :);
0401 mpc.gen([1 3], [PMAX PMIN]) = mpc.gen([1 3], [PMAX PMIN]) / 2;
0402 mpc.gen(3, [QMIN, QMAX]) = 0;
0403 mpc.gencost([1 3], COST:end) = mpc.gencost([1 3], COST:end) / 2;
0404 mpc.gen(1, VG) = 1.05;
0405 mpc.gen(3, VG) = 1.06;
0406 mpopt1 = mpoption(mpopt, 'opf.use_vg', 1);
0407 r = runopf(mpc, mpopt1);
0408 t_ok(r.success, [t 'success']);
0409 t_is(r.f, f_soln, 3, [t 'f']);
0410 t_is( r.bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0411 t_is( r.bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0412 t_is( r.bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0413 t_is( r.bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0414 t_is( r.gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0415 t_is( r.gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0416 t_is( r.gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0417 t_is(r.branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0418 t_is(r.branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0419 t_is(r.branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0420
0421
0422 t = [t0 'w/opf.use_vg = 0.9 : '];
0423 mpopt1 = mpoption(mpopt, 'opf.use_vg', 0.9);
0424 r = runopf(mpc, mpopt1);
0425 t_ok(r.success, [t 'success']);
0426 t_is(r.f, f_soln1, 3, [t 'f']);
0427 t_is( r.bus(:,ib_data ), bus_soln1(:,ib_data ), 10, [t 'bus data']);
0428 t_is( r.bus(:,ib_voltage), bus_soln1(:,ib_voltage), 3, [t 'bus voltage']);
0429 t_is( r.bus(:,ib_lam ), bus_soln1(:,ib_lam ), 3, [t 'bus lambda']);
0430 t_is( r.bus(:,ib_mu ), bus_soln1(:,ib_mu ), 2, [t 'bus mu']);
0431 t_is( r.gen(:,ig_data ), gen_soln1(:,ig_data ), 10, [t 'gen data']);
0432 t_is( r.gen(:,ig_disp ), gen_soln1(:,ig_disp ), 3, [t 'gen dispatch']);
0433 t_is( r.gen(:,ig_mu ), gen_soln1(:,ig_mu ), 3, [t 'gen mu']);
0434 t_is(r.branch(:,ibr_data ), branch_soln1(:,ibr_data ), 10, [t 'branch data']);
0435 t_is(r.branch(:,ibr_flow ), branch_soln1(:,ibr_flow ), 3, [t 'branch flow']);
0436 t_is(r.branch(:,ibr_mu ), branch_soln1(:,ibr_mu ), 2, [t 'branch mu']);
0437
0438 t = [t0 'hi-deg polynomial costs : '];
0439 mpc = loadcase(casefile);
0440 mpc.gencost = [
0441 2 1500 0 6 1e-6/5 0 0 0 0 0;
0442 2 3000 0 5 1e-4/4 0 0 0 0 0;
0443 2 2000 0 3 1/2 0 0 0 0 0;
0444 ];
0445 r = runopf(mpc, mpopt);
0446 [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0447 t_ok(r.success, [t 'success']);
0448 t_is(f, 11899.4652, 4, [t 'f']);
0449 t_is(gen(:, PG), [100.703628; 88.719864; 128.679485], 5, [t 'Pg']);
0450 t_is([min(bus(:, VM)) mean(bus(:, VM)) max(bus(:, VM))], ...
0451 [1.059191 1.079404 1.1], 5, [t 'bus voltage']);
0452
0453
0454 t = [t0 'w/nonlin eq constraint : '];
0455 mpc = loadcase('case30');
0456 mpc.user_constraints.nle = {
0457 {'Pg_usr', 1, 'opf_nle_fcn1', 'opf_nle_hess1', {'Pg'}, {}}
0458 };
0459 r = runopf(mpc, mpopt);
0460 t_ok(r.success, [t 'success']);
0461 t_is(r.gen(1, PG) * r.gen(2, PG) / 100, r.gen(6, PG), 8, t);
0462 t_is(r.gen(6, PG), 20.751163, 5, t);
0463
0464
0465 t = [t0 'all buses isolated : '];
0466 mpc.bus(:, BUS_TYPE) = NONE;
0467 try
0468 r = runopf(mpc, mpopt);
0469 t_is(r.success, 0, 12, [t 'success = 0']);
0470 catch
0471 t_ok(0, [t 'unexpected fatal error']);
0472 end
0473
0474
0475 t = [t0 'w/no branch limits : '];
0476 mpc = loadcase(casefile);
0477 mpc.branch(:, RATE_A) = 0;
0478 r = runopf(mpc, mpopt);
0479 t_ok(r.success, [t 'success']);
0480 t_is(r.f, 5496.128635, 4, [t 'f']);
0481 t_is(r.gen(:, PG), [90; 220.463932; 10], 5, [t 'Pg']);
0482 t_is([min(r.bus(:, VM)) mean(r.bus(:, VM)) max(r.bus(:, VM))], ...
0483 [1.070692 1.090449 1.1], 5, [t 'bus voltage']);
0484 end
0485
0486 t_end;