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

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005