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