0001 function t_off2case(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin < 1
0013 quiet = 0;
0014 end
0015
0016 n_tests = 35;
0017
0018 t_begin(n_tests, quiet);
0019
0020
0021 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0022 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0023 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0024 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0025
0026
0027
0028 gen0 = [
0029 1 10 0 60 -15 1 100 1 60 10 0 0 0 0 0 0 0 0 0 0 0;
0030 2 10 0 60 -15 1 100 1 60 12 0 0 0 0 0 0 0 0 0 0 0;
0031 7 -30 -15 0 -15 1 100 1 0 -30 0 0 0 0 0 0 0 0 0 0 0;
0032 13 10 0 60 -15 1 100 1 60 12 0 0 0 0 0 0 0 0 0 0 0;
0033 30 -30 7.5 7.5 0 1 100 1 0 -30 0 0 0 0 0 0 0 0 0 0 0;
0034 ];
0035
0036
0037
0038 gencost0 = [
0039 1 0 0 4 0 0 12 240 36 1200 60 2400;
0040 1 100 0 4 0 0 12 240 36 1200 60 2400;
0041 1 0 0 4 -30 0 -20 1000 -10 2000 0 3000;
0042 1 0 0 4 0 0 12 240 36 1200 60 2400;
0043 1 0 50 4 -30 0 -20 1000 -10 2000 0 3000;
0044 ];
0045
0046 if ~have_fcn('smartmarket')
0047 t_skip(n_tests, 'smartmarket code not available');
0048 else
0049 t = 'isload()';
0050 t_is(isload(gen0), [0;0;1;0;1], 8, t);
0051
0052 G = find(~isload(gen0) );
0053 L = find( isload(gen0) );
0054 nGL = length(G) + length(L);
0055
0056 t = 'P offers only';
0057 offers.P.qty = [25; 26; 27];
0058 offers.P.prc = [10; 50; 100];
0059 [gen, gencost] = off2case(gen0, gencost0, offers);
0060
0061 gen1 = gen0;
0062 gen1(G, PMAX) = offers.P.qty;
0063 gen1(L, GEN_STATUS) = 0;
0064 t_is( gen, gen1, 8, [t ' - gen'] );
0065
0066 gencost1 = gencost0;
0067 gencost1(G, NCOST:(NCOST+8)) = [[2 0 0 25 250; 2 0 0 26 1300; 2 0 0 27 2700] zeros(3,4)];
0068
0069 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0070
0071 offers.P.qty = [25; 26; 0; 27; 0];
0072 offers.P.prc = [10; 50; 0; 100; 0];
0073 [gen, gencost] = off2case(gen0, gencost0, offers);
0074 t_is( gen, gen1, 8, [t ' (all rows in offer) - gen'] );
0075 t_is( gencost, gencost1, 8, [t ' (all rows in offer) - gencost'] );
0076
0077 t = 'P offers only (GEN_STATUS=0 for 0 qty offer)';
0078 offers.P.qty = [0; 26; 27];
0079 offers.P.prc = [10; 50; 100];
0080 [gen, gencost] = off2case(gen0, gencost0, offers);
0081
0082 gen1 = gen0;
0083 gen1(G(2:3), PMAX) = offers.P.qty(2:3);
0084 gen1(G(1), GEN_STATUS) = 0;
0085 gen1(L, GEN_STATUS) = 0;
0086 t_is( gen, gen1, 8, [t ' - gen'] );
0087
0088 gencost1 = gencost0;
0089 gencost1(G(2:3), NCOST:(NCOST+8)) = [[2 0 0 26 1300; 2 0 0 27 2700] zeros(2,4)];
0090
0091 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0092
0093 t = 'P offers, lim.P.max_offer';
0094 offers.P.qty = [25; 26; 27];
0095 offers.P.prc = [10; 50; 100];
0096 lim.P.max_offer = 75;
0097 [gen, gencost] = off2case(gen0, gencost0, offers, [], lim);
0098
0099 gen1 = gen0;
0100 gen1(G(1:2), PMAX) = offers.P.qty(1:2, :);
0101 gen1([G(3); L], GEN_STATUS) = 0;
0102 t_is( gen, gen1, 8, [t ' - gen'] );
0103
0104 gencost1 = gencost0;
0105 gencost1(G(1:2), NCOST:(NCOST+8)) = [[2 0 0 25 250; 2 0 0 26 1300] zeros(2,4)];
0106 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0107
0108 t = 'P offers & P bids';
0109 bids.P.qty = [20; 28];
0110 bids.P.prc = [100; 10];
0111 [gen, gencost] = off2case(gen0, gencost0, offers, bids);
0112
0113 gen1 = gen0;
0114 gen1(G, PMAX) = offers.P.qty;
0115 gen1(L, [PMIN QMIN QMAX]) = [-20 -10 0; -28 0 7];
0116 t_is( gen, gen1, 8, [t ' - gen'] );
0117
0118 gencost1 = gencost0(:, 1:8);
0119 gencost1(G, NCOST:(NCOST+4)) = [2 0 0 25 250; 2 0 0 26 1300; 2 0 0 27 2700];
0120 gencost1(L, NCOST:(NCOST+4)) = [2 -20 -2000 0 0; 2 -28 -280 0 0];
0121 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0122
0123 t = 'P offers & P bids (all rows in bid)';
0124 bids.P.qty = [0; 0; 20; 0; 28];
0125 bids.P.prc = [0; 0; 100; 0; 10];
0126 [gen, gencost] = off2case(gen0, gencost0, offers, bids);
0127
0128 t_is( gen, gen1, 8, [t ' - gen'] );
0129 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0130
0131 t = 'P offers & P bids (GEN_STATUS=0 for 0 qty bid)';
0132 bids.P.qty = [0; 28];
0133 bids.P.prc = [100; 10];
0134 [gen, gencost] = off2case(gen0, gencost0, offers, bids);
0135
0136 gen1 = gen0;
0137 gen1(G, PMAX) = offers.P.qty;
0138 gen1(L(1), GEN_STATUS) = 0;
0139 gen1(L(2), [PMIN QMIN QMAX]) = [-28 0 7];
0140 t_is( gen, gen1, 8, [t ' - gen'] );
0141
0142 gencost1 = gencost0;
0143 gencost1(G, NCOST:(NCOST+8)) = [[2 0 0 25 250; 2 0 0 26 1300; 2 0 0 27 2700] zeros(3,4)];
0144 gencost1(L(2), NCOST:(NCOST+8)) = [[2 -28 -280 0 0] zeros(1,4)];
0145 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0146
0147 t = 'P offers & P bids (1 gen with both)';
0148 gen2 = gen0;
0149 gen2(2, PMIN) = -5;
0150 bids.P.qty = [0; 3; 20; 0; 28];
0151 bids.P.prc = [0; 50; 100; 0; 10];
0152 [gen, gencost] = off2case(gen2, gencost0, offers, bids);
0153
0154 gen1 = gen2;
0155 gen1(G, PMAX) = offers.P.qty;
0156 gen1(2, PMIN) = -sum(bids.P.qty(2, :));
0157 gen1(L, [PMIN QMIN QMAX]) = [-20 -10 0; -28 0 7];
0158 t_is( gen, gen1, 8, [t ' - gen'] );
0159
0160 gencost1 = gencost0(:, 1:10);
0161 gencost1(G, NCOST:(NCOST+6)) = [2 0 0 25 250 0 0; 3 -3 -150 0 0 26 1300; 2 0 0 27 2700 0 0];
0162 gencost1(L, NCOST:(NCOST+6)) = [[2 -20 -2000 0 0; 2 -28 -280 0 0] zeros(2,2)];
0163 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0164
0165 t = 'P offers & P bids, lim.P.max_offer/min_bid';
0166 bids.P.qty = [20; 28];
0167 bids.P.prc = [100; 10];
0168 lim.P.min_bid = 50;
0169 [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0170
0171 gen1 = gen0;
0172 gen1(G(1:2), PMAX) = offers.P.qty(1:2, :);
0173 gen1([G(3); L(2)], GEN_STATUS) = 0;
0174 gen1(L(1), [PMIN QMIN QMAX]) = [-20 -10 0];
0175 t_is( gen, gen1, 8, [t ' - gen'] );
0176
0177 gencost1 = gencost0;
0178 gencost1(G(1:2), NCOST:(NCOST+8)) = [[2 0 0 25 250; 2 0 0 26 1300] zeros(2,4)];
0179 gencost1(L(1), NCOST:(NCOST+8)) = [2 -20 -2000 0 0 0 0 0 0];
0180 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0181
0182 t = 'P offers & P bids, lim.P.max_offer/min_bid, multi-block';
0183 offers.P.qty = [10 40; 20 30; 25 25];
0184 offers.P.prc = [10 100; 25 65; 50 90];
0185 bids.P.qty = [20 10; 12 18];
0186 bids.P.prc = [100 60; 70 10];
0187 [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0188
0189 gen1 = gen0;
0190 gen1(G, PMAX) = [10; 50; 25];
0191 gen1(L, [PMIN QMIN QMAX]) = [-30 -15 0; -12 0 3];
0192 t_is( gen, gen1, 8, [t ' - gen'] );
0193
0194 gencost1 = gencost0(:, 1:10);
0195 gencost1(G, NCOST:(NCOST+6)) = [2 0 0 10 100 0 0; 3 0 0 20 500 50 2450; 2 0 0 25 1250 0 0];
0196 gencost1(L, NCOST:(NCOST+6)) = [3 -30 -2600 -20 -2000 0 0; 2 -12 -840 0 0 0 0];
0197 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0198
0199
0200
0201
0202
0203 gencost0 = [
0204 1 0 0 4 0 0 12 240 36 1200 60 2400;
0205 1 100 0 4 0 0 12 240 36 1200 60 2400;
0206 1 0 0 4 -30 0 -20 1000 -10 2000 0 3000;
0207 1 0 0 4 0 0 12 240 36 1200 60 2400;
0208 1 0 50 4 -30 0 -20 1000 -10 2000 0 3000;
0209 1 0 0 4 -15 -150 0 0 30 150 60 450;
0210 1 100 0 2 0 0 0 0 0 0 0 0;
0211 1 0 0 3 -20 -15 -10 -10 0 0 0 0;
0212 1 0 0 3 0 0 40 80 60 180 0 0;
0213 1 0 50 2 0 0 0 0 0 0 0 0;
0214 ];
0215
0216 t = 'PQ offers only';
0217 offers.P.qty = [25; 26; 27];
0218 offers.P.prc = [10; 50; 100];
0219 offers.Q.qty = [10; 20; 30];
0220 offers.Q.prc = [10; 5; 1];
0221 [gen, gencost] = off2case(gen0, gencost0, offers);
0222
0223 gen1 = gen0;
0224 gen1(G, PMAX) = offers.P.qty;
0225 gen1(G, QMAX) = offers.Q.qty;
0226 gen1(G, QMIN) = 0;
0227 gen1(L, GEN_STATUS) = 0;
0228 t_is( gen, gen1, 8, [t ' - gen'] );
0229
0230 gencost1 = gencost0;
0231 gencost1(G, NCOST:(NCOST+8)) = [[2 0 0 25 250; 2 0 0 26 1300; 2 0 0 27 2700] zeros(3,4)];
0232 gencost1(G+nGL, NCOST:(NCOST+8)) = [[2 0 0 10 100; 2 0 0 20 100; 2 0 0 30 30] zeros(3,4)];
0233
0234 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0235
0236 t = 'PQ offers & PQ bids, lim.P/Q.max_offer/min_bid, multi-block';
0237 offers.P.qty = [10 40; 20 30; 25 25];
0238 offers.P.prc = [10 100; 25 65; 50 90];
0239 bids.P.qty = [20 10; 12 18];
0240 bids.P.prc = [100 60; 70 10];
0241 offers.Q.qty = [5 5; 10 10; 15 15];
0242 offers.Q.prc = [10 20; 5 60; 1 10];
0243 bids.Q.qty = [15; 10; 15; 15; 0];
0244 bids.Q.prc = [-10; 0; 5; -20; 10];
0245 lim.Q.max_offer = 50;
0246 lim.Q.min_bid = -15;
0247 [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0248
0249 gen1 = gen0;
0250 gen1(:, [GEN_STATUS PMIN PMAX QMIN QMAX]) = [ ...
0251 1 10 10 -15 10;
0252 1 12 50 -10 10;
0253 1 -30 0 -15 0;
0254 1 12 25 0 30;
0255 0 -30 0 0 7.5 ];
0256 t_is( gen, gen1, 8, [t ' - gen'] );
0257
0258 gencost1 = gencost0(:, 1:12);
0259 gencost1(:, NCOST:(NCOST+8)) = [ ...
0260 2 0 0 10 100 0 0 0 0;
0261 3 0 0 20 500 50 2450 0 0;
0262 3 -30 -2600 -20 -2000 0 0 0 0;
0263 2 0 0 25 1250 0 0 0 0;
0264 4 -30 0 -20 1000 -10 2000 0 3000;
0265 4 -15 150 0 0 5 50 10 150;
0266 3 -10 0 0 0 10 50 0 0;
0267 2 -15 -75 0 0 0 0 0 0;
0268 3 0 0 15 15 30 165 0 0;
0269 2 0 0 0 0 0 0 0 0 ];
0270 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0271
0272 t = 'PQ offers & PQ bids, for gen, no P, no shutdown';
0273 gen2 = gen0;
0274 gen2(1, PMIN) = 0;
0275 offers.P.qty = [0 40; 20 30; 25 25];
0276 [gen, gencost] = off2case(gen2, gencost0, offers, bids, lim);
0277
0278 gen1(1, [PMIN PMAX QMIN QMAX]) = [ 0 0 -15 10 ];
0279 t_is( gen, gen1, 8, [t ' - gen'] );
0280
0281 gencost1(1, NCOST:(NCOST+8)) = gencost0(1, NCOST:(NCOST+8));
0282 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0283
0284 t = 'PQ offers & PQ bids, for gen, no Q, no shutdown';
0285 offers.P.qty = [10 40; 20 30; 25 25];
0286 offers.Q.qty = [5 5; 0 10; 15 15];
0287 bids.Q.qty = [15; 0; 15; 15; 0];
0288 [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0289
0290 gen1(1, [PMIN PMAX QMIN QMAX]) = [ 10 10 -15 10 ];
0291 gen1(2, [PMIN PMAX QMIN QMAX]) = [ 12 50 0 0 ];
0292 t_is( gen, gen1, 8, [t ' - gen'] );
0293
0294 gencost1([1,2,7], NCOST:(NCOST+8)) = [ ...
0295 2 0 0 10 100 0 0 0 0;
0296 3 0 0 20 500 50 2450 0 0;
0297 2 0 0 0 0 0 0 0 0 ];
0298 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0299
0300 t = 'PQ offers & PQ bids, lim.P/Q.max_offer/min_bid, multi-block';
0301 offers.P.qty = [10 40; 20 30; 25 25];
0302 offers.P.prc = [10 100; 25 65; 50 90];
0303 bids.P.qty = [10 0; 12 18];
0304 bids.P.prc = [100 60; 70 10];
0305 offers.Q.qty = [5 5; 10 10; 15 15];
0306 offers.Q.prc = [10 20; 5 60; 1 10];
0307 bids.Q.qty = [15; 10; 10; 15; 0];
0308 bids.Q.prc = [-10; 0; 5; -20; 10];
0309 lim.Q.max_offer = 50;
0310 lim.Q.min_bid = -15;
0311 [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0312
0313 gen1 = gen0;
0314 gen1(:, [GEN_STATUS PMIN PMAX QMIN QMAX]) = [ ...
0315 1 10 10 -15 10;
0316 1 12 50 -10 10;
0317 1 -10 0 -5 0;
0318 1 12 25 0 30;
0319 0 -30 0 0 7.5 ];
0320 t_is( gen, gen1, 8, [t ' - gen'] );
0321
0322 gencost1 = gencost0(:, 1:12);
0323 gencost1(:, NCOST:(NCOST+8)) = [ ...
0324 2 0 0 10 100 0 0 0 0;
0325 3 0 0 20 500 50 2450 0 0;
0326 2 -10 -1000 0 0 0 0 0 0;
0327 2 0 0 25 1250 0 0 0 0;
0328 4 -30 0 -20 1000 -10 2000 0 3000;
0329 4 -15 150 0 0 5 50 10 150;
0330 3 -10 0 0 0 10 50 0 0;
0331 2 -10 -50 0 0 0 0 0 0;
0332 3 0 0 15 15 30 165 0 0;
0333 2 0 0 0 0 0 0 0 0 ];
0334 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0335
0336 t = 'PQ offers & PQ bids, zero Q load w/P bid, shutdown bugfix';
0337 gen1 = gen0;
0338 gen1(5, [QG, QMIN, QMAX]) = 0;
0339 [gen, gencost] = off2case(gen1, gencost0, offers, bids, lim);
0340
0341 gen1(:, [PMIN PMAX QMIN QMAX]) = [ ...
0342 10 10 -15 10;
0343 12 50 -10 10;
0344 -10 0 -5 0;
0345 12 25 0 30;
0346 -12 0 0 0 ];
0347 t_is( gen, gen1, 8, [t ' - gen'] );
0348
0349 gencost1 = gencost0(:, 1:12);
0350 gencost1(:, NCOST:(NCOST+8)) = [ ...
0351 2 0 0 10 100 0 0 0 0;
0352 3 0 0 20 500 50 2450 0 0;
0353 2 -10 -1000 0 0 0 0 0 0;
0354 2 0 0 25 1250 0 0 0 0;
0355 2 -12 -840 0 0 0 0 0 0;
0356 4 -15 150 0 0 5 50 10 150;
0357 3 -10 0 0 0 10 50 0 0;
0358 2 -10 -50 0 0 0 0 0 0;
0359 3 0 0 15 15 30 165 0 0;
0360 2 0 0 0 0 0 0 0 0 ];
0361 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0362
0363 t = 'PQ offers & PQ bids, non-zero Q load w/no P bid, shutdown bugfix';
0364 offers.P.qty = [10 40; 20 30; 25 25];
0365 offers.P.prc = [10 100; 25 65; 50 90];
0366 bids.P.qty = [0 10; 12 18];
0367 bids.P.prc = [100 40; 70 10];
0368 offers.Q.qty = [5 5; 10 10; 15 15];
0369 offers.Q.prc = [10 20; 5 60; 1 10];
0370 bids.Q.qty = [15; 10; 15; 15; 0];
0371 bids.Q.prc = [-10; 0; 5; -20; 10];
0372 lim.Q.max_offer = 50;
0373 lim.Q.min_bid = -15;
0374 [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0375
0376 gen1 = gen0;
0377 gen1(:, [GEN_STATUS PMIN PMAX QMIN QMAX]) = [ ...
0378 1 10 10 -15 10;
0379 1 12 50 -10 10;
0380 0 -30 0 -15 0;
0381 1 12 25 0 30;
0382 0 -30 0 0 7.5 ];
0383 t_is( gen, gen1, 8, [t ' - gen'] );
0384
0385 gencost1 = gencost0(:, 1:12);
0386 gencost1(:, NCOST:(NCOST+8)) = [ ...
0387 2 0 0 10 100 0 0 0 0;
0388 3 0 0 20 500 50 2450 0 0;
0389 4 -30 0 -20 1000 -10 2000 0 3000;
0390 2 0 0 25 1250 0 0 0 0;
0391 4 -30 0 -20 1000 -10 2000 0 3000;
0392 4 -15 150 0 0 5 50 10 150;
0393 3 -10 0 0 0 10 50 0 0;
0394 3 -20 -15 -10 -10 0 0 0 0;
0395 3 0 0 15 15 30 165 0 0;
0396 2 0 0 0 0 0 0 0 0 ];
0397 t_is( gencost, gencost1, 8, [t ' - gencost'] );
0398 end
0399
0400 t_end;