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