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