0001 function t_opf_softlims(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
0034 if nargin < 1
0035 quiet = 0;
0036 end
0037
0038 casefile = 'case9';
0039 if quiet
0040 verbose = 0;
0041 else
0042 verbose = 0;
0043 end
0044
0045 t_begin(55, quiet);
0046
0047
0048 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0049 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0050 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0051 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0052 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0053 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0054 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0055
0056
0057 mpopt = mpoption('model', 'DC', 'opf.dc.solver', 'MIPS');
0058 mpopt = mpoption(mpopt, 'opf.violation', 1e-6, 'mips.gradtol', 1e-8, ...
0059 'mips.comptol', 1e-8, 'mips.costtol', 1e-9);
0060 if verbose <= 1
0061 mpopt = mpoption(mpopt, 'out.all', 0);
0062 end
0063 mpopt = mpoption(mpopt, 'verbose', verbose);
0064
0065
0066 mpc = loadcase(casefile);
0067 nl = size(mpc.branch, 1);
0068 mpc.gencost(:, NCOST) = 2;
0069 mpc.gencost(:, COST) = [];
0070 mpc.gencost(:, COST) = [50; 40; 25];
0071 mpc.gencost(:, COST+1) = 0;
0072 mpc.branch(2:6, RATE_A) = [0; 120; 0; 120; 0];
0073 mpc.branch(3, RATE_A) = 120;
0074 mpc.branch(5, RATE_A) = 120;
0075 mpc.branch = [mpc.branch(1:4, :); mpc.branch(4, :); mpc.branch(5:end, :)];
0076 mpc.branch(5, BR_STATUS) = 0;
0077
0078 nl = size(mpc.branch, 1);
0079
0080
0081 mpc.softlims.idx = (2:nl)';
0082 mpc.softlims.cost = 100 * ones(nl-1, 1);
0083
0084 t = 'hard limits : ';
0085 t_ok(~toggle_softlims(mpc, 'status'), 'toggle_softlims(mpc, ''status'') == 0');
0086 r = runopf(mpc, mpopt);
0087 t_ok(r.success, [t 'success']);
0088 t_ok(~isfield(r.softlims, 'overload'), [t 'no softlims.overload']);
0089 t_ok(~isfield(r.softlims, 'overload'), [t 'no softlims.ovl_cost']);
0090 t_is(r.f, 9126.87, 4, [t 'f']);
0091 t_is(r.gen(:, PG), [12.687; 62.3130; 240], 4, [t 'Pg']);
0092 t_is(r.branch(:, PF), [12.687; -30; -120; 240; 0; 120; 20; -62.3130; 82.3130; -42.687], 4, [t 'Pf']);
0093 t_is(r.branch(:, MU_SF)+r.branch(:, MU_ST), [0; 0; 35.6504; 0; 0; 7.9756; 0; 0; 0; 0], 4, [t 'mu Pf']);
0094
0095 t = 'soft limits (satisfied) : ';
0096 mpc = toggle_softlims(mpc, 'on');
0097 t_ok(toggle_softlims(mpc, 'status'), 'toggle_softlims(mpc, ''status'') == 1');
0098 r = runopf(mpc, mpopt);
0099 t_ok(r.success, [t 'success']);
0100 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.overload exists']);
0101 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.ovl_cost exists']);
0102 t_is(r.f, 9126.87, 4, [t 'f']);
0103 t_is(r.gen(:, PG), [12.687; 62.3130; 240], 4, [t 'Pg']);
0104 t_is(r.branch(:, PF), [12.687; -30; -120; 240; 0; 120; 20; -62.3130; 82.3130; -42.687], 4, [t 'Pf']);
0105 t_is(r.branch(:, MU_SF)+r.branch(:, MU_ST), [0; 0; 35.6504; 0; 0; 7.9756; 0; 0; 0; 0], 4, [t 'mu Pf']);
0106 t_is(r.softlims.overload, zeros(10, 1), 12, [t 'softlims.overload']);
0107 t_is(r.softlims.ovl_cost, zeros(10, 1), 12, [t 'softlims.ovl_cost']);
0108 t_is(r.order.branch.status.on(r.order.int.softlims.idx), [3; 6; 8; 9; 10], 12, [t 'mu Pf']);
0109
0110 t = 'savecase(fname, mpc) : ';
0111 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0112 savecase(fn, mpc);
0113 mpc1 = loadcase(fn);
0114 delete([fn '.m']);
0115 t_ok(isfield(mpc1, 'softlims'), [t 'mpc.softlims']);
0116 t_ok(isfield(mpc1.softlims, 'idx'), [t 'mpc.softlims.idx']);
0117 t_is(mpc1.softlims.idx, mpc.softlims.idx, 5, [t 'mpc.softlims.idx']);
0118 t_ok(isfield(mpc1.softlims, 'cost'), [t 'mpc.softlims.cost']);
0119 t_is(mpc1.softlims.cost, mpc.softlims.cost, 5, [t 'mpc.softlims.cost']);
0120
0121 t = 'savecase(fname, results) : ';
0122 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0123 savecase(fn, r);
0124 mpc1 = loadcase(fn);
0125 delete([fn '.m']);
0126 t_ok(isfield(mpc1, 'softlims'), [t 'results.softlims']);
0127 t_ok(isfield(mpc1.softlims, 'idx'), [t 'results.softlims.idx']);
0128 t_is(mpc1.softlims.idx, r.softlims.idx, 5, [t 'results.softlims.idx']);
0129 t_ok(isfield(mpc1.softlims, 'cost'), [t 'results.softlims.cost']);
0130 t_is(mpc1.softlims.cost, r.softlims.cost, 5, [t 'results.softlims.cost']);
0131 t_ok(isfield(mpc1.softlims, 'overload'), [t 'results.softlims.overload']);
0132 t_is(mpc1.softlims.overload, r.softlims.overload, 5, [t 'results.softlims.overload']);
0133 t_ok(isfield(mpc1.softlims, 'ovl_cost'), [t 'results.softlims.ovl_cost']);
0134 t_is(mpc1.softlims.ovl_cost, r.softlims.ovl_cost, 4, [t 'results.softlims.ovl_cost']);
0135
0136 t = 'soft limits (violated) : ';
0137 mpc = rmfield(mpc, 'softlims');
0138 mpc.softlims.cost = 20;
0139 r = runopf(mpc, mpopt);
0140 t_ok(r.success, [t 'success']);
0141 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.overload exists']);
0142 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.ovl_cost exists']);
0143 t_is(r.f, 9106.5059, 4, [t 'f']);
0144 t_is(r.gen(:, PG), [10; 63.6988; 241.3012], 4, [t 'Pg']);
0145 t_is(r.branch(:, PF), [10; -31.3012; -121.3012; 241.3012; 0; 120; 20; -63.6988; 83.6988; -41.3012], 4, [t 'Pf']);
0146 t_is(r.branch(:, MU_SF)+r.branch(:, MU_ST), [0; 0; 20; 0; 0; 13.2992; 0; 0; 0; 0], 4, [t 'mu Pf']);
0147 t_is(r.softlims.overload, [0; 0; 1.3011811; 0; 0; 0; 0; 0; 0; 0], 6, [t 'softlims.overload']);
0148 t_is(r.softlims.ovl_cost, [0; 0; 26.023622; 0; 0; 0; 0; 0; 0; 0], 6, [t 'softlims.ovl_cost']);
0149
0150 t = 'savecase(fname, mpc) : ';
0151 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0152 savecase(fn, mpc);
0153 mpc1 = loadcase(fn);
0154 delete([fn '.m']);
0155 t_ok(isfield(mpc1, 'softlims'), [t 'mpc.softlims']);
0156 t_ok(~isfield(mpc1.softlims, 'idx'), [t 'mpc.softlims.idx']);
0157 t_ok(isfield(mpc1.softlims, 'cost'), [t 'mpc.softlims.cost']);
0158 t_is(mpc1.softlims.cost, mpc.softlims.cost, 5, [t 'mpc.softlims.cost']);
0159
0160 t = 'savecase(fname, results) : ';
0161 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0162 savecase(fn, r);
0163 mpc1 = loadcase(fn);
0164 delete([fn '.m']);
0165 t_ok(isfield(mpc1, 'softlims'), [t 'results.softlims']);
0166 t_ok(isfield(mpc1.softlims, 'idx'), [t 'results.softlims.idx']);
0167 t_ok(isempty(mpc1.softlims.idx), [t 'results.softlims.idx']);
0168 t_ok(isfield(mpc1.softlims, 'cost'), [t 'results.softlims.cost']);
0169 t_is(mpc1.softlims.cost, r.softlims.cost, 5, [t 'results.softlims.cost']);
0170 t_ok(isfield(mpc1.softlims, 'overload'), [t 'results.softlims.overload']);
0171 t_is(mpc1.softlims.overload, r.softlims.overload, 5, [t 'results.softlims.overload']);
0172 t_ok(isfield(mpc1.softlims, 'ovl_cost'), [t 'results.softlims.ovl_cost']);
0173 t_is(mpc1.softlims.ovl_cost, r.softlims.ovl_cost, 4, [t 'results.softlims.ovl_cost']);
0174
0175 t_end;