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