Home > matpower6.0 > t > t_apply_changes.m

t_apply_changes

PURPOSE ^

T_APPLY_CHANGES Tests for code in apply_changes.m.

SYNOPSIS ^

function t_apply_changes(quiet)

DESCRIPTION ^

T_APPLY_CHANGES  Tests for code in apply_changes.m.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_apply_changes(quiet)
0002 %T_APPLY_CHANGES  Tests for code in apply_changes.m.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2008-2016, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of MATPOWER.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 n_tests = 570;
0017 
0018 t_begin(n_tests, quiet);
0019 
0020 %% define named indices into data matrices
0021 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0022     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
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 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0027     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0028     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0029 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0030 [CT_LABEL, CT_PROB, CT_TABLE, CT_TBUS, CT_TGEN, CT_TBRCH, CT_TAREABUS, ...
0031     CT_TAREAGEN, CT_TAREABRCH, CT_ROW, CT_COL, CT_CHGTYPE, CT_REP, ...
0032     CT_REL, CT_ADD, CT_NEWVAL, CT_TLOAD, CT_TAREALOAD, CT_LOAD_ALL_PQ, ...
0033     CT_LOAD_FIX_PQ, CT_LOAD_DIS_PQ, CT_LOAD_ALL_P, CT_LOAD_FIX_P, ...
0034     CT_LOAD_DIS_P, CT_TGENCOST, CT_TAREAGENCOST, CT_MODCOST_F, ...
0035     CT_MODCOST_X] = idx_ct;
0036 
0037 mpc = loadcase('t_auction_case');
0038 mpc.gen(8, GEN_BUS) = 2;    %% multiple d. loads per area, same bus as gen
0039 mpc.gen(8, [QG QMIN QMAX]) = [ 3 0 3 ];
0040 %% put it load before gen in matrix
0041 mpc.gen = [mpc.gen(8, :); mpc.gen(1:7, :); mpc.gen(9, :)];
0042 ld = find(isload(mpc.gen));
0043 
0044 %% create map of external bus numbers to bus indices
0045 i2e = mpc.bus(:, BUS_I);
0046 e2i = sparse(max(i2e), 1);
0047 e2i(i2e) = (1:size(mpc.bus, 1))';
0048 
0049 for k = 1:3
0050     a{k} = find(mpc.bus(:, BUS_AREA) == k); %% buses in area k
0051     [junk, tmp, junk2] = intersect(e2i(mpc.gen(ld, GEN_BUS)), a{k});
0052     lda{k} = ld(tmp);                       %% disp loads in area k
0053     ga{k} = find(ismember(e2i(mpc.gen(:, GEN_BUS)), a{k}));
0054     tmp1 = find(ismember(e2i(mpc.branch(:, F_BUS)), a{k}));
0055     tmp2 = find(ismember(e2i(mpc.branch(:, T_BUS)), a{k}));
0056     bra{k} = unique([tmp1; tmp2]);
0057 end
0058 for k = 1:3
0059     area(k).fixed.p = sum(mpc.bus(a{k}, PD));
0060     area(k).fixed.q = sum(mpc.bus(a{k}, QD));
0061     area(k).disp.p = -sum(mpc.gen(lda{k}, PMIN));
0062     area(k).disp.qmin = -sum(mpc.gen(lda{k}, QMIN));
0063     area(k).disp.qmax = -sum(mpc.gen(lda{k}, QMAX));
0064     area(k).disp.q = area(k).disp.qmin + area(k).disp.qmax;
0065     area(k).both.p = area(k).fixed.p + area(k).disp.p;
0066     area(k).both.q = area(k).fixed.q + area(k).disp.q;
0067 end
0068 total.fixed.p = sum(mpc.bus(:, PD));
0069 total.fixed.q = sum(mpc.bus(:, QD));
0070 total.disp.p = -sum(mpc.gen(ld, PMIN));
0071 total.disp.qmin = -sum(mpc.gen(ld, QMIN));
0072 total.disp.qmax = -sum(mpc.gen(ld, QMAX));
0073 total.disp.q = total.disp.qmin + total.disp.qmax;
0074 total.both.p = total.fixed.p + total.disp.p;
0075 total.both.q = total.fixed.q + total.disp.q;
0076 
0077 chgtab = [
0078     1   0.002   CT_TBUS         1   GS              CT_REP  5;
0079     2   0.002   CT_TBUS         2   VMIN            CT_REL  1/0.95; %% 1
0080     3   0.002   CT_TBUS         0   VMAX            CT_ADD  -0.01;  %% VMAX - 0.01
0081     4   0.002   CT_TBRCH        1   BR_STATUS       CT_REP  0;
0082     5   0.002   CT_TBRCH        2   RATE_A          CT_REL  0.1;    %% 1000
0083     6   0.002   CT_TBRCH        0   RATE_B          CT_ADD  0.1;    %% RATE_B + 0.1
0084     7   0.002   CT_TGEN         1   GEN_STATUS      CT_REP  0;
0085     8   0.002   CT_TGEN         2   QMAX            CT_REL  1.1;    %% 66
0086     9   0.002   CT_TGEN         0   PMIN            CT_ADD  0.5;    %% PMIN + 0.5
0087     10  0.002   CT_TAREABUS     1   VMAX            CT_REP  1.1;
0088     11  0.002   CT_TAREABUS     2   VMAX            CT_REL  1.01;
0089     12  0.002   CT_TAREABUS     3   VMAX            CT_ADD  0.1;
0090     13  0.002   CT_TAREABRCH    1   RATE_B          CT_REP  100;
0091     14  0.002   CT_TAREABRCH    2   RATE_B          CT_REL  1.1;
0092     15  0.002   CT_TAREABRCH    3   RATE_B          CT_ADD  0.5;
0093     16  0.002   CT_TAREAGEN     1   PMIN            CT_REP  0;
0094     17  0.002   CT_TAREAGEN     2   PMIN            CT_REL  1.1;
0095     18  0.002   CT_TAREAGEN     3   PMIN            CT_ADD  0.1;
0096     20  0.002   CT_TLOAD        0   CT_LOAD_FIX_PQ  CT_REL  2;      %% fixed PQ * 2
0097     21  0.002   CT_TLOAD        0   CT_LOAD_FIX_P   CT_REL  2;      %% fixed P * 2
0098     22  0.002   CT_TLOAD        0   CT_LOAD_ALL_PQ  CT_REL  2;      %% all PQ * 2
0099     23  0.002   CT_TLOAD        0   CT_LOAD_ALL_P   CT_REL  2;      %% all P * 2
0100     24  0.002   CT_TLOAD        0   CT_LOAD_DIS_PQ  CT_REL  2;      %% disp PQ * 2
0101     25  0.002   CT_TLOAD        0   CT_LOAD_DIS_P   CT_REL  2;      %% disp P * 2
0102     26  0.002   CT_TLOAD        0   CT_LOAD_FIX_PQ  CT_REP  200;    %% fixed PQ => total = 200
0103     27  0.002   CT_TLOAD        0   CT_LOAD_FIX_P   CT_REP  200;    %% fixed P => total = 200
0104     28  0.002   CT_TLOAD        0   CT_LOAD_ALL_PQ  CT_REP  200;    %% all PQ => total = 200
0105     29  0.002   CT_TLOAD        0   CT_LOAD_ALL_P   CT_REP  200;    %% all P => total = 200
0106     30  0.002   CT_TLOAD        0   CT_LOAD_DIS_PQ  CT_REP  200;    %% disp PQ => total = 200
0107     31  0.002   CT_TLOAD        0   CT_LOAD_DIS_P   CT_REP  200;    %% disp P => total = 200
0108     32  0.002   CT_TLOAD        0   CT_LOAD_FIX_PQ  CT_ADD  25;     %% fixed PQ + 25
0109     33  0.002   CT_TLOAD        0   CT_LOAD_FIX_P   CT_ADD  25;     %% fixed P + 25
0110     34  0.002   CT_TLOAD        0   CT_LOAD_ALL_PQ  CT_ADD  25;     %% all PQ + 25
0111     35  0.002   CT_TLOAD        0   CT_LOAD_ALL_P   CT_ADD  25;     %% all P + 25
0112     36  0.002   CT_TLOAD        0   CT_LOAD_DIS_PQ  CT_ADD  25;     %% disp PQ + 25
0113     37  0.002   CT_TLOAD        0   CT_LOAD_DIS_P   CT_ADD  25;     %% disp P + 25
0114     40  0.002   CT_TLOAD        2   CT_LOAD_FIX_PQ  CT_REL  2;      %% fixed PQ * 2
0115     41  0.002   CT_TLOAD        2   CT_LOAD_FIX_P   CT_REL  2;      %% fixed P * 2
0116     42  0.002   CT_TLOAD        2   CT_LOAD_ALL_PQ  CT_REL  2;      %% all PQ * 2
0117     43  0.002   CT_TLOAD        2   CT_LOAD_ALL_P   CT_REL  2;      %% all P * 2
0118     44  0.002   CT_TLOAD        2   CT_LOAD_DIS_PQ  CT_REL  2;      %% disp PQ * 2
0119     45  0.002   CT_TLOAD        2   CT_LOAD_DIS_P   CT_REL  2;      %% disp P * 2
0120     46  0.002   CT_TLOAD        2   CT_LOAD_FIX_PQ  CT_REP  50;     %% fixed PQ => total = 50
0121     47  0.002   CT_TLOAD        2   CT_LOAD_FIX_P   CT_REP  50;     %% fixed P => total = 50
0122     48  0.002   CT_TLOAD        2   CT_LOAD_ALL_PQ  CT_REP  50;     %% all PQ => total = 50
0123     49  0.002   CT_TLOAD        2   CT_LOAD_ALL_P   CT_REP  50;     %% all P => total = 50
0124     50  0.002   CT_TLOAD        2   CT_LOAD_DIS_PQ  CT_REP  50;     %% disp PQ => total = 50
0125     51  0.002   CT_TLOAD        2   CT_LOAD_DIS_P   CT_REP  50;     %% disp P => total = 50
0126     52  0.002   CT_TLOAD        2   CT_LOAD_FIX_PQ  CT_ADD  10;     %% fixed PQ + 10
0127     53  0.002   CT_TLOAD        2   CT_LOAD_FIX_P   CT_ADD  10;     %% fixed P + 10
0128     54  0.002   CT_TLOAD        2   CT_LOAD_ALL_PQ  CT_ADD  10;     %% all PQ + 10
0129     55  0.002   CT_TLOAD        2   CT_LOAD_ALL_P   CT_ADD  10;     %% all P + 10
0130     56  0.002   CT_TLOAD        2   CT_LOAD_DIS_PQ  CT_ADD  10;     %% disp PQ + 10
0131     57  0.002   CT_TLOAD        2   CT_LOAD_DIS_P   CT_ADD  10;     %% disp P + 10
0132     60  0.002   CT_TAREALOAD    1   CT_LOAD_FIX_PQ  CT_REL  3;      %% fixed PQ * 2
0133     61  0.002   CT_TAREALOAD    1   CT_LOAD_FIX_P   CT_REL  3;      %% fixed P * 2
0134     62  0.002   CT_TAREALOAD    1   CT_LOAD_ALL_PQ  CT_REL  3;      %% all PQ * 2
0135     63  0.002   CT_TAREALOAD    1   CT_LOAD_ALL_P   CT_REL  3;      %% all P * 2
0136     64  0.002   CT_TAREALOAD    1   CT_LOAD_DIS_PQ  CT_REL  3;      %% disp PQ * 2
0137     65  0.002   CT_TAREALOAD    1   CT_LOAD_DIS_P   CT_REL  3;      %% disp P * 2
0138     66  0.002   CT_TAREALOAD    1   CT_LOAD_FIX_PQ  CT_REP  100;    %% fixed PQ => total = 50
0139     67  0.002   CT_TAREALOAD    1   CT_LOAD_FIX_P   CT_REP  100;    %% fixed P => total = 50
0140     68  0.002   CT_TAREALOAD    1   CT_LOAD_ALL_PQ  CT_REP  100;    %% all PQ => total = 50
0141     69  0.002   CT_TAREALOAD    1   CT_LOAD_ALL_P   CT_REP  100;    %% all P => total = 50
0142     70  0.002   CT_TAREALOAD    1   CT_LOAD_DIS_PQ  CT_REP  100;    %% disp PQ => total = 50
0143     71  0.002   CT_TAREALOAD    1   CT_LOAD_DIS_P   CT_REP  100;    %% disp P => total = 50
0144     72  0.002   CT_TAREALOAD    1   CT_LOAD_FIX_PQ  CT_ADD  20;     %% fixed PQ + 10
0145     73  0.002   CT_TAREALOAD    1   CT_LOAD_FIX_P   CT_ADD  20;     %% fixed P + 10
0146     74  0.002   CT_TAREALOAD    1   CT_LOAD_ALL_PQ  CT_ADD  20;     %% all PQ + 10
0147     75  0.002   CT_TAREALOAD    1   CT_LOAD_ALL_P   CT_ADD  20;     %% all P + 10
0148     76  0.002   CT_TAREALOAD    1   CT_LOAD_DIS_PQ  CT_ADD  20;     %% disp PQ + 10
0149     77  0.002   CT_TAREALOAD    1   CT_LOAD_DIS_P   CT_ADD  20;     %% disp P + 10
0150     78  0.002   CT_TGENCOST     1   STARTUP         CT_REP  1000;
0151     79  0.002   CT_TGENCOST     2   COST+3          CT_REL  1.1;    %% 240 * 1.1
0152     80  0.002   CT_TGENCOST     0   NCOST           CT_ADD  -1;     %% NCOST - 1
0153     81  0.002   CT_TGENCOST     1   CT_MODCOST_X    CT_REL  1.1;    %% SCALE COST HORIZ
0154     82  0.002   CT_TGENCOST     0   CT_MODCOST_X    CT_REL  0.9;    %% SCALE COST HORIZ
0155     83  0.002   CT_TGENCOST     2   CT_MODCOST_X    CT_ADD  -10;    %% SHIFT COST HORIZ
0156     84  0.002   CT_TGENCOST     0   CT_MODCOST_X    CT_ADD  20;     %% SHIFT COST HORIZ
0157     85  0.002   CT_TGENCOST     1   CT_MODCOST_F    CT_REL  1.1;    %% SCALE COST VERTICAL
0158     86  0.002   CT_TGENCOST     0   CT_MODCOST_F    CT_REL  0.9;    %% SCALE COST VERTICAL
0159     87  0.002   CT_TGENCOST     2   CT_MODCOST_F    CT_ADD  -10;    %% SHIFT COST VERTICAL
0160     88  0.002   CT_TGENCOST     0   CT_MODCOST_F    CT_ADD  20;     %% SHIFT COST VERTICAL
0161     89  0.002   CT_TAREAGENCOST 1   SHUTDOWN        CT_REP  500;
0162     90  0.002   CT_TAREAGENCOST 2   COST+5          CT_REL  1.1;
0163     91  0.002   CT_TAREAGENCOST 3   NCOST           CT_ADD  -2;
0164     92  0.002   CT_TAREAGENCOST 1   CT_MODCOST_X    CT_REL  1.1;    %% SCALE COST HORIZ
0165     93  0.002   CT_TAREAGENCOST 2   CT_MODCOST_X    CT_ADD  -10;    %% SHIFT COST HORIZ
0166     94  0.002   CT_TAREAGENCOST 1   CT_MODCOST_F    CT_REL  1.1;    %% SCALE COST VERTICAL
0167     95  0.002   CT_TAREAGENCOST 2   CT_MODCOST_F    CT_ADD  -10;    %% SHIFT COST VERTICAL
0168     122 0.002   CT_TLOAD        0   -CT_LOAD_ALL_PQ CT_REL  2;      %% all PQ * 2, incl cost
0169     123 0.002   CT_TLOAD        0   -CT_LOAD_ALL_P  CT_REL  2;      %% all P * 2, incl cost
0170     124 0.002   CT_TLOAD        0   -CT_LOAD_DIS_PQ CT_REL  2;      %% disp PQ * 2, incl cost
0171     125 0.002   CT_TLOAD        0   -CT_LOAD_DIS_P  CT_REL  2;      %% disp P * 2, incl cost
0172     128 0.002   CT_TLOAD        0   -CT_LOAD_ALL_PQ CT_REP  200;    %% all PQ => total = 200, incl cost
0173     129 0.002   CT_TLOAD        0   -CT_LOAD_ALL_P  CT_REP  200;    %% all P => total = 200, incl cost
0174     130 0.002   CT_TLOAD        0   -CT_LOAD_DIS_PQ CT_REP  200;    %% disp PQ => total = 200, incl cost
0175     131 0.002   CT_TLOAD        0   -CT_LOAD_DIS_P  CT_REP  200;    %% disp P => total = 200, incl cost
0176     134 0.002   CT_TLOAD        0   -CT_LOAD_ALL_PQ CT_ADD  25;     %% all PQ + 25, incl cost
0177     135 0.002   CT_TLOAD        0   -CT_LOAD_ALL_P  CT_ADD  25;     %% all P + 25, incl cost
0178     136 0.002   CT_TLOAD        0   -CT_LOAD_DIS_PQ CT_ADD  25;     %% disp PQ + 25, incl cost
0179     137 0.002   CT_TLOAD        0   -CT_LOAD_DIS_P  CT_ADD  25;     %% disp P + 25, incl cost
0180     142 0.002   CT_TLOAD        2   -CT_LOAD_ALL_PQ CT_REL  2;      %% all PQ * 2, incl cost
0181     143 0.002   CT_TLOAD        2   -CT_LOAD_ALL_P  CT_REL  2;      %% all P * 2, incl cost
0182     144 0.002   CT_TLOAD        2   -CT_LOAD_DIS_PQ CT_REL  2;      %% disp PQ * 2, incl cost
0183     145 0.002   CT_TLOAD        2   -CT_LOAD_DIS_P  CT_REL  2;      %% disp P * 2, incl cost
0184     148 0.002   CT_TLOAD        2   -CT_LOAD_ALL_PQ CT_REP  50;     %% all PQ => total = 50, incl cost
0185     149 0.002   CT_TLOAD        2   -CT_LOAD_ALL_P  CT_REP  50;     %% all P => total = 50, incl cost
0186     150 0.002   CT_TLOAD        2   -CT_LOAD_DIS_PQ CT_REP  50;     %% disp PQ => total = 50, incl cost
0187     151 0.002   CT_TLOAD        2   -CT_LOAD_DIS_P  CT_REP  50;     %% disp P => total = 50, incl cost
0188     154 0.002   CT_TLOAD        2   -CT_LOAD_ALL_PQ CT_ADD  10;     %% all PQ + 10, incl cost
0189     155 0.002   CT_TLOAD        2   -CT_LOAD_ALL_P  CT_ADD  10;     %% all P + 10, incl cost
0190     156 0.002   CT_TLOAD        2   -CT_LOAD_DIS_PQ CT_ADD  10;     %% disp PQ + 10, incl cost
0191     157 0.002   CT_TLOAD        2   -CT_LOAD_DIS_P  CT_ADD  10;     %% disp P + 10, incl cost
0192     162 0.002   CT_TAREALOAD    1   -CT_LOAD_ALL_PQ CT_REL  3;      %% all PQ * 2, incl cost
0193     163 0.002   CT_TAREALOAD    1   -CT_LOAD_ALL_P  CT_REL  3;      %% all P * 2, incl cost
0194     164 0.002   CT_TAREALOAD    1   -CT_LOAD_DIS_PQ CT_REL  3;      %% disp PQ * 2, incl cost
0195     165 0.002   CT_TAREALOAD    1   -CT_LOAD_DIS_P  CT_REL  3;      %% disp P * 2, incl cost
0196     168 0.002   CT_TAREALOAD    1   -CT_LOAD_ALL_PQ CT_REP  100;    %% all PQ => total = 50, incl cost
0197     169 0.002   CT_TAREALOAD    1   -CT_LOAD_ALL_P  CT_REP  100;    %% all P => total = 50, incl cost
0198     170 0.002   CT_TAREALOAD    1   -CT_LOAD_DIS_PQ CT_REP  100;    %% disp PQ => total = 50, incl cost
0199     171 0.002   CT_TAREALOAD    1   -CT_LOAD_DIS_P  CT_REP  100;    %% disp P => total = 50, incl cost
0200     174 0.002   CT_TAREALOAD    1   -CT_LOAD_ALL_PQ CT_ADD  20;     %% all PQ + 10, incl cost
0201     175 0.002   CT_TAREALOAD    1   -CT_LOAD_ALL_P  CT_ADD  20;     %% all P + 10, incl cost
0202     176 0.002   CT_TAREALOAD    1   -CT_LOAD_DIS_PQ CT_ADD  20;     %% disp PQ + 10, incl cost
0203     177 0.002   CT_TAREALOAD    1   -CT_LOAD_DIS_P  CT_ADD  20;     %% disp P + 10, incl cost
0204 ];
0205 
0206 %%-----  bus  -----
0207 t = 'bus, replace';
0208 g = apply_changes(1, mpc, chgtab);
0209 e = mpc;
0210 e.bus(1, GS) = 5;
0211 t_is(g.bus, e.bus, 12, t);
0212 
0213 t = 'bus, scale';
0214 g = apply_changes(2, mpc, chgtab);
0215 e = mpc;
0216 e.bus(2, VMIN) = 1;
0217 t_is(g.bus, e.bus, 12, t);
0218 
0219 t = 'bus, shift';
0220 g = apply_changes(3, mpc, chgtab);
0221 e = mpc;
0222 e.bus(:, VMAX) = mpc.bus(:, VMAX) - 0.01;
0223 t_is(g.bus, e.bus, 12, t);
0224 
0225 %%-----  branch  -----
0226 t = 'branch, replace';
0227 g = apply_changes(4, mpc, chgtab);
0228 e = mpc;
0229 e.branch(1, BR_STATUS) = 0;
0230 t_is(g.branch, e.branch, 12, t);
0231 
0232 t = 'branch, scale';
0233 g = apply_changes(5, mpc, chgtab);
0234 e = mpc;
0235 e.branch(2, RATE_A) = 1000;
0236 t_is(g.branch, e.branch, 12, t);
0237 
0238 t = 'branch, shift';
0239 g = apply_changes(6, mpc, chgtab);
0240 e = mpc;
0241 e.branch(:, RATE_B) = mpc.branch(:, RATE_B) + 0.1;
0242 t_is(g.branch, e.branch, 12, t);
0243 
0244 %%-----  gen  -----
0245 t = 'gen, replace';
0246 g = apply_changes(7, mpc, chgtab);
0247 e = mpc;
0248 e.gen(1, GEN_STATUS) = 0;
0249 t_is(g.gen, e.gen, 12, t);
0250 
0251 t = 'gen, scale';
0252 g = apply_changes(8, mpc, chgtab);
0253 e = mpc;
0254 e.gen(2, QMAX) = 66;
0255 t_is(g.gen, e.gen, 12, t);
0256 
0257 t = 'gen, shift';
0258 g = apply_changes(9, mpc, chgtab);
0259 e = mpc;
0260 e.gen(:, PMIN) = mpc.gen(:, PMIN) + 0.5;
0261 t_is(g.gen, e.gen, 12, t);
0262 
0263 %%-----  gencost  -----
0264 t = 'gencost, replace';
0265 g = apply_changes(78, mpc, chgtab);
0266 e = mpc;
0267 e.gencost(1, STARTUP) = 1000;
0268 t_is(g.gencost, e.gencost, 12, t);
0269 
0270 t = 'gencost, scale';
0271 g = apply_changes(79, mpc, chgtab);
0272 e = mpc;
0273 e.gencost(2, COST+3) = 264;
0274 t_is(g.gencost, e.gencost, 12, t);
0275 
0276 t = 'gencost, shift';
0277 g = apply_changes(80, mpc, chgtab);
0278 e = mpc;
0279 e.gencost(:, NCOST) = 3;
0280 t_is(g.gencost, e.gencost, 12, t);
0281 
0282 t = 'gencost, modcost x, scale';
0283 g = apply_changes(81, mpc, chgtab);
0284 e = mpc;
0285 e.gencost(1, :) = modcost(mpc.gencost(1, :), 1.1, 'SCALE_X');
0286 t_is(g.gencost, e.gencost, 12, t);
0287 
0288 t = 'gencost, modcost x, scale all';
0289 g = apply_changes(82, mpc, chgtab);
0290 e = mpc;
0291 e.gencost = modcost(mpc.gencost, 0.9, 'SCALE_X');
0292 t_is(g.gencost, e.gencost, 12, t);
0293 
0294 t = 'gencost, modcost x, shift';
0295 g = apply_changes(83, mpc, chgtab);
0296 e = mpc;
0297 e.gencost(2, :) = modcost(mpc.gencost(2, :), -10, 'SHIFT_X');
0298 t_is(g.gencost, e.gencost, 12, t);
0299 
0300 t = 'gencost, modcost x, shift all';
0301 g = apply_changes(84, mpc, chgtab);
0302 e = mpc;
0303 e.gencost = modcost(mpc.gencost, 20, 'SHIFT_X');
0304 t_is(g.gencost, e.gencost, 12, t);
0305 
0306 t = 'gencost, modcost f, scale';
0307 g = apply_changes(85, mpc, chgtab);
0308 e = mpc;
0309 e.gencost(1, :) = modcost(mpc.gencost(1, :), 1.1, 'SCALE_F');
0310 t_is(g.gencost, e.gencost, 12, t);
0311 
0312 t = 'gencost, modcost f, scale all';
0313 g = apply_changes(86, mpc, chgtab);
0314 e = mpc;
0315 e.gencost = modcost(mpc.gencost, 0.9, 'SCALE_F');
0316 t_is(g.gencost, e.gencost, 12, t);
0317 
0318 t = 'gencost, modcost f, shift';
0319 g = apply_changes(87, mpc, chgtab);
0320 e = mpc;
0321 e.gencost(2, :) = modcost(mpc.gencost(2, :), -10, 'SHIFT_F');
0322 t_is(g.gencost, e.gencost, 12, t);
0323 
0324 t = 'gencost, modcost f, shift all';
0325 g = apply_changes(88, mpc, chgtab);
0326 e = mpc;
0327 e.gencost = modcost(mpc.gencost, 20, 'SHIFT_F');
0328 t_is(g.gencost, e.gencost, 12, t);
0329 
0330 %%-----  area bus  -----
0331 t = 'area bus : replace';
0332 g = apply_changes(10, mpc, chgtab);
0333 e = mpc;
0334 e.bus(a{1}, VMAX) = 1.1;
0335 t_is(g.bus, e.bus, 12, t);
0336 
0337 t = 'area bus, scale';
0338 g = apply_changes(11, mpc, chgtab);
0339 e = mpc;
0340 e.bus(a{2}, VMAX) = e.bus(a{2}, VMAX) * 1.01;
0341 t_is(g.bus, e.bus, 12, t);
0342 
0343 t = 'area bus, shift';
0344 g = apply_changes(12, mpc, chgtab);
0345 e = mpc;
0346 e.bus(a{3}, VMAX) = mpc.bus(a{3}, VMAX) + 0.1;
0347 t_is(g.bus, e.bus, 12, t);
0348 
0349 %%-----  area branch  -----
0350 t = 'area branch : replace';
0351 g = apply_changes(13, mpc, chgtab);
0352 e = mpc;
0353 e.branch(bra{1}, RATE_B) = 100;
0354 t_is(g.branch, e.branch, 12, t);
0355 
0356 t = 'area branch, scale';
0357 g = apply_changes(14, mpc, chgtab);
0358 e = mpc;
0359 e.branch(bra{2}, RATE_B) = e.branch(bra{2}, RATE_B) * 1.1;
0360 t_is(g.branch, e.branch, 12, t);
0361 
0362 t = 'area branch, shift';
0363 g = apply_changes(15, mpc, chgtab);
0364 e = mpc;
0365 e.branch(bra{3}, RATE_B) = mpc.branch(bra{3}, RATE_B) + 0.5;
0366 t_is(g.branch, e.branch, 12, t);
0367 
0368 %%-----  area gen  -----
0369 t = 'area gen : replace';
0370 g = apply_changes(16, mpc, chgtab);
0371 e = mpc;
0372 e.gen(ga{1}, PMIN) = 0;
0373 t_is(g.gen, e.gen, 12, t);
0374 
0375 t = 'area gen, scale';
0376 g = apply_changes(17, mpc, chgtab);
0377 e = mpc;
0378 e.gen(ga{2}, PMIN) = e.gen(ga{2}, PMIN) * 1.1;
0379 t_is(g.gen, e.gen, 12, t);
0380 
0381 t = 'area gen, shift';
0382 g = apply_changes(18, mpc, chgtab);
0383 e = mpc;
0384 e.gen(ga{3}, PMIN) = mpc.gen(ga{3}, PMIN) + 0.1;
0385 t_is(g.gen, e.gen, 12, t);
0386 
0387 %%-----  area gencost  -----
0388 t = 'area gencost : replace';
0389 g = apply_changes(89, mpc, chgtab);
0390 e = mpc;
0391 e.gencost(ga{1}, SHUTDOWN) = 500;
0392 t_is(g.gencost, e.gencost, 12, t);
0393 
0394 t = 'area gencost, scale';
0395 g = apply_changes(90, mpc, chgtab);
0396 e = mpc;
0397 e.gencost(ga{2}, COST+5) = e.gencost(ga{2}, COST+5) * 1.1;
0398 t_is(g.gencost, e.gencost, 12, t);
0399 
0400 t = 'area gencost, shift';
0401 g = apply_changes(91, mpc, chgtab);
0402 e = mpc;
0403 e.gencost(ga{3}, NCOST) = 2;
0404 t_is(g.gencost, e.gencost, 12, t);
0405 
0406 t = 'area gencost, modcost x, scale';
0407 g = apply_changes(92, mpc, chgtab);
0408 e = mpc;
0409 e.gencost(ga{1}, :) = modcost(mpc.gencost(ga{1}, :), 1.1, 'SCALE_X');
0410 t_is(g.gencost, e.gencost, 12, t);
0411 
0412 t = 'area gencost, modcost x, shift';
0413 g = apply_changes(93, mpc, chgtab);
0414 e = mpc;
0415 e.gencost(ga{2}, :) = modcost(mpc.gencost(ga{2}, :), -10, 'SHIFT_X');
0416 t_is(g.gencost, e.gencost, 12, t);
0417 
0418 t = 'area gencost, modcost f, scale';
0419 g = apply_changes(94, mpc, chgtab);
0420 e = mpc;
0421 e.gencost(ga{1}, :) = modcost(mpc.gencost(ga{1}, :), 1.1, 'SCALE_F');
0422 t_is(g.gencost, e.gencost, 12, t);
0423 
0424 t = 'area gencost, modcost f, shift';
0425 g = apply_changes(95, mpc, chgtab);
0426 e = mpc;
0427 e.gencost(ga{2}, :) = modcost(mpc.gencost(ga{2}, :), -10, 'SHIFT_F');
0428 t_is(g.gencost, e.gencost, 12, t);
0429 
0430 %%-----  single load zone, one scale factor  -----
0431 load = 2;
0432 t = 'all fixed loads (PQ) * 2 : ';
0433 e = mpc;
0434 g = apply_changes(20, mpc, chgtab);
0435 t_is(sum(g.bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0436 t_is(sum(g.bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0437 t_is(-sum(g.gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0438 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0439 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0440 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0441 
0442 t = 'all fixed loads (P) * 2 : ';
0443 e = mpc;
0444 g = apply_changes(21, mpc, chgtab);
0445 t_is(sum(g.bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0446 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0447 t_is(-sum(g.gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0448 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0449 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0450 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0451 
0452 t = 'all loads (PQ) * 2 : ';
0453 e = mpc;
0454 g = apply_changes(22, mpc, chgtab);
0455 t_is(sum(g.bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0456 t_is(sum(g.bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0457 t_is(-sum(g.gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0458 t_is(-sum(g.gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0459 t_is(-sum(g.gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0460 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0461 
0462 t = 'all loads (P) * 2 : ';
0463 e = mpc;
0464 g = apply_changes(23, mpc, chgtab);
0465 t_is(sum(g.bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0466 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0467 t_is(-sum(g.gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0468 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0469 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0470 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0471 
0472 t = 'all disp loads (PQ) * 2 : ';
0473 e = mpc;
0474 g = apply_changes(24, mpc, chgtab);
0475 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0476 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0477 t_is(-sum(g.gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0478 t_is(-sum(g.gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0479 t_is(-sum(g.gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0480 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0481 
0482 t = 'all disp loads (P) * 2 : ';
0483 e = mpc;
0484 g = apply_changes(25, mpc, chgtab);
0485 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0486 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0487 t_is(-sum(g.gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0488 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0489 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0490 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0491 
0492 t = 'all loads+cost (PQ) * 2 : ';
0493 e = mpc;
0494 e.gencost(ld, :) = modcost(e.gencost(ld, :), load, 'SCALE_F');
0495 e.gencost(ld, :) = modcost(e.gencost(ld, :), load, 'SCALE_X');
0496 g = apply_changes(122, mpc, chgtab);
0497 t_is(sum(g.bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0498 t_is(sum(g.bus(:, QD)), load*total.fixed.q, 8, [t 'total fixed Q']);
0499 t_is(-sum(g.gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0500 t_is(-sum(g.gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0501 t_is(-sum(g.gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0502 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0503 
0504 t = 'all loads+cost (P) * 2 : ';
0505 e = mpc;
0506 e.gencost(ld, :) = modcost(e.gencost(ld, :), load, 'SCALE_F');
0507 e.gencost(ld, :) = modcost(e.gencost(ld, :), load, 'SCALE_X');
0508 g = apply_changes(123, mpc, chgtab);
0509 t_is(sum(g.bus(:, PD)), load*total.fixed.p, 8, [t 'total fixed P']);
0510 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0511 t_is(-sum(g.gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0512 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0513 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0514 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0515 
0516 t = 'all disp loads+cost (PQ) * 2 : ';
0517 e = mpc;
0518 e.gencost(ld, :) = modcost(e.gencost(ld, :), load, 'SCALE_F');
0519 e.gencost(ld, :) = modcost(e.gencost(ld, :), load, 'SCALE_X');
0520 g = apply_changes(124, mpc, chgtab);
0521 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0522 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0523 t_is(-sum(g.gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0524 t_is(-sum(g.gen(ld, QMIN)), load*total.disp.qmin, 8, [t 'total disp Qmin']);
0525 t_is(-sum(g.gen(ld, QMAX)), load*total.disp.qmax, 8, [t 'total disp Qmax']);
0526 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0527 
0528 t = 'all disp loads+cost (P) * 2 : ';
0529 e = mpc;
0530 e.gencost(ld, :) = modcost(e.gencost(ld, :), load, 'SCALE_F');
0531 e.gencost(ld, :) = modcost(e.gencost(ld, :), load, 'SCALE_X');
0532 g = apply_changes(125, mpc, chgtab);
0533 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0534 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0535 t_is(-sum(g.gen(ld, PMIN)), load*total.disp.p, 8, [t 'total disp P']);
0536 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0537 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0538 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0539 
0540 %%-----  single load zone, one replace quantity  -----
0541 load = 200;
0542 t = 'all fixed loads (PQ) => total = 200 : ';
0543 e = mpc;
0544 g = apply_changes(26, mpc, chgtab);
0545 t_is(sum(g.bus(:, PD)), load-total.disp.p, 8, [t 'total fixed P']);
0546 t_is(sum(g.bus(:, QD)), (load-total.disp.p)/total.fixed.p*total.fixed.q, 8, [t 'total fixed Q']);
0547 t_is(-sum(g.gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0548 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0549 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0550 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0551 
0552 t = 'all fixed loads (P) => total = 200 : ';
0553 e = mpc;
0554 g = apply_changes(27, mpc, chgtab);
0555 t_is(sum(g.bus(:, PD)), load-total.disp.p, 8, [t 'total fixed P']);
0556 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0557 t_is(-sum(g.gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0558 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0559 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0560 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0561 
0562 t = 'all loads (PQ) => total = 200 : ';
0563 e = mpc;
0564 g = apply_changes(28, mpc, chgtab);
0565 t_is(sum(g.bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0566 t_is(sum(g.bus(:, QD)), load/total.both.p*total.fixed.q, 8, [t 'total fixed Q']);
0567 t_is(-sum(g.gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0568 t_is(-sum(g.gen(ld, QMIN)), load/total.both.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0569 t_is(-sum(g.gen(ld, QMAX)), load/total.both.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0570 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0571 
0572 t = 'all loads (P) => total = 200 : ';
0573 e = mpc;
0574 g = apply_changes(29, mpc, chgtab);
0575 t_is(sum(g.bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0576 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0577 t_is(-sum(g.gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0578 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0579 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0580 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0581 
0582 t = 'all disp loads (PQ) => total = 200 : ';
0583 e = mpc;
0584 g = apply_changes(30, mpc, chgtab);
0585 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0586 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0587 t_is(-sum(g.gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0588 t_is(-sum(g.gen(ld, QMIN)), (load-total.fixed.p)/total.disp.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0589 t_is(-sum(g.gen(ld, QMAX)), (load-total.fixed.p)/total.disp.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0590 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0591 
0592 t = 'all disp loads (P) => total = 200 : ';
0593 e = mpc;
0594 g = apply_changes(31, mpc, chgtab);
0595 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0596 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0597 t_is(-sum(g.gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0598 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0599 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0600 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0601 
0602 t = 'all loads+cost (PQ) => total = 200 : ';
0603 e = mpc;
0604 e.gencost(ld, :) = modcost(e.gencost(ld, :), load/total.both.p, 'SCALE_F');
0605 e.gencost(ld, :) = modcost(e.gencost(ld, :), load/total.both.p, 'SCALE_X');
0606 g = apply_changes(128, mpc, chgtab);
0607 t_is(sum(g.bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0608 t_is(sum(g.bus(:, QD)), load/total.both.p*total.fixed.q, 8, [t 'total fixed Q']);
0609 t_is(-sum(g.gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0610 t_is(-sum(g.gen(ld, QMIN)), load/total.both.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0611 t_is(-sum(g.gen(ld, QMAX)), load/total.both.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0612 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0613 
0614 t = 'all loads+cost (P) => total = 200 : ';
0615 e = mpc;
0616 e.gencost(ld, :) = modcost(e.gencost(ld, :), load/total.both.p, 'SCALE_F');
0617 e.gencost(ld, :) = modcost(e.gencost(ld, :), load/total.both.p, 'SCALE_X');
0618 g = apply_changes(129, mpc, chgtab);
0619 t_is(sum(g.bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0620 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0621 t_is(-sum(g.gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0622 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0623 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0624 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0625 
0626 t = 'all disp loads+cost (PQ) => total = 200 : ';
0627 e = mpc;
0628 e.gencost(ld, :) = modcost(e.gencost(ld, :), (load-total.fixed.p)/total.disp.p, 'SCALE_F');
0629 e.gencost(ld, :) = modcost(e.gencost(ld, :), (load-total.fixed.p)/total.disp.p, 'SCALE_X');
0630 g = apply_changes(130, mpc, chgtab);
0631 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0632 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0633 t_is(-sum(g.gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0634 t_is(-sum(g.gen(ld, QMIN)), (load-total.fixed.p)/total.disp.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0635 t_is(-sum(g.gen(ld, QMAX)), (load-total.fixed.p)/total.disp.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0636 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0637 
0638 t = 'all disp loads+cost (P) => total = 200 : ';
0639 e = mpc;
0640 e.gencost(ld, :) = modcost(e.gencost(ld, :), (load-total.fixed.p)/total.disp.p, 'SCALE_F');
0641 e.gencost(ld, :) = modcost(e.gencost(ld, :), (load-total.fixed.p)/total.disp.p, 'SCALE_X');
0642 g = apply_changes(131, mpc, chgtab);
0643 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0644 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0645 t_is(-sum(g.gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0646 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0647 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0648 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0649 
0650 %%-----  single load zone, one shift quantity  -----
0651 load = 25 + total_load(mpc, 'all');
0652 t = 'all fixed loads (PQ) => total + 25 : ';
0653 e = mpc;
0654 g = apply_changes(32, mpc, chgtab);
0655 t_is(sum(g.bus(:, PD)), load-total.disp.p, 8, [t 'total fixed P']);
0656 t_is(sum(g.bus(:, QD)), (load-total.disp.p)/total.fixed.p*total.fixed.q, 8, [t 'total fixed Q']);
0657 t_is(-sum(g.gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0658 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0659 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0660 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0661 
0662 t = 'all fixed loads (P) => total + 25 : ';
0663 e = mpc;
0664 g = apply_changes(33, mpc, chgtab);
0665 t_is(sum(g.bus(:, PD)), load-total.disp.p, 8, [t 'total fixed P']);
0666 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0667 t_is(-sum(g.gen(ld, PMIN)), total.disp.p, 8, [t 'total disp P']);
0668 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0669 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0670 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0671 
0672 t = 'all loads (PQ) => total + 25 : ';
0673 e = mpc;
0674 g = apply_changes(34, mpc, chgtab);
0675 t_is(sum(g.bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0676 t_is(sum(g.bus(:, QD)), load/total.both.p*total.fixed.q, 8, [t 'total fixed Q']);
0677 t_is(-sum(g.gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0678 t_is(-sum(g.gen(ld, QMIN)), load/total.both.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0679 t_is(-sum(g.gen(ld, QMAX)), load/total.both.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0680 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0681 
0682 t = 'all loads (P) => total + 25 : ';
0683 e = mpc;
0684 g = apply_changes(35, mpc, chgtab);
0685 t_is(sum(g.bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0686 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0687 t_is(-sum(g.gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0688 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0689 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0690 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0691 
0692 t = 'all disp loads (PQ) => total + 25 : ';
0693 e = mpc;
0694 g = apply_changes(36, mpc, chgtab);
0695 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0696 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0697 t_is(-sum(g.gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0698 t_is(-sum(g.gen(ld, QMIN)), (load-total.fixed.p)/total.disp.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0699 t_is(-sum(g.gen(ld, QMAX)), (load-total.fixed.p)/total.disp.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0700 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0701 
0702 t = 'all disp loads (P) => total + 25 : ';
0703 e = mpc;
0704 g = apply_changes(37, mpc, chgtab);
0705 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0706 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0707 t_is(-sum(g.gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0708 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0709 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0710 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0711 
0712 t = 'all loads+cost (PQ) => total + 25 : ';
0713 e = mpc;
0714 e.gencost(ld, :) = modcost(e.gencost(ld, :), load/total.both.p, 'SCALE_F');
0715 e.gencost(ld, :) = modcost(e.gencost(ld, :), load/total.both.p, 'SCALE_X');
0716 g = apply_changes(134, mpc, chgtab);
0717 t_is(sum(g.bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0718 t_is(sum(g.bus(:, QD)), load/total.both.p*total.fixed.q, 8, [t 'total fixed Q']);
0719 t_is(-sum(g.gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0720 t_is(-sum(g.gen(ld, QMIN)), load/total.both.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0721 t_is(-sum(g.gen(ld, QMAX)), load/total.both.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0722 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0723 
0724 t = 'all loads+cost (P) => total + 25 : ';
0725 e = mpc;
0726 e.gencost(ld, :) = modcost(e.gencost(ld, :), load/total.both.p, 'SCALE_F');
0727 e.gencost(ld, :) = modcost(e.gencost(ld, :), load/total.both.p, 'SCALE_X');
0728 g = apply_changes(135, mpc, chgtab);
0729 t_is(sum(g.bus(:, PD)), load/total.both.p*total.fixed.p, 8, [t 'total fixed P']);
0730 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0731 t_is(-sum(g.gen(ld, PMIN)), load/total.both.p*total.disp.p, 8, [t 'total disp P']);
0732 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0733 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0734 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0735 
0736 t = 'all disp loads+cost (PQ) => total + 25 : ';
0737 e = mpc;
0738 e.gencost(ld, :) = modcost(e.gencost(ld, :), (load-total.fixed.p)/total.disp.p, 'SCALE_F');
0739 e.gencost(ld, :) = modcost(e.gencost(ld, :), (load-total.fixed.p)/total.disp.p, 'SCALE_X');
0740 g = apply_changes(136, mpc, chgtab);
0741 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0742 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0743 t_is(-sum(g.gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0744 t_is(-sum(g.gen(ld, QMIN)), (load-total.fixed.p)/total.disp.p*total.disp.qmin, 8, [t 'total disp Qmin']);
0745 t_is(-sum(g.gen(ld, QMAX)), (load-total.fixed.p)/total.disp.p*total.disp.qmax, 8, [t 'total disp Qmax']);
0746 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0747 
0748 t = 'all disp loads+cost (P) => total + 25 : ';
0749 e = mpc;
0750 e.gencost(ld, :) = modcost(e.gencost(ld, :), (load-total.fixed.p)/total.disp.p, 'SCALE_F');
0751 e.gencost(ld, :) = modcost(e.gencost(ld, :), (load-total.fixed.p)/total.disp.p, 'SCALE_X');
0752 g = apply_changes(137, mpc, chgtab);
0753 t_is(sum(g.bus(:, PD)), total.fixed.p, 8, [t 'total fixed P']);
0754 t_is(sum(g.bus(:, QD)), total.fixed.q, 8, [t 'total fixed Q']);
0755 t_is(-sum(g.gen(ld, PMIN)), load-total.fixed.p, 8, [t 'total disp P']);
0756 t_is(-sum(g.gen(ld, QMIN)), total.disp.qmin, 8, [t 'total disp Qmin']);
0757 t_is(-sum(g.gen(ld, QMAX)), total.disp.qmax, 8, [t 'total disp Qmax']);
0758 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0759 
0760 %%-----  single bus, one scale factor  -----
0761 nb = size(mpc.bus, 1);
0762 ng = size(mpc.gen, 1);
0763 idx1 = [1 3:nb]';
0764 idx2 = (2:ng)';
0765 load = 2;
0766 t = 'bus 2 fixed loads (PQ) * 2 : ';
0767 e = mpc;
0768 g = apply_changes(40, mpc, chgtab);
0769 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0770 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0771 t_is(g.bus(2, PD), load*mpc.bus(2, PD), 8, [t 'fixed P']);
0772 t_is(g.bus(2, QD), load*mpc.bus(2, QD), 8, [t 'fixed Q']);
0773 t_is(g.gen(1, PMIN), mpc.gen(1, PMIN), 8, [t 'disp P']);
0774 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0775 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0776 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0777 
0778 t = 'bus 2 fixed loads (P) * 2 : ';
0779 e = mpc;
0780 g = apply_changes(41, mpc, chgtab);
0781 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0782 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0783 t_is(g.bus(2, PD), load*mpc.bus(2, PD), 8, [t 'fixed P']);
0784 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0785 t_is(g.gen(1, PMIN), mpc.gen(1, PMIN), 8, [t 'disp P']);
0786 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0787 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0788 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0789 
0790 t = 'bus 2 loads (PQ) * 2 : ';
0791 e = mpc;
0792 g = apply_changes(42, mpc, chgtab);
0793 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0794 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0795 t_is(g.bus(2, PD), load*mpc.bus(2, PD), 8, [t 'fixed P']);
0796 t_is(g.bus(2, QD), load*mpc.bus(2, QD), 8, [t 'fixed Q']);
0797 t_is(g.gen(1, PMIN), load*mpc.gen(1, PMIN), 8, [t 'disp P']);
0798 t_is(g.gen(1, QMIN), load*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0799 t_is(g.gen(1, QMAX), load*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0800 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0801 
0802 t = 'bus 2 loads (P) * 2 : ';
0803 e = mpc;
0804 g = apply_changes(43, mpc, chgtab);
0805 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0806 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0807 t_is(g.bus(2, PD), load*mpc.bus(2, PD), 8, [t 'fixed P']);
0808 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0809 t_is(g.gen(1, PMIN), load*mpc.gen(1, PMIN), 8, [t 'disp P']);
0810 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0811 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0812 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0813 
0814 t = 'bus 2 disp loads (PQ) * 2 : ';
0815 e = mpc;
0816 g = apply_changes(44, mpc, chgtab);
0817 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0818 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0819 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
0820 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0821 t_is(g.gen(1, PMIN), load*mpc.gen(1, PMIN), 8, [t 'disp P']);
0822 t_is(g.gen(1, QMIN), load*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0823 t_is(g.gen(1, QMAX), load*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0824 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0825 
0826 t = 'bus 2 disp loads (P) * 2 : ';
0827 e = mpc;
0828 g = apply_changes(45, mpc, chgtab);
0829 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0830 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0831 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
0832 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0833 t_is(g.gen(1, PMIN), load*mpc.gen(1, PMIN), 8, [t 'disp P']);
0834 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0835 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0836 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0837 
0838 t = 'bus 2 loads+cost (PQ) * 2 : ';
0839 e = mpc;
0840 e.gencost(1, :) = modcost(e.gencost(1, :), load, 'SCALE_F');
0841 e.gencost(1, :) = modcost(e.gencost(1, :), load, 'SCALE_X');
0842 g = apply_changes(142, mpc, chgtab);
0843 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0844 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0845 t_is(g.bus(2, PD), load*mpc.bus(2, PD), 8, [t 'fixed P']);
0846 t_is(g.bus(2, QD), load*mpc.bus(2, QD), 8, [t 'fixed Q']);
0847 t_is(g.gen(1, PMIN), load*mpc.gen(1, PMIN), 8, [t 'disp P']);
0848 t_is(g.gen(1, QMIN), load*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0849 t_is(g.gen(1, QMAX), load*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0850 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0851 
0852 t = 'bus 2 loads+cost (P) * 2 : ';
0853 e = mpc;
0854 e.gencost(1, :) = modcost(e.gencost(1, :), load, 'SCALE_F');
0855 e.gencost(1, :) = modcost(e.gencost(1, :), load, 'SCALE_X');
0856 g = apply_changes(143, mpc, chgtab);
0857 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0858 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0859 t_is(g.bus(2, PD), load*mpc.bus(2, PD), 8, [t 'fixed P']);
0860 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0861 t_is(g.gen(1, PMIN), load*mpc.gen(1, PMIN), 8, [t 'disp P']);
0862 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0863 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0864 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0865 
0866 t = 'bus 2 disp loads+cost (PQ) * 2 : ';
0867 e = mpc;
0868 e.gencost(1, :) = modcost(e.gencost(1, :), load, 'SCALE_F');
0869 e.gencost(1, :) = modcost(e.gencost(1, :), load, 'SCALE_X');
0870 g = apply_changes(144, mpc, chgtab);
0871 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0872 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0873 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
0874 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0875 t_is(g.gen(1, PMIN), load*mpc.gen(1, PMIN), 8, [t 'disp P']);
0876 t_is(g.gen(1, QMIN), load*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0877 t_is(g.gen(1, QMAX), load*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0878 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0879 
0880 t = 'bus 2 disp loads+cost (P) * 2 : ';
0881 e = mpc;
0882 e.gencost(1, :) = modcost(e.gencost(1, :), load, 'SCALE_F');
0883 e.gencost(1, :) = modcost(e.gencost(1, :), load, 'SCALE_X');
0884 g = apply_changes(145, mpc, chgtab);
0885 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0886 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0887 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
0888 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0889 t_is(g.gen(1, PMIN), load*mpc.gen(1, PMIN), 8, [t 'disp P']);
0890 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0891 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0892 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0893 
0894 %%-----  single bus, one replace quantity  -----
0895 load = 50;
0896 t = 'bus 2 fixed loads (PQ) => Pd = 50 : ';
0897 scale = (load+mpc.gen(1, PMIN)) / mpc.bus(2, PD);
0898 e = mpc;
0899 g = apply_changes(46, mpc, chgtab);
0900 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0901 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0902 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
0903 t_is(g.bus(2, QD), scale*mpc.bus(2, QD), 8, [t 'fixed Q']);
0904 t_is(g.gen(1, PMIN), mpc.gen(1, PMIN), 8, [t 'disp P']);
0905 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0906 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0907 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0908 
0909 t = 'bus 2 fixed loads (P) => Pd = 50 : ';
0910 e = mpc;
0911 g = apply_changes(47, mpc, chgtab);
0912 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0913 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0914 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
0915 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0916 t_is(g.gen(1, PMIN), mpc.gen(1, PMIN), 8, [t 'disp P']);
0917 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0918 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0919 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0920 
0921 t = 'bus 2 loads (PQ) => Pd = 50 : ';
0922 scale = load / (mpc.bus(2, PD) - mpc.gen(1, PMIN));
0923 e = mpc;
0924 g = apply_changes(48, mpc, chgtab);
0925 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0926 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0927 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
0928 t_is(g.bus(2, QD), scale*mpc.bus(2, QD), 8, [t 'fixed Q']);
0929 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
0930 t_is(g.gen(1, QMIN), scale*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0931 t_is(g.gen(1, QMAX), scale*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0932 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0933 
0934 t = 'bus 2 loads (P) => Pd = 50 : ';
0935 e = mpc;
0936 g = apply_changes(49, mpc, chgtab);
0937 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0938 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0939 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
0940 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0941 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
0942 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0943 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0944 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0945 
0946 t = 'bus 2 disp loads (PQ) => Pd = 50 : ';
0947 scale = (load - mpc.bus(2, PD)) / -mpc.gen(1, PMIN);
0948 e = mpc;
0949 g = apply_changes(50, mpc, chgtab);
0950 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0951 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0952 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
0953 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0954 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
0955 t_is(g.gen(1, QMIN), scale*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0956 t_is(g.gen(1, QMAX), scale*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0957 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0958 
0959 t = 'bus 2 disp loads (P) => Pd = 50 : ';
0960 e = mpc;
0961 g = apply_changes(51, mpc, chgtab);
0962 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0963 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0964 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
0965 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0966 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
0967 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0968 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0969 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0970 
0971 t = 'bus 2 loads+cost (PQ) => Pd = 50 : ';
0972 scale = load / (mpc.bus(2, PD) - mpc.gen(1, PMIN));
0973 e = mpc;
0974 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_F');
0975 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_X');
0976 g = apply_changes(148, mpc, chgtab);
0977 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0978 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0979 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
0980 t_is(g.bus(2, QD), scale*mpc.bus(2, QD), 8, [t 'fixed Q']);
0981 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
0982 t_is(g.gen(1, QMIN), scale*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0983 t_is(g.gen(1, QMAX), scale*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0984 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0985 
0986 t = 'bus 2 loads+cost (P) => Pd = 50 : ';
0987 e = mpc;
0988 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_F');
0989 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_X');
0990 g = apply_changes(149, mpc, chgtab);
0991 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
0992 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
0993 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
0994 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
0995 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
0996 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
0997 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
0998 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
0999 
1000 t = 'bus 2 disp loads+cost (PQ) => Pd = 50 : ';
1001 scale = (load - mpc.bus(2, PD)) / -mpc.gen(1, PMIN);
1002 e = mpc;
1003 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_F');
1004 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_X');
1005 g = apply_changes(150, mpc, chgtab);
1006 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1007 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1008 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
1009 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
1010 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
1011 t_is(g.gen(1, QMIN), scale*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1012 t_is(g.gen(1, QMAX), scale*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1013 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1014 
1015 t = 'bus 2 disp loads+cost (P) => Pd = 50 : ';
1016 e = mpc;
1017 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_F');
1018 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_X');
1019 g = apply_changes(151, mpc, chgtab);
1020 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1021 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1022 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
1023 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
1024 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
1025 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1026 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1027 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1028 
1029 %%-----  single bus, one shift quantity  -----
1030 load = 10 + (mpc.bus(2, PD) - mpc.gen(1, PMIN));
1031 t = 'bus 2 fixed loads (PQ) => total + 25 : ';
1032 scale = (load+mpc.gen(1, PMIN)) / mpc.bus(2, PD);
1033 e = mpc;
1034 g = apply_changes(52, mpc, chgtab);
1035 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1036 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1037 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
1038 t_is(g.bus(2, QD), scale*mpc.bus(2, QD), 8, [t 'fixed Q']);
1039 t_is(g.gen(1, PMIN), mpc.gen(1, PMIN), 8, [t 'disp P']);
1040 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1041 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1042 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1043 
1044 t = 'bus 2 fixed loads (P) => total + 25 : ';
1045 e = mpc;
1046 g = apply_changes(53, mpc, chgtab);
1047 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1048 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1049 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
1050 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
1051 t_is(g.gen(1, PMIN), mpc.gen(1, PMIN), 8, [t 'disp P']);
1052 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1053 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1054 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1055 
1056 t = 'bus 2 loads (PQ) => total + 25 : ';
1057 scale = load / (mpc.bus(2, PD) - mpc.gen(1, PMIN));
1058 e = mpc;
1059 g = apply_changes(54, mpc, chgtab);
1060 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1061 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1062 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
1063 t_is(g.bus(2, QD), scale*mpc.bus(2, QD), 8, [t 'fixed Q']);
1064 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
1065 t_is(g.gen(1, QMIN), scale*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1066 t_is(g.gen(1, QMAX), scale*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1067 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1068 
1069 t = 'bus 2 loads (P) => total + 25 : ';
1070 e = mpc;
1071 g = apply_changes(55, mpc, chgtab);
1072 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1073 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1074 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
1075 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
1076 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
1077 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1078 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1079 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1080 
1081 t = 'bus 2 disp loads (PQ) => total + 25 : ';
1082 scale = (load - mpc.bus(2, PD)) / -mpc.gen(1, PMIN);
1083 e = mpc;
1084 g = apply_changes(56, mpc, chgtab);
1085 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1086 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1087 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
1088 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
1089 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
1090 t_is(g.gen(1, QMIN), scale*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1091 t_is(g.gen(1, QMAX), scale*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1092 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1093 
1094 t = 'bus 2 disp loads (P) => total + 25 : ';
1095 e = mpc;
1096 g = apply_changes(57, mpc, chgtab);
1097 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1098 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1099 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
1100 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
1101 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
1102 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1103 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1104 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1105 
1106 t = 'bus 2 loads+cost (PQ) => total + 25 : ';
1107 scale = load / (mpc.bus(2, PD) - mpc.gen(1, PMIN));
1108 e = mpc;
1109 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_F');
1110 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_X');
1111 g = apply_changes(154, mpc, chgtab);
1112 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1113 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1114 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
1115 t_is(g.bus(2, QD), scale*mpc.bus(2, QD), 8, [t 'fixed Q']);
1116 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
1117 t_is(g.gen(1, QMIN), scale*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1118 t_is(g.gen(1, QMAX), scale*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1119 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1120 
1121 t = 'bus 2 loads+cost (P) => total + 25 : ';
1122 e = mpc;
1123 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_F');
1124 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_X');
1125 g = apply_changes(155, mpc, chgtab);
1126 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1127 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1128 t_is(g.bus(2, PD), scale*mpc.bus(2, PD), 8, [t 'fixed P']);
1129 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
1130 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
1131 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1132 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1133 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1134 
1135 t = 'bus 2 disp loads+cost (PQ) => total + 25 : ';
1136 scale = (load - mpc.bus(2, PD)) / -mpc.gen(1, PMIN);
1137 e = mpc;
1138 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_F');
1139 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_X');
1140 g = apply_changes(156, mpc, chgtab);
1141 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1142 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1143 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
1144 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
1145 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
1146 t_is(g.gen(1, QMIN), scale*mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1147 t_is(g.gen(1, QMAX), scale*mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1148 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1149 
1150 t = 'bus 2 disp loads+cost (P) => total + 25 : ';
1151 e = mpc;
1152 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_F');
1153 e.gencost(1, :) = modcost(e.gencost(1, :), scale, 'SCALE_X');
1154 g = apply_changes(157, mpc, chgtab);
1155 t_is(g.bus(idx1, :), mpc.bus(idx1, :), 12, [t 'bus']);
1156 t_is(g.gen(idx2, :), mpc.gen(idx2, :), 12, [t 'gen']);
1157 t_is(g.bus(2, PD), mpc.bus(2, PD), 8, [t 'fixed P']);
1158 t_is(g.bus(2, QD), mpc.bus(2, QD), 8, [t 'fixed Q']);
1159 t_is(g.gen(1, PMIN), scale*mpc.gen(1, PMIN), 8, [t 'disp P']);
1160 t_is(g.gen(1, QMIN), mpc.gen(1, QMIN), 8, [t 'disp Qmin']);
1161 t_is(g.gen(1, QMAX), mpc.gen(1, QMAX), 8, [t 'disp Qmax']);
1162 t_is(g.gencost(ld, :), e.gencost(ld, :), 8, [t 'disp gencost']);
1163 
1164 %%-----  1 zone, area scale factor  -----
1165 t = 'area fixed loads (PQ) * [3 1 1] : ';
1166 load = [3 1 1];
1167 e = mpc;
1168 g = apply_changes(60, mpc, chgtab);
1169 for k = 1:length(load)
1170     if k > 1
1171         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1172         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1173     else
1174         t_is(sum(g.bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1175         t_is(sum(g.bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1176         t_is(-sum(g.gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1177         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1178         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1179     end
1180 end
1181 
1182 t = 'area fixed loads (P) * [3 1 1] : ';
1183 e = mpc;
1184 g = apply_changes(61, mpc, chgtab);
1185 for k = 1:length(load)
1186     if k > 1
1187         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1188         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1189     else
1190         t_is(sum(g.bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1191         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1192         t_is(-sum(g.gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1193         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1194         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1195     end
1196 end
1197 
1198 t = 'all area loads (PQ) * [3 1 1] : ';
1199 e = mpc;
1200 g = apply_changes(62, mpc, chgtab);
1201 for k = 1:length(load)
1202     if k > 1
1203         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1204         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1205     else
1206         t_is(sum(g.bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1207         t_is(sum(g.bus(a{k}, QD)), load(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1208         t_is(-sum(g.gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1209         t_is(-sum(g.gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1210         t_is(-sum(g.gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1211     end
1212 end
1213 
1214 t = 'all area loads (P) * [3 1 1] : ';
1215 e = mpc;
1216 g = apply_changes(63, mpc, chgtab);
1217 for k = 1:length(load)
1218     if k > 1
1219         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1220         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1221     else
1222         t_is(sum(g.bus(a{k}, PD)), load(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1223         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1224         t_is(-sum(g.gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1225         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1226         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1227     end
1228 end
1229 
1230 t = 'area disp loads (PQ) * [3 1 1] : ';
1231 e = mpc;
1232 g = apply_changes(64, mpc, chgtab);
1233 for k = 1:length(load)
1234     if k > 1
1235         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1236         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1237     else
1238         t_is(sum(g.bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1239         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1240         t_is(-sum(g.gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1241         t_is(-sum(g.gen(lda{k}, QMIN)), load(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1242         t_is(-sum(g.gen(lda{k}, QMAX)), load(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1243     end
1244 end
1245 
1246 t = 'area disp loads (P) * [3 1 1] : ';
1247 e = mpc;
1248 g = apply_changes(65, mpc, chgtab);
1249 for k = 1:length(load)
1250     if k > 1
1251         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1252         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1253     else
1254         t_is(sum(g.bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1255         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1256         t_is(-sum(g.gen(lda{k}, PMIN)), load(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1257         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1258         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1259     end
1260 end
1261 
1262 %%-----  1 zones, area target quantity  -----
1263 t = 'area fixed loads (PQ) => total = 100 : ';
1264 load = 100;
1265 e = mpc;
1266 g = apply_changes(66, mpc, chgtab);
1267 scale = [(load-area(1).disp.p) / area(1).fixed.p 1 1];
1268 for k = 1:length(load)
1269     if k > 1
1270         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1271         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1272     else
1273         t_is(sum(g.bus(a{k}, PD)), scale(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1274         t_is(sum(g.bus(a{k}, QD)), scale(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1275         t_is(-sum(g.gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1276         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1277         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1278     end
1279 end
1280 
1281 t = 'area fixed loads (P) => total = 100 : ';
1282 e = mpc;
1283 g = apply_changes(67, mpc, chgtab);
1284 for k = 1:length(load)
1285     if k > 1
1286         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1287         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1288     else
1289         t_is(sum(g.bus(a{k}, PD)), scale(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1290         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1291         t_is(-sum(g.gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1292         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1293         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1294     end
1295 end
1296 
1297 t = 'all area loads (PQ) => total = 100 : ';
1298 e = mpc;
1299 g = apply_changes(68, mpc, chgtab);
1300 scale = [load / (area(1).fixed.p + area(1).disp.p) 1 1];
1301 for k = 1:length(load)
1302     if k > 1
1303         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1304         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1305     else
1306         t_is(sum(g.bus(a{k}, PD)), scale(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1307         t_is(sum(g.bus(a{k}, QD)), scale(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1308         t_is(-sum(g.gen(lda{k}, PMIN)), scale(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1309         t_is(-sum(g.gen(lda{k}, QMIN)), scale(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1310         t_is(-sum(g.gen(lda{k}, QMAX)), scale(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1311     end
1312 end
1313 
1314 t = 'all area loads (P) => total = 100 : ';
1315 e = mpc;
1316 g = apply_changes(69, mpc, chgtab);
1317 for k = 1:length(load)
1318     if k > 1
1319         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1320         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1321     else
1322         t_is(sum(g.bus(a{k}, PD)), scale(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1323         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1324         t_is(-sum(g.gen(lda{k}, PMIN)), scale(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1325         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1326         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1327     end
1328 end
1329 
1330 t = 'area disp loads (PQ) => total = 100 : ';
1331 e = mpc;
1332 g = apply_changes(70, mpc, chgtab);
1333 scale = [(load - area(1).fixed.p) / area(1).disp.p 1 1];
1334 for k = 1:length(load)
1335     if k > 1
1336         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1337         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1338     else
1339         t_is(sum(g.bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1340         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1341         t_is(-sum(g.gen(lda{k}, PMIN)), scale(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1342         t_is(-sum(g.gen(lda{k}, QMIN)), scale(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1343         t_is(-sum(g.gen(lda{k}, QMAX)), scale(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1344     end
1345 end
1346 
1347 t = 'area disp loads (P) => total = 100 : ';
1348 e = mpc;
1349 g = apply_changes(71, mpc, chgtab);
1350 for k = 1:length(load)
1351     if k > 1
1352         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1353         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1354     else
1355         t_is(sum(g.bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1356         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1357         t_is(-sum(g.gen(lda{k}, PMIN)), scale(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1358         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1359         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1360     end
1361 end
1362 
1363 %%-----  1 zones, area shift quantity  -----
1364 t = 'area fixed loads (PQ) => total = total + 20 : ';
1365 load = area(1).both.p + 20;
1366 e = mpc;
1367 g = apply_changes(72, mpc, chgtab);
1368 scale = [(load-area(1).disp.p) / area(1).fixed.p 1 1];
1369 for k = 1:length(load)
1370     if k > 1
1371         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1372         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1373     else
1374         t_is(sum(g.bus(a{k}, PD)), scale(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1375         t_is(sum(g.bus(a{k}, QD)), scale(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1376         t_is(-sum(g.gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1377         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1378         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1379     end
1380 end
1381 
1382 t = 'area fixed loads (P) => total + 20 : ';
1383 e = mpc;
1384 g = apply_changes(73, mpc, chgtab);
1385 for k = 1:length(load)
1386     if k > 1
1387         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1388         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1389     else
1390         t_is(sum(g.bus(a{k}, PD)), scale(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1391         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1392         t_is(-sum(g.gen(lda{k}, PMIN)), area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1393         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1394         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1395     end
1396 end
1397 
1398 t = 'all area loads (PQ) => total + 20 : ';
1399 e = mpc;
1400 g = apply_changes(74, mpc, chgtab);
1401 scale = [load / (area(1).fixed.p + area(1).disp.p) 1 1];
1402 for k = 1:length(load)
1403     if k > 1
1404         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1405         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1406     else
1407         t_is(sum(g.bus(a{k}, PD)), scale(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1408         t_is(sum(g.bus(a{k}, QD)), scale(k)*area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1409         t_is(-sum(g.gen(lda{k}, PMIN)), scale(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1410         t_is(-sum(g.gen(lda{k}, QMIN)), scale(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1411         t_is(-sum(g.gen(lda{k}, QMAX)), scale(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1412     end
1413 end
1414 
1415 t = 'all area loads (P) => total + 20 : ';
1416 e = mpc;
1417 g = apply_changes(75, mpc, chgtab);
1418 for k = 1:length(load)
1419     if k > 1
1420         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1421         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1422     else
1423         t_is(sum(g.bus(a{k}, PD)), scale(k)*area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1424         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1425         t_is(-sum(g.gen(lda{k}, PMIN)), scale(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1426         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1427         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1428     end
1429 end
1430 
1431 t = 'area disp loads (PQ) => total + 20 : ';
1432 e = mpc;
1433 g = apply_changes(76, mpc, chgtab);
1434 scale = [(load - area(1).fixed.p) / area(1).disp.p 1 1];
1435 for k = 1:length(load)
1436     if k > 1
1437         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1438         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1439     else
1440         t_is(sum(g.bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1441         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1442         t_is(-sum(g.gen(lda{k}, PMIN)), scale(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1443         t_is(-sum(g.gen(lda{k}, QMIN)), scale(k)*area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1444         t_is(-sum(g.gen(lda{k}, QMAX)), scale(k)*area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1445     end
1446 end
1447 
1448 t = 'area disp loads (P) => total + 20 : ';
1449 e = mpc;
1450 g = apply_changes(77, mpc, chgtab);
1451 for k = 1:length(load)
1452     if k > 1
1453         t_is(g.bus(a{k}, :), mpc.bus(a{k}, :), 12, sprintf('%s area %d bus', t, k));
1454         t_is(g.gen(ga{k}, :), mpc.gen(ga{k}, :), 12, sprintf('%s area %d gen', t, k));
1455     else
1456         t_is(sum(g.bus(a{k}, PD)), area(k).fixed.p, 8, sprintf('%s area %d fixed P', t, k));
1457         t_is(sum(g.bus(a{k}, QD)), area(k).fixed.q, 8, sprintf('%s area %d fixed Q', t, k));
1458         t_is(-sum(g.gen(lda{k}, PMIN)), scale(k)*area(k).disp.p, 8, sprintf('%s area %d disp P', t, k));
1459         t_is(-sum(g.gen(lda{k}, QMIN)), area(k).disp.qmin, 8, sprintf('%s area %d disp Qmin', t, k));
1460         t_is(-sum(g.gen(lda{k}, QMAX)), area(k).disp.qmax, 8, sprintf('%s area %d disp Qmax', t, k));
1461     end
1462 end
1463 
1464 t_end;

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005