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