0001 function t_most_fixed_res(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin < 1
0013 quiet = 0;
0014 end
0015
0016 t_begin(44, quiet);
0017
0018 if quiet
0019 verbose = 0;
0020 else
0021 verbose = 0;
0022 end
0023
0024 casefile = 't_case30_userfcns';
0025 mpopt = mpoption('opf.violation', 1e-6, 'mips.gradtol', 1e-8, ...
0026 'mips.comptol', 1e-8, 'mips.costtol', 1e-9);
0027 mpopt = mpoption(mpopt, 'out.all', 0, 'verbose', verbose, 'opf.ac.solver', 'MIPS');
0028 mpopt = mpoption(mpopt, 'model', 'DC');
0029 mpopt = mpoption(mpopt, 'most.solver', 'DEFAULT');
0030 if have_feature('gurobi')
0031 mpopt = mpoption(mpopt, 'gurobi.method', 1);
0032 end
0033 if have_feature('cplex')
0034 mpopt = mpoption(mpopt, 'cplex.qpmethod', 2);
0035 end
0036
0037
0038
0039
0040 if have_feature('linprog')
0041 if have_feature('linprog_ds')
0042 mpopt = mpoption(mpopt, 'linprog.Algorithm', 'dual-simplex');
0043 else
0044 mpopt = mpoption(mpopt, 'linprog.Algorithm', 'simplex');
0045 end
0046 end
0047
0048
0049
0050 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0051 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0052 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0053 [CT_LABEL, CT_PROB, CT_TABLE, CT_TBUS, CT_TGEN, CT_TBRCH, CT_TAREABUS, ...
0054 CT_TAREAGEN, CT_TAREABRCH, CT_ROW, CT_COL, CT_CHGTYPE, CT_REP, ...
0055 CT_REL, CT_ADD, CT_NEWVAL, CT_TLOAD, CT_TAREALOAD, CT_LOAD_ALL_PQ, ...
0056 CT_LOAD_FIX_PQ, CT_LOAD_DIS_PQ, CT_LOAD_ALL_P, CT_LOAD_FIX_P, ...
0057 CT_LOAD_DIS_P, CT_TGENCOST, CT_TAREAGENCOST, CT_MODCOST_F, ...
0058 CT_MODCOST_X] = idx_ct;
0059
0060 t = 'runopf_w_res(''t_case30_userfcns'') : ';
0061 r1 = runopf_w_res(casefile, mpopt);
0062 t_is(r1.reserves.R, [25; 15; 0; 0; 20; 0], 6, [t 'R']);
0063 t_is(r1.reserves.prc, [2; 2; 2; 2; 5.33007; 5.33007], 5, [t 'prc']);
0064 t_is(r1.reserves.mu.l, [0; 0; 1; 2; 0; 0.169935], 6, [t 'mu.l']);
0065 t_is(r1.reserves.mu.u, [0.1; 0; 0; 0; 0; 0], 7, [t 'mu.u']);
0066 t_is(r1.reserves.mu.Pmax, [0; 0; 0; 0; 0.330065; 0], 6, [t 'mu.Pmax']);
0067 mpc = loadcase(casefile);
0068 [i2e, mpc.bus, mpc.gen, mpc.branch] = ext2int(mpc.bus, mpc.gen, mpc.branch);
0069
0070 t_is(r1.reserves.cost, mpc.reserves.cost, 12, [t 'cost']);
0071 t_is(r1.reserves.qty, mpc.reserves.qty, 12, [t 'qty']);
0072 t_is(r1.reserves.totalcost, 177.5, 4, [t 'totalcost']);
0073
0074
0075 mpc.gen(:, RAMP_10) = Inf;
0076 mpc.gen(:, RAMP_30) = Inf;
0077
0078
0079 xgd_table.colnames = {
0080 'PositiveActiveReservePrice', ...
0081 'PositiveActiveReserveQuantity', ...
0082 'NegativeActiveReservePrice', ...
0083 'NegativeActiveReserveQuantity', ...
0084 'PositiveActiveDeltaPrice', ...
0085 'NegativeActiveDeltaPrice', ...
0086 };
0087 xgd_table.data = [
0088 1 0 1 0 1 1;
0089 1 0 1 0 1 1;
0090 1 0 1 0 1 1;
0091 1 0 1 0 1 1;
0092 1 0 1 0 1 1;
0093 1 0 1 0 1 1;
0094 ];
0095
0096 ng = size(mpc.gen, 1);
0097 xgd = loadxgendata(xgd_table, mpc);
0098 mdi = loadmd(mpc, [], xgd);
0099 mdi.FixedReserves = mpc.reserves;
0100
0101
0102
0103 mdo = most(mdi, mpopt);
0104
0105
0106 t = 'success1';
0107 t_ok(r1.success, t);
0108
0109 t = 'success2';
0110 t_ok(mdo.QP.exitflag, t);
0111
0112 t = 'f';
0113 t_is(mdo.results.f, r1.f, 7, t);
0114
0115 t = 'Pg';
0116 t_is(mdo.flow.mpc.gen(:, PG), r1.gen(:, PG), 8, t);
0117
0118 t = 'R';
0119 t_is(mdo.flow.mpc.reserves.R, r1.reserves.R, 8, t);
0120
0121 t = 'prc';
0122 t_is(mdo.flow.mpc.reserves.prc, r1.reserves.prc, 8, t);
0123
0124 t = 'totalcost';
0125 t_is(mdo.flow.mpc.reserves.totalcost, r1.reserves.totalcost, 7, t);
0126
0127 t = 'mu.l';
0128 t_is(mdo.flow.mpc.reserves.mu.l, r1.reserves.mu.l, 8, t);
0129
0130 t = 'mu.u';
0131 t_is(mdo.flow.mpc.reserves.mu.u, r1.reserves.mu.u, 8, t);
0132
0133 t = 'mu.Pmax';
0134 t_is(mdo.flow.mpc.reserves.mu.Pmax, r1.reserves.mu.Pmax, 8, t);
0135
0136
0137
0138 nt = 3;
0139 profiles = struct( ...
0140 'type', 'mpcData', ...
0141 'table', CT_TLOAD, ...
0142 'rows', 0, ...
0143 'col', CT_LOAD_ALL_PQ, ...
0144 'chgtype', CT_REL, ...
0145 'values', [1.0; 1.1; 1.2] );
0146 mdi = loadmd(mpc, nt, xgd, [], [], profiles);
0147
0148 for t = 1:nt
0149 mdi.FixedReserves(t,1,1) = mpc.reserves;
0150 end
0151
0152
0153 f = 0;
0154 for tt = 1:nt
0155 mpc1 = mpc;
0156 mpc1.bus = scale_load(profiles.values(tt), mpc1.bus);
0157 r(tt) = runopf_w_res(mpc1, mpopt);
0158 f = f + r(tt).f;
0159 end
0160
0161 mdo = most(mdi, mpopt);
0162
0163
0164 t = 'success2';
0165 t_ok(mdo.QP.exitflag, t);
0166
0167 t = 'f';
0168 t_is(mdo.results.f, f, 4, t);
0169
0170 for tt = 1:nt
0171 t = 'success1';
0172 t_ok(r(tt).success, t);
0173
0174 t = 'Pg';
0175 t_is(mdo.flow(tt,1,1).mpc.gen(:, PG), r(tt).gen(:, PG), 4, sprintf('(t=%d) : %s', tt, t));
0176
0177 t = 'R';
0178 t_is(mdo.flow(tt,1,1).mpc.reserves.R, r(tt).reserves.R, 4, sprintf('(t=%d) : %s', tt, t));
0179
0180 t = 'prc';
0181 t_is(mdo.flow(tt,1,1).mpc.reserves.prc, r(tt).reserves.prc, 5, sprintf('(t=%d) : %s', tt, t));
0182
0183 t = 'totalcost';
0184 t_is(mdo.flow(tt,1,1).mpc.reserves.totalcost, r(tt).reserves.totalcost, 4, sprintf('(t=%d) : %s', tt, t));
0185
0186 t = 'mu.l';
0187 t_is(mdo.flow(tt,1,1).mpc.reserves.mu.l, r(tt).reserves.mu.l, 5, sprintf('(t=%d) : %s', tt, t));
0188
0189 t = 'mu.u';
0190 t_is(mdo.flow(tt,1,1).mpc.reserves.mu.u, r(tt).reserves.mu.u, 6, sprintf('(t=%d) : %s', tt, t));
0191
0192 t = 'mu.Pmax';
0193 t_is(mdo.flow(tt,1,1).mpc.reserves.mu.Pmax, r(tt).reserves.mu.Pmax, 5, sprintf('(t=%d) : %s', tt, t));
0194 end
0195
0196 t_end;