Home > matpower4.0 > t > t_off2case.m

t_off2case

PURPOSE ^

T_OFF2CASE Tests for code in OFF2CASE.

SYNOPSIS ^

function t_off2case(quiet)

DESCRIPTION ^

T_OFF2CASE  Tests for code in OFF2CASE.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_off2case(quiet)
0002 %T_OFF2CASE  Tests for code in OFF2CASE.
0003 
0004 %   MATPOWER
0005 %   $Id: t_off2case.m,v 1.10 2010/04/26 19:45:26 ray Exp $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2005-2010 by Power System Engineering Research Center (PSERC)
0008 %
0009 %   This file is part of MATPOWER.
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 %
0012 %   MATPOWER is free software: you can redistribute it and/or modify
0013 %   it under the terms of the GNU General Public License as published
0014 %   by the Free Software Foundation, either version 3 of the License,
0015 %   or (at your option) any later version.
0016 %
0017 %   MATPOWER is distributed in the hope that it will be useful,
0018 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0020 %   GNU General Public License for more details.
0021 %
0022 %   You should have received a copy of the GNU General Public License
0023 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0024 %
0025 %   Additional permission under GNU GPL version 3 section 7
0026 %
0027 %   If you modify MATPOWER, or any covered work, to interface with
0028 %   other modules (such as MATLAB code and MEX-files) available in a
0029 %   MATLAB(R) or comparable environment containing parts covered
0030 %   under other licensing terms, the licensors of MATPOWER grant
0031 %   you additional permission to convey the resulting work.
0032 
0033 if nargin < 1
0034     quiet = 0;
0035 end
0036 
0037 n_tests = 35;
0038 
0039 t_begin(n_tests, quiet);
0040 
0041 %% define named indices into data matrices
0042 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0043     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0044     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0045 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0046 
0047 %% generator data
0048 %    bus    Pg    Qg    Qmax    Qmin    Vg    mBase    status    Pmax    Pmin    Pc1    Pc2    Qc1min    Qc1max    Qc2min    Qc2max    ramp_agc    ramp_10    ramp_30    ramp_q    apf
0049 gen0 = [
0050     1    10    0    60    -15    1    100    1    60    10    0    0    0    0    0    0    0    0    0    0    0;
0051     2    10    0    60    -15    1    100    1    60    12    0    0    0    0    0    0    0    0    0    0    0;
0052     7    -30    -15    0    -15    1    100    1    0    -30    0    0    0    0    0    0    0    0    0    0    0;
0053     13    10    0    60    -15    1    100    1    60    12    0    0    0    0    0    0    0    0    0    0    0;
0054     30    -30    7.5    7.5    0    1    100    1    0    -30    0    0    0    0    0    0    0    0    0    0    0;
0055 ];
0056 %% generator cost data
0057 %    1    startup    shutdown    n    x1    y1    ...    xn    yn
0058 %    2    startup    shutdown    n    c(n-1)    ...    c0
0059 gencost0 = [
0060     1    0    0    4    0    0    12    240    36    1200    60    2400;
0061     1    100    0    4    0    0    12    240    36    1200    60    2400;
0062     1    0    0    4    -30    0    -20    1000    -10    2000    0    3000;
0063     1    0    0    4    0    0    12    240    36    1200    60    2400;
0064     1    0    50    4    -30    0    -20    1000    -10    2000    0    3000;
0065 ];
0066 
0067 if ~have_fcn('smartmarket')
0068     t_skip(n_tests, 'smartmarket code not available');
0069 else
0070     t = 'isload()';
0071     t_is(isload(gen0), [0;0;1;0;1], 8, t);
0072     
0073     G = find(~isload(gen0) );
0074     L = find( isload(gen0) );
0075     nGL = length(G) + length(L);
0076     
0077     t = 'P offers only';
0078     offers.P.qty = [25; 26; 27];
0079     offers.P.prc = [10; 50; 100];
0080     [gen, gencost] = off2case(gen0, gencost0, offers);
0081     
0082     gen1 = gen0;
0083     gen1(G, PMAX) = offers.P.qty;
0084     gen1(L, GEN_STATUS) = 0;
0085     t_is( gen, gen1, 8, [t ' - gen'] );
0086     
0087     gencost1 = gencost0;
0088     gencost1(G, NCOST:(NCOST+8)) = [[2 0 0 25 250; 2 0 0 26 1300; 2 0 0 27 2700] zeros(3,4)];
0089     
0090     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0091     
0092     offers.P.qty = [25; 26; 0; 27; 0];
0093     offers.P.prc = [10; 50; 0; 100; 0];
0094     [gen, gencost] = off2case(gen0, gencost0, offers);
0095     t_is( gen, gen1, 8, [t ' (all rows in offer) - gen'] );
0096     t_is( gencost, gencost1, 8, [t ' (all rows in offer) - gencost'] );
0097     
0098     t = 'P offers only (GEN_STATUS=0 for 0 qty offer)';
0099     offers.P.qty = [0; 26; 27];
0100     offers.P.prc = [10; 50; 100];
0101     [gen, gencost] = off2case(gen0, gencost0, offers);
0102     
0103     gen1 = gen0;
0104     gen1(G(2:3), PMAX) = offers.P.qty(2:3);
0105     gen1(G(1), GEN_STATUS) = 0;
0106     gen1(L, GEN_STATUS) = 0;
0107     t_is( gen, gen1, 8, [t ' - gen'] );
0108     
0109     gencost1 = gencost0;
0110     gencost1(G(2:3), NCOST:(NCOST+8)) = [[2 0 0 26 1300; 2 0 0 27 2700] zeros(2,4)];
0111     
0112     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0113 
0114     t = 'P offers, lim.P.max_offer';
0115     offers.P.qty = [25; 26; 27];
0116     offers.P.prc = [10; 50; 100];
0117     lim.P.max_offer = 75;
0118     [gen, gencost] = off2case(gen0, gencost0, offers, [], lim);
0119     
0120     gen1 = gen0;
0121     gen1(G(1:2), PMAX) = offers.P.qty(1:2, :);
0122     gen1([G(3); L], GEN_STATUS) = 0;
0123     t_is( gen, gen1, 8, [t ' - gen'] );
0124     
0125     gencost1 = gencost0;
0126     gencost1(G(1:2), NCOST:(NCOST+8)) = [[2 0 0 25 250; 2 0 0 26 1300] zeros(2,4)];
0127     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0128     
0129     t = 'P offers & P bids';
0130     bids.P.qty = [20; 28];
0131     bids.P.prc = [100; 10];
0132     [gen, gencost] = off2case(gen0, gencost0, offers, bids);
0133     
0134     gen1 = gen0;
0135     gen1(G, PMAX) = offers.P.qty;
0136     gen1(L, [PMIN QMIN QMAX]) = [-20 -10 0; -28 0 7];
0137     t_is( gen, gen1, 8, [t ' - gen'] );
0138     
0139     gencost1 = gencost0(:, 1:8);
0140     gencost1(G, NCOST:(NCOST+4)) = [2 0 0 25 250; 2 0 0 26 1300; 2 0 0 27 2700];
0141     gencost1(L, NCOST:(NCOST+4)) = [2 -20 -2000 0 0; 2 -28 -280 0 0];
0142     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0143     
0144     t = 'P offers & P bids (all rows in bid)';
0145     bids.P.qty = [0; 0; 20; 0; 28];
0146     bids.P.prc = [0; 0; 100; 0; 10];
0147     [gen, gencost] = off2case(gen0, gencost0, offers, bids);
0148     
0149     t_is( gen, gen1, 8, [t ' - gen'] );
0150     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0151     
0152     t = 'P offers & P bids (GEN_STATUS=0 for 0 qty bid)';
0153     bids.P.qty = [0; 28];
0154     bids.P.prc = [100; 10];
0155     [gen, gencost] = off2case(gen0, gencost0, offers, bids);
0156     
0157     gen1 = gen0;
0158     gen1(G, PMAX) = offers.P.qty;
0159     gen1(L(1), GEN_STATUS) = 0;
0160     gen1(L(2), [PMIN QMIN QMAX]) = [-28 0 7];
0161     t_is( gen, gen1, 8, [t ' - gen'] );
0162     
0163     gencost1 = gencost0;
0164     gencost1(G, NCOST:(NCOST+8)) = [[2 0 0 25 250; 2 0 0 26 1300; 2 0 0 27 2700] zeros(3,4)];
0165     gencost1(L(2), NCOST:(NCOST+8)) = [[2 -28 -280 0 0] zeros(1,4)];
0166     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0167     
0168     t = 'P offers & P bids (1 gen with both)';
0169     gen2 = gen0;
0170     gen2(2, PMIN) = -5;
0171     bids.P.qty = [0; 3; 20; 0; 28];
0172     bids.P.prc = [0; 50; 100; 0; 10];
0173     [gen, gencost] = off2case(gen2, gencost0, offers, bids);
0174     
0175     gen1 = gen2;
0176     gen1(G, PMAX) = offers.P.qty;
0177     gen1(2, PMIN) = -sum(bids.P.qty(2, :));
0178     gen1(L, [PMIN QMIN QMAX]) = [-20 -10 0; -28 0 7];
0179     t_is( gen, gen1, 8, [t ' - gen'] );
0180     
0181     gencost1 = gencost0(:, 1:10);
0182     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];
0183     gencost1(L, NCOST:(NCOST+6)) = [[2 -20 -2000 0 0; 2 -28 -280 0 0] zeros(2,2)];
0184     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0185     
0186     t = 'P offers & P bids, lim.P.max_offer/min_bid';
0187     bids.P.qty = [20; 28];
0188     bids.P.prc = [100; 10];
0189     lim.P.min_bid = 50;
0190     [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0191     
0192     gen1 = gen0;
0193     gen1(G(1:2), PMAX) = offers.P.qty(1:2, :);
0194     gen1([G(3); L(2)], GEN_STATUS) = 0;
0195     gen1(L(1), [PMIN QMIN QMAX]) = [-20 -10 0];
0196     t_is( gen, gen1, 8, [t ' - gen'] );
0197     
0198     gencost1 = gencost0;
0199     gencost1(G(1:2), NCOST:(NCOST+8)) = [[2 0 0 25 250; 2 0 0 26 1300] zeros(2,4)];
0200     gencost1(L(1), NCOST:(NCOST+8)) = [2 -20 -2000 0 0 0 0 0 0];
0201     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0202     
0203     t = 'P offers & P bids, lim.P.max_offer/min_bid, multi-block';
0204     offers.P.qty = [10 40; 20 30; 25 25];
0205     offers.P.prc = [10 100; 25 65; 50 90];
0206     bids.P.qty = [20 10; 12 18];
0207     bids.P.prc = [100 60; 70 10];
0208     [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0209     
0210     gen1 = gen0;
0211     gen1(G, PMAX) = [10; 50; 25];
0212     gen1(L, [PMIN QMIN QMAX]) = [-30 -15 0; -12 0 3];
0213     t_is( gen, gen1, 8, [t ' - gen'] );
0214     
0215     gencost1 = gencost0(:, 1:10);
0216     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];
0217     gencost1(L, NCOST:(NCOST+6)) = [3 -30 -2600 -20 -2000 0 0; 2 -12 -840 0 0 0 0];
0218     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0219     
0220     %%-----  reactive  -----
0221     %% generator cost data
0222     %    1    startup    shutdown    n    x1    y1    ...    xn    yn
0223     %    2    startup    shutdown    n    c(n-1)    ...    c0
0224     gencost0 = [
0225         1    0    0    4    0    0    12    240    36    1200    60    2400;
0226         1    100    0    4    0    0    12    240    36    1200    60    2400;
0227         1    0    0    4    -30    0    -20    1000    -10    2000    0    3000;
0228         1    0    0    4    0    0    12    240    36    1200    60    2400;
0229         1    0    50    4    -30    0    -20    1000    -10    2000    0    3000;
0230         1    0    0    4    -15    -150    0    0    30    150    60    450;
0231         1    100    0    2    0    0    0    0    0    0    0    0;
0232         1    0    0    3    -20    -15    -10    -10    0    0    0    0;
0233         1    0    0    3    0    0    40    80    60    180    0    0;
0234         1    0    50    2    0    0    0    0    0    0    0    0;
0235     ];
0236     
0237     t = 'PQ offers only';
0238     offers.P.qty = [25; 26; 27];
0239     offers.P.prc = [10; 50; 100];
0240     offers.Q.qty = [10; 20; 30];
0241     offers.Q.prc = [10; 5; 1];
0242     [gen, gencost] = off2case(gen0, gencost0, offers);
0243     
0244     gen1 = gen0;
0245     gen1(G, PMAX) = offers.P.qty;
0246     gen1(G, QMAX) = offers.Q.qty;
0247     gen1(G, QMIN) = 0;
0248     gen1(L, GEN_STATUS) = 0;
0249     t_is( gen, gen1, 8, [t ' - gen'] );
0250     
0251     gencost1 = gencost0;
0252     gencost1(G, NCOST:(NCOST+8))     = [[2 0 0 25 250; 2 0 0 26 1300; 2 0 0 27 2700] zeros(3,4)];
0253     gencost1(G+nGL, NCOST:(NCOST+8)) = [[2 0 0 10 100; 2 0 0 20 100; 2 0 0 30 30] zeros(3,4)];
0254     
0255     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0256     
0257     t = 'PQ offers & PQ bids, lim.P/Q.max_offer/min_bid, multi-block';
0258     offers.P.qty = [10 40; 20 30; 25 25];
0259     offers.P.prc = [10 100; 25 65; 50 90];
0260     bids.P.qty = [20 10; 12 18];
0261     bids.P.prc = [100 60; 70 10];
0262     offers.Q.qty = [5 5; 10 10; 15 15];
0263     offers.Q.prc = [10 20; 5 60; 1 10];
0264     bids.Q.qty = [15; 10; 15; 15; 0];
0265     bids.Q.prc = [-10; 0; 5; -20; 10];
0266     lim.Q.max_offer = 50;
0267     lim.Q.min_bid = -15;
0268     [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0269     
0270     gen1 = gen0;
0271     gen1(:, [GEN_STATUS PMIN PMAX QMIN QMAX]) = [ ...
0272         1    10    10    -15    10;
0273         1    12    50    -10    10;
0274         1    -30    0    -15    0;
0275         1    12    25    0    30;
0276         0    -30    0    0    7.5    ];
0277     t_is( gen, gen1, 8, [t ' - gen'] );
0278     
0279     gencost1 = gencost0(:, 1:12);
0280     gencost1(:, NCOST:(NCOST+8)) = [ ...
0281         2    0    0    10    100    0    0    0    0;
0282         3    0    0    20    500    50    2450    0    0;
0283         3    -30    -2600    -20    -2000    0    0    0    0;
0284         2    0    0    25    1250    0    0    0    0;
0285         4    -30    0    -20    1000    -10    2000    0    3000;
0286         4    -15    150    0    0    5    50    10    150;
0287         3    -10    0    0    0    10    50    0    0;
0288         2    -15    -75    0    0    0    0    0    0;
0289         3    0    0    15    15    30    165    0    0;
0290         2    0    0    0    0    0    0    0    0    ];
0291     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0292     
0293     t = 'PQ offers & PQ bids, for gen, no P, no shutdown';
0294     gen2 = gen0;
0295     gen2(1, PMIN) = 0;
0296     offers.P.qty = [0 40; 20 30; 25 25];
0297     [gen, gencost] = off2case(gen2, gencost0, offers, bids, lim);
0298     
0299     gen1(1, [PMIN PMAX QMIN QMAX]) = [ 0 0 -15 10 ];
0300     t_is( gen, gen1, 8, [t ' - gen'] );
0301     
0302     gencost1(1, NCOST:(NCOST+8)) = gencost0(1, NCOST:(NCOST+8));
0303     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0304     
0305     t = 'PQ offers & PQ bids, for gen, no Q, no shutdown';
0306     offers.P.qty = [10 40; 20 30; 25 25];
0307     offers.Q.qty = [5 5; 0 10; 15 15];
0308     bids.Q.qty = [15; 0; 15; 15; 0];
0309     [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0310     
0311     gen1(1, [PMIN PMAX QMIN QMAX]) = [ 10 10 -15 10 ];    %% restore original
0312     gen1(2, [PMIN PMAX QMIN QMAX]) = [ 12 50 0 0 ];
0313     t_is( gen, gen1, 8, [t ' - gen'] );
0314     
0315     gencost1([1,2,7], NCOST:(NCOST+8)) = [ ...
0316         2    0    0    10    100    0    0    0    0;
0317         3    0    0    20    500    50    2450    0    0;
0318         2    0    0    0    0    0    0    0    0    ];
0319     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0320     
0321     t = 'PQ offers & PQ bids, lim.P/Q.max_offer/min_bid, multi-block';
0322     offers.P.qty = [10 40; 20 30; 25 25];
0323     offers.P.prc = [10 100; 25 65; 50 90];
0324     bids.P.qty = [10 0; 12 18];
0325     bids.P.prc = [100 60; 70 10];
0326     offers.Q.qty = [5 5; 10 10; 15 15];
0327     offers.Q.prc = [10 20; 5 60; 1 10];
0328     bids.Q.qty = [15; 10; 10; 15; 0];
0329     bids.Q.prc = [-10; 0; 5; -20; 10];
0330     lim.Q.max_offer = 50;
0331     lim.Q.min_bid = -15;
0332     [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0333     
0334     gen1 = gen0;
0335     gen1(:, [GEN_STATUS PMIN PMAX QMIN QMAX]) = [ ...
0336         1    10    10    -15    10;
0337         1    12    50    -10    10;
0338         1    -10    0    -5    0;
0339         1    12    25    0    30;
0340         0    -30    0    0    7.5    ];
0341     t_is( gen, gen1, 8, [t ' - gen'] );
0342     
0343     gencost1 = gencost0(:, 1:12);
0344     gencost1(:, NCOST:(NCOST+8)) = [ ...
0345         2    0    0    10    100    0    0    0    0;
0346         3    0    0    20    500    50    2450    0    0;
0347         2    -10    -1000    0    0    0    0    0    0;
0348         2    0    0    25    1250    0    0    0    0;
0349         4    -30    0    -20    1000    -10    2000    0    3000;
0350         4    -15    150    0    0    5    50    10    150;
0351         3    -10    0    0    0    10    50    0    0;
0352         2    -10    -50    0    0    0    0    0    0;
0353         3    0    0    15    15    30    165    0    0;
0354         2    0    0    0    0    0    0    0    0    ];
0355     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0356 
0357     t = 'PQ offers & PQ bids, zero Q load w/P bid, shutdown bugfix';
0358     gen1 = gen0;
0359     gen1(5, [QG, QMIN, QMAX]) = 0;
0360     [gen, gencost] = off2case(gen1, gencost0, offers, bids, lim);
0361     
0362     gen1(:, [PMIN PMAX QMIN QMAX]) = [ ...
0363         10    10    -15    10;
0364         12    50    -10    10;
0365         -10    0    -5    0;
0366         12    25    0    30;
0367         -12    0    0    0    ];
0368     t_is( gen, gen1, 8, [t ' - gen'] );
0369     
0370     gencost1 = gencost0(:, 1:12);
0371     gencost1(:, NCOST:(NCOST+8)) = [ ...
0372         2    0    0    10    100    0    0    0    0;
0373         3    0    0    20    500    50    2450    0    0;
0374         2    -10    -1000    0    0    0    0    0    0;
0375         2    0    0    25    1250    0    0    0    0;
0376         2    -12    -840    0    0    0    0    0    0;
0377         4    -15    150    0    0    5    50    10    150;
0378         3    -10    0    0    0    10    50    0    0;
0379         2    -10    -50    0    0    0    0    0    0;
0380         3    0    0    15    15    30    165    0    0;
0381         2    0    0    0    0    0    0    0    0    ];
0382     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0383 
0384     t = 'PQ offers & PQ bids, non-zero Q load w/no P bid, shutdown bugfix';
0385     offers.P.qty = [10 40; 20 30; 25 25];
0386     offers.P.prc = [10 100; 25 65; 50 90];
0387     bids.P.qty = [0 10; 12 18];
0388     bids.P.prc = [100 40; 70 10];
0389     offers.Q.qty = [5 5; 10 10; 15 15];
0390     offers.Q.prc = [10 20; 5 60; 1 10];
0391     bids.Q.qty = [15; 10; 15; 15; 0];
0392     bids.Q.prc = [-10; 0; 5; -20; 10];
0393     lim.Q.max_offer = 50;
0394     lim.Q.min_bid = -15;
0395     [gen, gencost] = off2case(gen0, gencost0, offers, bids, lim);
0396     
0397     gen1 = gen0;
0398     gen1(:, [GEN_STATUS PMIN PMAX QMIN QMAX]) = [ ...
0399         1    10    10    -15    10;
0400         1    12    50    -10    10;
0401         0    -30    0    -15    0;
0402         1    12    25    0    30;
0403         0    -30    0    0    7.5    ];
0404     t_is( gen, gen1, 8, [t ' - gen'] );
0405     
0406     gencost1 = gencost0(:, 1:12);
0407     gencost1(:, NCOST:(NCOST+8)) = [ ...
0408         2    0    0    10    100    0    0    0    0;
0409         3    0    0    20    500    50    2450    0    0;
0410         4    -30    0    -20    1000    -10    2000    0    3000;
0411         2    0    0    25    1250    0    0    0    0;
0412         4    -30    0    -20    1000    -10    2000    0    3000;
0413         4    -15    150    0    0    5    50    10    150;
0414         3    -10    0    0    0    10    50    0    0;
0415         3    -20    -15    -10    -10    0    0    0    0;
0416         3    0    0    15    15    30    165    0    0;
0417         2    0    0    0    0    0    0    0    0    ];
0418     t_is( gencost, gencost1, 8, [t ' - gencost'] );
0419 end
0420 
0421 t_end;

Generated on Mon 26-Jan-2015 14:56:45 by m2html © 2005