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