Home > matpower6.0 > t > t_ext2int2ext.m

t_ext2int2ext

PURPOSE ^

T_EXT2INT2EXT Tests EXT2INT, INT2EXT, and related functions.

SYNOPSIS ^

function t_ext2int2ext(quiet)

DESCRIPTION ^

T_EXT2INT2EXT  Tests EXT2INT, INT2EXT, and related functions.
   Includes tests for GET_REORDER, SET_REORDER, E2I_DATA, I2E_DATA
   E2I_FIELD, I2E_FIELD, EXT2INT and INT2EXT.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_ext2int2ext(quiet)
0002 %T_EXT2INT2EXT  Tests EXT2INT, INT2EXT, and related functions.
0003 %   Includes tests for GET_REORDER, SET_REORDER, E2I_DATA, I2E_DATA
0004 %   E2I_FIELD, I2E_FIELD, EXT2INT and INT2EXT.
0005 
0006 %   MATPOWER
0007 %   Copyright (c) 2009-2016, Power Systems Engineering Research Center (PSERC)
0008 %   by Ray Zimmerman, PSERC Cornell
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 num_tests = 122;
0019 t_begin(num_tests, quiet);
0020 
0021 if have_fcn('matlab', 'vnum') < 7.001
0022     t_skip(num_tests, 'test requires cellfun() construct not available before Matlab 7.1');
0023 else
0024     mpce = loadcase('t_case_ext');
0025     mpci = loadcase('t_case_int');
0026 
0027     An = mpce.xbus;
0028     As = mpce.strbus;
0029 
0030     %%-----  get_reorder  -----
0031     k = [3; 7; 4; 1];
0032     t = 'get_reorder(A, k, 1) : numeric';
0033     t_is(get_reorder(An, k, 1), An(k, :), 12, t);
0034 
0035     t = 'get_reorder(A, k, 2) : numeric';
0036     t_is(get_reorder(An, k, 2), An(:, k), 12, t);
0037 
0038     %%-----  set_reorder  -----
0039     k = (2:2:10)';
0040     t = 'set_reorder(A, B, k, 1) : numeric';
0041     B = An(k, :) * -1;
0042     got = set_reorder(An, B, k, 1);
0043     ex = An;
0044     ex(k, :) = -ex(k, :);
0045     t_is(got, ex, 12, t);
0046 
0047     t = 'set_reorder(A, B, k, 2) : numeric';
0048     B = An(:, k) * -1;
0049     got = set_reorder(An, B, k, 2);
0050     ex = An;
0051     ex(:, k) = -ex(:, k);
0052     t_is(got, ex, 12, t);
0053 
0054     t = 'set_reorder(A, Bshort, k, 1) : numeric';
0055     k = (2:2:8)';
0056     B = An(k, 1:8) * -1;
0057     got = set_reorder(An, B, k, 1);
0058     ex = An;
0059     ex(k, 1:8) = -ex(k, 1:8);
0060     t_is(got, ex, 12, t);
0061 
0062     t = 'set_reorder(A, Bshort, k, 2) : numeric';
0063     B = An(1:8, k) * -1;
0064     got = set_reorder(An, B, k, 2);
0065     ex = An;
0066     ex(1:8, k) = -ex(1:8, k);
0067     t_is(got, ex, 12, t);
0068 
0069     t = 'set_reorder(A, Blong, k, 1) : numeric';
0070     k = (2:2:10)';
0071     B = An(k, :) * -1;
0072     B = [B B];
0073     got = set_reorder(An, B, k, 1);
0074     ex = [An zeros(size(An))];
0075     ex(k, :) = [-An(k, :) -An(k, :)];
0076     t_is(got, ex, 12, t);
0077 
0078     t = 'set_reorder(A, Blong, k, 2) : numeric';
0079     B = An(:, k) * -1;
0080     B = [B; B];
0081     got = set_reorder(An, B, k, 2);
0082     ex = [An; zeros(size(An))];
0083     ex(:, k) = [-An(:, k); -An(:, k)];
0084     t_is(got, ex, 12, t);
0085 
0086 
0087     %%-----  get_reorder (cell)  -----
0088     k = [3; 7; 4; 1];
0089     t = 'get_reorder(A, k, 1) : cell';
0090     t_is(cellfun(@str2num, get_reorder(As, k, 1)), cellfun(@str2num, As(k, :)), 12, t);
0091 
0092     t = 'get_reorder(A, k, 2) : cell';
0093     t_is(cellfun(@str2num, get_reorder(As, k, 2)), cellfun(@str2num, As(:, k)), 12, t);
0094 
0095     %%-----  set_reorder (cell)  -----
0096     k = (2:2:10)';
0097     t = 'set_reorder(A, B, k, 1) : cell';
0098     B = cellfun(@num2str, num2cell(An(k, :) * -1), 'UniformOutput', 0);
0099     got = set_reorder(As, B, k, 1);
0100     ex = As;
0101     ex(k, :) = cellfun(@num2str, num2cell(-cellfun(@str2num, ex(k, :))), 'UniformOutput', 0);
0102     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0103 
0104     t = 'set_reorder(A, B, k, 2) : cell';
0105     B = cellfun(@num2str, num2cell(An(:, k) * -1), 'UniformOutput', 0);
0106     got = set_reorder(As, B, k, 2);
0107     ex = As;
0108     ex(:, k) = cellfun(@num2str, num2cell(-cellfun(@str2num, ex(:, k))), 'UniformOutput', 0);
0109     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0110 
0111     t = 'set_reorder(A, Bshort, k, 1) : cell';
0112     k = (2:2:8)';
0113     B = cellfun(@num2str, num2cell(An(k, 1:8) * -1), 'UniformOutput', 0);
0114     got = set_reorder(As, B, k, 1);
0115     ex = As;
0116     ex(k, 1:8) = cellfun(@num2str, num2cell(-cellfun(@str2num, ex(k, 1:8))), 'UniformOutput', 0);
0117     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0118 
0119     t = 'set_reorder(A, Bshort, k, 2) : cell';
0120     B = cellfun(@num2str, num2cell(An(1:8, k) * -1), 'UniformOutput', 0);
0121     got = set_reorder(As, B, k, 2);
0122     ex = As;
0123     ex(1:8, k) = cellfun(@num2str, num2cell(-cellfun(@str2num, ex(1:8, k))), 'UniformOutput', 0);
0124     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0125 
0126     t = 'set_reorder(A, Blong, k, 1) : cell';
0127     k = (2:2:10)';
0128     B = cellfun(@num2str, num2cell(An(k, :) * -1), 'UniformOutput', 0);
0129     B = [B B];
0130     got = set_reorder(As, B, k, 1);
0131     ex = [As cell(size(As))];
0132     ex(k, :) = cellfun(@num2str, num2cell([-An(k, :) -An(k, :)]), 'UniformOutput', 0);
0133     for i = 1:size(got, 1)      %% replace [] with '-999' to make str2num happy
0134         for j = 1:size(got, 2)
0135             if isempty(got{i, j})
0136                 got{i, j} = '-999';
0137             end
0138             if isempty(ex{i, j})
0139                 ex{i, j} = '-999';
0140             end
0141         end
0142     end
0143     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0144 
0145     t = 'set_reorder(A, Blong, k, 2) : cell';
0146     B = cellfun(@num2str, num2cell(An(:, k) * -1), 'UniformOutput', 0);
0147     B = [B; B];
0148     got = set_reorder(As, B, k, 2);
0149     ex = [As; cell(size(As))];
0150     ex(:, k) = cellfun(@num2str, num2cell([-An(:, k); -An(:, k)]), 'UniformOutput', 0);
0151     for i = 1:size(got, 1)      %% replace [] with '-999' to make str2num happy
0152         for j = 1:size(got, 2)
0153             if isempty(got{i, j})
0154                 got{i, j} = '-999';
0155             end
0156             if isempty(ex{i, j})
0157                 ex{i, j} = '-999';
0158             end
0159         end
0160     end
0161     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0162 
0163     %%-----  mpc = ext2int/int2ext(mpc)  -----
0164     t = 'mpc = ext2int(mpc) : ';
0165     mpc = ext2int(mpce);
0166     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0167     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0168     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0169     t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0170     t_is(mpc.A, mpci.A, 12, [t 'A']);
0171     t_is(mpc.N, mpci.N, 12, [t 'N']);
0172     t = 'mpc = ext2int(mpc) - repeat : ';
0173     mpc = ext2int(mpc);
0174     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0175     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0176     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0177     t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0178     t_is(mpc.A, mpci.A, 12, [t 'A']);
0179     t_is(mpc.N, mpci.N, 12, [t 'N']);
0180     t = 'mpc = int2ext(mpc) : ';
0181     mpc = int2ext(mpc);
0182     t_is(mpc.bus, mpce.bus, 12, [t 'bus']);
0183     t_is(mpc.branch, mpce.branch, 12, [t 'branch']);
0184     t_is(mpc.gen, mpce.gen, 12, [t 'gen']);
0185     t_is(mpc.gencost, mpce.gencost, 12, [t 'gencost']);
0186     t_is(mpc.A, mpce.A, 12, [t 'A']);
0187     t_is(mpc.N, mpce.N, 12, [t 'N']);
0188 
0189     %%-----  val = e2i_data/i2e_data(mpc, val, ...)  -----
0190     t = 'val = e2i_data(mpc, val, ''bus'')';
0191     mpc = ext2int(mpce);
0192     got = e2i_data(mpc, mpce.xbus, 'bus');
0193     ex = mpce.xbus;
0194     ex(6, :) = [];
0195     t_is(got, ex, 12, t);
0196     t = 'val = i2e_data(mpc, val, oldval, ''bus'')';
0197     tmp = ones(size(mpce.xbus));
0198     tmp(6, :) = mpce.xbus(6, :);
0199     got = i2e_data(mpc, ex, tmp, 'bus');
0200     t_is(got, mpce.xbus, 12, t);
0201 
0202     t = 'val = e2i_data(mpc, val, ''bus'', 2)';
0203     got = e2i_data(mpc, mpce.xbus, 'bus', 2);
0204     ex = mpce.xbus;
0205     ex(:, 6) = [];
0206     t_is(got, ex, 12, t);
0207     t = 'val = i2e_data(mpc, val, oldval, ''bus'', 2)';
0208     tmp = ones(size(mpce.xbus));
0209     tmp(:, 6) = mpce.xbus(:, 6);
0210     got = i2e_data(mpc, ex, tmp, 'bus', 2);
0211     t_is(got, mpce.xbus, 12, t);
0212 
0213     t = 'val = e2i_data(mpc, val, ''gen'')';
0214     got = e2i_data(mpc, mpce.xgen, 'gen');
0215     ex = mpce.xgen([4 2 1], :);
0216     t_is(got, ex, 12, t);
0217     t = 'val = i2e_data(mpc, val, oldval, ''gen'')';
0218     tmp = ones(size(mpce.xgen));
0219     tmp(3, :) = mpce.xgen(3, :);
0220     got = i2e_data(mpc, ex, tmp, 'gen');
0221     t_is(got, mpce.xgen, 12, t);
0222 
0223     t = 'val = e2i_data(mpc, val, ''gen'', 2)';
0224     got = e2i_data(mpc, mpce.xgen, 'gen', 2);
0225     ex = mpce.xgen(:, [4 2 1]);
0226     t_is(got, ex, 12, t);
0227     t = 'val = i2e_data(mpc, val, oldval, ''gen'', 2)';
0228     tmp = ones(size(mpce.xgen));
0229     tmp(:, 3) = mpce.xgen(:, 3);
0230     got = i2e_data(mpc, ex, tmp, 'gen', 2);
0231     t_is(got, mpce.xgen, 12, t);
0232 
0233     t = 'val = e2i_data(mpc, val, ''branch'')';
0234     got = e2i_data(mpc, mpce.xbranch, 'branch');
0235     ex = mpce.xbranch;
0236     ex(7, :) = [];
0237     t_is(got, ex, 12, t);
0238     t = 'val = i2e_data(mpc, val, oldval, ''branch'')';
0239     tmp = ones(size(mpce.xbranch));
0240     tmp(7, :) = mpce.xbranch(7, :);
0241     got = i2e_data(mpc, ex, tmp, 'branch');
0242     t_is(got, mpce.xbranch, 12, t);
0243 
0244     t = 'val = e2i_data(mpc, val, ''branch'', 2)';
0245     got = e2i_data(mpc, mpce.xbranch, 'branch', 2);
0246     ex = mpce.xbranch;
0247     ex(:, 7) = [];
0248     t_is(got, ex, 12, t);
0249     t = 'val = i2e_data(mpc, val, oldval, ''branch'', 2)';
0250     tmp = ones(size(mpce.xbranch));
0251     tmp(:, 7) = mpce.xbranch(:, 7);
0252     got = i2e_data(mpc, ex, tmp, 'branch', 2);
0253     t_is(got, mpce.xbranch, 12, t);
0254 
0255     t = 'val = e2i_data(mpc, val, {''branch'', ''gen'', ''bus''})';
0256     got = e2i_data(mpc, mpce.xrows, {'branch', 'gen', 'bus'});
0257     ex = [mpce.xbranch([1:6, 8:10], 1:4); mpce.xgen([4 2 1], :); mpce.xbus([1:5, 7:10], 1:4); -ones(2, 4)];
0258     t_is(got, ex, 12, t);
0259     t = 'val = i2e_data(mpc, val, oldval, {''branch'', ''gen'', ''bus''})';
0260     tmp1 = ones(size(mpce.xbranch(:, 1:4)));
0261     tmp1(7, 1:4) = mpce.xbranch(7, 1:4);
0262     tmp2 = ones(size(mpce.xgen));
0263     tmp2(3, :) = mpce.xgen(3, :);
0264     tmp3 = ones(size(mpce.xbus(:, 1:4)));
0265     tmp3(6, 1:4) = mpce.xbus(6, 1:4);
0266     tmp = [tmp1; tmp2; tmp3];
0267     got = i2e_data(mpc, ex, tmp, {'branch', 'gen', 'bus'});
0268     t_is(got, mpce.xrows, 12, t);
0269 
0270     t = 'val = e2i_data(mpc, val, {''branch'', ''gen'', ''bus''}, 2)';
0271     got = e2i_data(mpc, mpce.xcols, {'branch', 'gen', 'bus'}, 2);
0272     ex = [mpce.xbranch([1:6, 8:10], 1:4); mpce.xgen([4 2 1], :); mpce.xbus([1:5, 7:10], 1:4); -ones(2, 4)]';
0273     t_is(got, ex, 12, t);
0274     t = 'val = i2e_data(mpc, val, oldval, {''branch'', ''gen'', ''bus''}, 2)';
0275     tmp1 = ones(size(mpce.xbranch(:, 1:4)));
0276     tmp1(7, 1:4) = mpce.xbranch(7, 1:4);
0277     tmp2 = ones(size(mpce.xgen));
0278     tmp2(3, :) = mpce.xgen(3, :);
0279     tmp3 = ones(size(mpce.xbus(:, 1:4)));
0280     tmp3(6, 1:4) = mpce.xbus(6, 1:4);
0281     tmp = [tmp1; tmp2; tmp3]';
0282     got = i2e_data(mpc, ex, tmp, {'branch', 'gen', 'bus'}, 2);
0283     t_is(got, mpce.xcols, 12, t);
0284 
0285     %%-----  val = e2i_data/i2e_data(mpc, cell, ...)  -----
0286     t = 'val = e2i_data(mpc, cell, ''bus'')';
0287     mpc = ext2int(mpce);
0288     got = e2i_data(mpc, mpce.strbus, 'bus');
0289     ex = mpce.strbus;
0290     ex(6, :) = [];
0291     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0292     t = 'val = i2e_data(mpc, cell, oldval, ''bus'')';
0293     tmp = cell(size(mpce.strbus));
0294     tmp(6, :) = mpce.strbus(6, :);
0295     got = i2e_data(mpc, ex, tmp, 'bus');
0296     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strbus), 12, t);
0297 
0298     t = 'val = e2i_data(mpc, cell, ''bus'', 2)';
0299     got = e2i_data(mpc, mpce.strbus, 'bus', 2);
0300     ex = mpce.strbus;
0301     ex(:, 6) = [];
0302     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0303     t = 'val = i2e_data(mpc, cell, oldval, ''bus'', 2)';
0304     tmp = cell(size(mpce.strbus));
0305     tmp(:, 6) = mpce.strbus(:, 6);
0306     got = i2e_data(mpc, ex, tmp, 'bus', 2);
0307     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strbus), 12, t);
0308 
0309     t = 'val = e2i_data(mpc, cell, ''gen'')';
0310     got = e2i_data(mpc, mpce.strgen, 'gen');
0311     ex = mpce.strgen([4 2 1], :);
0312     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0313     t = 'val = i2e_data(mpc, cell, oldval, ''gen'')';
0314     tmp = cell(size(mpce.strgen));
0315     tmp(3, :) = mpce.strgen(3, :);
0316     got = i2e_data(mpc, ex, tmp, 'gen');
0317     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strgen), 12, t);
0318 
0319     t = 'val = e2i_data(mpc, cell, ''gen'', 2)';
0320     got = e2i_data(mpc, mpce.strgen, 'gen', 2);
0321     ex = mpce.strgen(:, [4 2 1]);
0322     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0323     t = 'val = i2e_data(mpc, cell, oldval, ''gen'', 2)';
0324     tmp = cell(size(mpce.strgen));
0325     tmp(:, 3) = mpce.strgen(:, 3);
0326     got = i2e_data(mpc, ex, tmp, 'gen', 2);
0327     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strgen), 12, t);
0328 
0329     t = 'val = e2i_data(mpc, cell, ''branch'')';
0330     got = e2i_data(mpc, mpce.strbranch, 'branch');
0331     ex = mpce.strbranch;
0332     ex(7, :) = [];
0333     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0334     t = 'val = i2e_data(mpc, cell, oldval, ''branch'')';
0335     tmp = cell(size(mpce.strbranch));
0336     tmp(7, :) = mpce.strbranch(7, :);
0337     got = i2e_data(mpc, ex, tmp, 'branch');
0338     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strbranch), 12, t);
0339 
0340     t = 'val = e2i_data(mpc, cell, ''branch'', 2)';
0341     got = e2i_data(mpc, mpce.strbranch, 'branch', 2);
0342     ex = mpce.strbranch;
0343     ex(:, 7) = [];
0344     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0345     t = 'val = i2e_data(mpc, cell, oldval, ''branch'', 2)';
0346     tmp = cell(size(mpce.strbranch));
0347     tmp(:, 7) = mpce.strbranch(:, 7);
0348     got = i2e_data(mpc, ex, tmp, 'branch', 2);
0349     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strbranch), 12, t);
0350 
0351     t = 'val = e2i_data(mpc, cell, {''branch'', ''gen'', ''bus''})';
0352     got = e2i_data(mpc, mpce.strrows, {'branch', 'gen', 'bus'});
0353     ex = [mpce.strbranch([1:6, 8:10], 1:4); mpce.strgen([4 2 1], :); mpce.strbus([1:5, 7:10], 1:4); cellfun(@num2str, num2cell(-ones(2, 4)), 'UniformOutput', 0)];
0354     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0355     t = 'val = i2e_data(mpc, cell, oldval, {''branch'', ''gen'', ''bus''})';
0356     tmp1 = cell(size(mpce.strbranch(:, 1:4)));
0357     tmp1(7, 1:4) = mpce.strbranch(7, 1:4);
0358     tmp2 = cell(size(mpce.strgen));
0359     tmp2(3, :) = mpce.strgen(3, :);
0360     tmp3 = cell(size(mpce.strbus(:, 1:4)));
0361     tmp3(6, 1:4) = mpce.strbus(6, 1:4);
0362     tmp = [tmp1; tmp2; tmp3];
0363     got = i2e_data(mpc, ex, tmp, {'branch', 'gen', 'bus'});
0364     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strrows), 12, t);
0365 
0366     t = 'val = e2i_data(mpc, cell, {''branch'', ''gen'', ''bus''}, 2)';
0367     got = e2i_data(mpc, mpce.strcols, {'branch', 'gen', 'bus'}, 2);
0368     ex = [mpce.strbranch([1:6, 8:10], 1:4); mpce.strgen([4 2 1], :); mpce.strbus([1:5, 7:10], 1:4); cellfun(@num2str, num2cell(-ones(2, 4)), 'UniformOutput', 0)]';
0369     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0370     t = 'val = i2e_data(mpc, cell, oldval, {''branch'', ''gen'', ''bus''}, 2)';
0371     tmp1 = cell(size(mpce.strbranch(:, 1:4)));
0372     tmp1(7, 1:4) = mpce.strbranch(7, 1:4);
0373     tmp2 = cell(size(mpce.strgen));
0374     tmp2(3, :) = mpce.strgen(3, :);
0375     tmp3 = cell(size(mpce.strbus(:, 1:4)));
0376     tmp3(6, 1:4) = mpce.strbus(6, 1:4);
0377     tmp = [tmp1; tmp2; tmp3]';
0378     got = i2e_data(mpc, ex, tmp, {'branch', 'gen', 'bus'}, 2);
0379     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strcols), 12, t);
0380 
0381     %%-----  mpc = e2i_field/i2e_field(mpc, field, ...)  -----
0382     t = 'mpc = e2i_field(mpc, field, ''bus'')';
0383     mpc = ext2int(mpce);
0384     ex = mpce.xbus;
0385     ex(6, :) = [];
0386     got = e2i_field(mpc, 'xbus', 'bus');
0387     t_is(got.xbus, ex, 12, t);
0388     t = 'mpc = i2e_field(mpc, field, ''bus'')';
0389     got = i2e_field(got, 'xbus', 'bus');
0390     t_is(got.xbus, mpce.xbus, 12, t);
0391 
0392     t = 'mpc = e2i_field(mpc, field, ''bus'', 2)';
0393     ex = mpce.xbus;
0394     ex(:, 6) = [];
0395     got = e2i_field(mpc, 'xbus', 'bus', 2);
0396     t_is(got.xbus, ex, 12, t);
0397     t = 'mpc = i2e_field(mpc, field, ''bus'', 2)';
0398     got = i2e_field(got, 'xbus', 'bus', 2);
0399     t_is(got.xbus, mpce.xbus, 12, t);
0400 
0401     t = 'mpc = e2i_field(mpc, field, ''gen'')';
0402     ex = mpce.xgen([4 2 1], :);
0403     got = e2i_field(mpc, 'xgen', 'gen');
0404     t_is(got.xgen, ex, 12, t);
0405     t = 'mpc = i2e_field(mpc, field, ''gen'')';
0406     got = i2e_field(got, 'xgen', 'gen');
0407     t_is(got.xgen, mpce.xgen, 12, t);
0408 
0409     t = 'mpc = e2i_field(mpc, field, ''gen'', 2)';
0410     ex = mpce.xgen(:, [4 2 1]);
0411     got = e2i_field(mpc, 'xgen', 'gen', 2);
0412     t_is(got.xgen, ex, 12, t);
0413     t = 'mpc = i2e_field(mpc, field, ''gen'', 2)';
0414     got = i2e_field(got, 'xgen', 'gen', 2);
0415     t_is(got.xgen, mpce.xgen, 12, t);
0416 
0417     t = 'mpc = e2i_field(mpc, field, ''branch'')';
0418     ex = mpce.xbranch;
0419     ex(7, :) = [];
0420     got = e2i_field(mpc, 'xbranch', 'branch');
0421     t_is(got.xbranch, ex, 12, t);
0422     t = 'mpc = i2e_field(mpc, field, ''branch'')';
0423     got = i2e_field(got, 'xbranch', 'branch');
0424     t_is(got.xbranch, mpce.xbranch, 12, t);
0425 
0426     t = 'mpc = e2i_field(mpc, field, ''branch'', 2)';
0427     ex = mpce.xbranch;
0428     ex(:, 7) = [];
0429     got = e2i_field(mpc, 'xbranch', 'branch', 2);
0430     t_is(got.xbranch, ex, 12, t);
0431     t = 'mpc = i2e_field(mpc, field, ''branch'', 2)';
0432     got = i2e_field(got, 'xbranch', 'branch', 2);
0433     t_is(got.xbranch, mpce.xbranch, 12, t);
0434 
0435     t = 'mpc = e2i_field(mpc, field, {''branch'', ''gen'', ''bus''})';
0436     ex = [mpce.xbranch([1:6, 8:10], 1:4); mpce.xgen([4 2 1], :); mpce.xbus([1:5, 7:10], 1:4); -ones(2, 4)];
0437     got = e2i_field(mpc, 'xrows', {'branch', 'gen', 'bus'});
0438     t_is(got.xrows, ex, 12, t);
0439     t = 'mpc = i2e_field(mpc, field, {''branch'', ''gen'', ''bus''})';
0440     got = i2e_field(got, 'xrows', {'branch', 'gen', 'bus'});
0441     t_is(got.xrows, mpce.xrows, 12, t);
0442 
0443     t = 'mpc = e2i_field(mpc, field, {''branch'', ''gen'', ''bus''}, 2)';
0444     ex = [mpce.xbranch([1:6, 8:10], 1:4); mpce.xgen([4 2 1], :); mpce.xbus([1:5, 7:10], 1:4); -ones(2, 4)]';
0445     got = e2i_field(mpc, 'xcols', {'branch', 'gen', 'bus'}, 2);
0446     t_is(got.xcols, ex, 12, t);
0447     t = 'mpc = i2e_field(mpc, field, {''branch'', ''gen'', ''bus''})';
0448     got = i2e_field(got, 'xcols', {'branch', 'gen', 'bus'}, 2);
0449     t_is(got.xcols, mpce.xcols, 12, t);
0450 
0451     t = 'mpc = e2i_field(mpc, {''field1'', ''field2''}, ordering)';
0452     ex = mpce.x.more([4 2 1], :);
0453     got = e2i_field(mpc, {'x', 'more'}, 'gen');
0454     t_is(got.x.more, ex, 12, t);
0455     t = 'mpc = i2e_field(mpc, {''field1'', ''field2''}, ordering)';
0456     got = i2e_field(got, {'x', 'more'}, 'gen');
0457     t_is(got.x.more, mpce.x.more, 12, t);
0458 
0459     t = 'mpc = e2i_field(mpc, {''field1'', ''field2''}, ordering, 2)';
0460     ex = mpce.x.more(:, [4 2 1]);
0461     got = e2i_field(mpc, {'x', 'more'}, 'gen', 2);
0462     t_is(got.x.more, ex, 12, t);
0463     t = 'mpc = i2e_field(mpc, {''field1'', ''field2''}, ordering, 2)';
0464     got = i2e_field(got, {'x', 'more'}, 'gen', 2);
0465     t_is(got.x.more, mpce.x.more, 12, t);
0466 
0467     %%-----  mpc = e2i_field/i2e_field(mpc, cellfield, ...)  -----
0468     t = 'mpc = e2i_field(mpc, cellfield, ''bus'')';
0469     mpc = ext2int(mpce);
0470     ex = mpce.strbus;
0471     ex(6, :) = [];
0472     got = e2i_field(mpc, 'strbus', 'bus');
0473     t_is(cellfun(@str2num, got.strbus), cellfun(@str2num, ex), 12, t);
0474     t = 'mpc = i2e_field(mpc, cellfield, ''bus'')';
0475     got = i2e_field(got, 'strbus', 'bus');
0476     t_is(cellfun(@str2num, got.strbus), cellfun(@str2num, mpce.strbus), 12, t);
0477 
0478     t = 'mpc = e2i_field(mpc, cellfield, ''bus'', 2)';
0479     ex = mpce.strbus;
0480     ex(:, 6) = [];
0481     got = e2i_field(mpc, 'strbus', 'bus', 2);
0482     t_is(cellfun(@str2num, got.strbus), cellfun(@str2num, ex), 12, t);
0483     t = 'mpc = i2e_field(mpc, cellfield, ''bus'', 2)';
0484     got = i2e_field(got, 'strbus', 'bus', 2);
0485     t_is(cellfun(@str2num, got.strbus), cellfun(@str2num, mpce.strbus), 12, t);
0486 
0487     t = 'mpc = e2i_field(mpc, cellfield, ''gen'')';
0488     ex = mpce.strgen([4 2 1], :);
0489     got = e2i_field(mpc, 'strgen', 'gen');
0490     t_is(cellfun(@str2num, got.strgen), cellfun(@str2num, ex), 12, t);
0491     t = 'mpc = i2e_field(mpc, cellfield, ''gen'')';
0492     got = i2e_field(got, 'strgen', 'gen');
0493     t_is(cellfun(@str2num, got.strgen), cellfun(@str2num, mpce.strgen), 12, t);
0494 
0495     t = 'mpc = e2i_field(mpc, cellfield, ''gen'', 2)';
0496     ex = mpce.strgen(:, [4 2 1]);
0497     got = e2i_field(mpc, 'strgen', 'gen', 2);
0498     t_is(cellfun(@str2num, got.strgen), cellfun(@str2num, ex), 12, t);
0499     t = 'mpc = i2e_field(mpc, cellfield, ''gen'', 2)';
0500     got = i2e_field(got, 'strgen', 'gen', 2);
0501     t_is(cellfun(@str2num, got.strgen), cellfun(@str2num, mpce.strgen), 12, t);
0502 
0503     t = 'mpc = e2i_field(mpc, cellfield, ''branch'')';
0504     ex = mpce.strbranch;
0505     ex(7, :) = [];
0506     got = e2i_field(mpc, 'strbranch', 'branch');
0507     t_is(cellfun(@str2num, got.strbranch), cellfun(@str2num, ex), 12, t);
0508     t = 'mpc = i2e_field(mpc, cellfield, ''branch'')';
0509     got = i2e_field(got, 'strbranch', 'branch');
0510     t_is(cellfun(@str2num, got.strbranch), cellfun(@str2num, mpce.strbranch), 12, t);
0511 
0512     t = 'mpc = e2i_field(mpc, cellfield, ''branch'', 2)';
0513     ex = mpce.strbranch;
0514     ex(:, 7) = [];
0515     got = e2i_field(mpc, 'strbranch', 'branch', 2);
0516     t_is(cellfun(@str2num, got.strbranch), cellfun(@str2num, ex), 12, t);
0517     t = 'mpc = i2e_field(mpc, cellfield, ''branch'', 2)';
0518     got = i2e_field(got, 'strbranch', 'branch', 2);
0519     t_is(cellfun(@str2num, got.strbranch), cellfun(@str2num, mpce.strbranch), 12, t);
0520 
0521     t = 'mpc = e2i_field(mpc, cellfield, {''branch'', ''gen'', ''bus''})';
0522     ex = [mpce.strbranch([1:6, 8:10], 1:4); mpce.strgen([4 2 1], :); mpce.strbus([1:5, 7:10], 1:4); cellfun(@num2str, num2cell(-ones(2, 4)), 'UniformOutput', 0)];
0523     got = e2i_field(mpc, 'strrows', {'branch', 'gen', 'bus'});
0524     t_is(cellfun(@str2num, got.strrows), cellfun(@str2num, ex), 12, t);
0525     t = 'mpc = i2e_field(mpc, cellfield, {''branch'', ''gen'', ''bus''})';
0526     got = i2e_field(got, 'strrows', {'branch', 'gen', 'bus'});
0527     t_is(cellfun(@str2num, got.strrows), cellfun(@str2num, mpce.strrows), 12, t);
0528 
0529     t = 'mpc = e2i_field(mpc, cellfield, {''branch'', ''gen'', ''bus''}, 2)';
0530     ex = [mpce.strbranch([1:6, 8:10], 1:4); mpce.strgen([4 2 1], :); mpce.strbus([1:5, 7:10], 1:4); cellfun(@num2str, num2cell(-ones(2, 4)), 'UniformOutput', 0)]';
0531     got = e2i_field(mpc, 'strcols', {'branch', 'gen', 'bus'}, 2);
0532     t_is(cellfun(@str2num, got.strcols), cellfun(@str2num, ex), 12, t);
0533     t = 'mpc = i2e_field(mpc, cellfield, {''branch'', ''gen'', ''bus''})';
0534     got = i2e_field(got, 'strcols', {'branch', 'gen', 'bus'}, 2);
0535     t_is(cellfun(@str2num, got.strcols), cellfun(@str2num, mpce.strcols), 12, t);
0536 
0537     %%-----  more mpc = ext2int/int2ext(mpc)  -----
0538     t = 'mpc = ext2int(mpc) - bus/gen/branch only : ';
0539     mpce = loadcase('t_case_ext');
0540     mpci = loadcase('t_case_int');
0541     mpce = rmfield(mpce, 'gencost');
0542     mpce = rmfield(mpce, 'A');
0543     mpce = rmfield(mpce, 'N');
0544     mpci = rmfield(mpci, 'gencost');
0545     mpci = rmfield(mpci, 'A');
0546     mpci = rmfield(mpci, 'N');
0547     mpc = ext2int(mpce);
0548     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0549     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0550     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0551 
0552     t = 'mpc = ext2int(mpc) - Qg cost, no N : ';
0553     mpce = loadcase('t_case_ext');
0554     mpci = loadcase('t_case_int');
0555     mpce = rmfield(mpce, 'N');
0556     mpci = rmfield(mpci, 'N');
0557     mpce.gencost = [mpce.gencost; mpce.gencost];
0558     mpci.gencost = [mpci.gencost; mpci.gencost];
0559     mpc = ext2int(mpce);
0560     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0561     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0562     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0563     t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0564     t_is(mpc.A, mpci.A, 12, [t 'A']);
0565 
0566     t = 'mpc = ext2int(mpc) - A, N are DC sized : ';
0567     mpce = loadcase('t_case_ext');
0568     mpci = loadcase('t_case_int');
0569     eVmQgcols = [11:20 25:28]';
0570     iVmQgcols = [10:18 22:24]';
0571     mpce.A(:, eVmQgcols) = [];
0572     mpce.N(:, eVmQgcols) = [];
0573     mpci.A(:, iVmQgcols) = [];
0574     mpci.N(:, iVmQgcols) = [];
0575     mpc = ext2int(mpce);
0576     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0577     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0578     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0579     t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0580     t_is(mpc.A, mpci.A, 12, [t 'A']);
0581     t_is(mpc.N, mpci.N, 12, [t 'N']);
0582 
0583     t = 'mpc = int2ext(mpc) - A, N are DC sized : ';
0584     mpc = int2ext(mpc);
0585     t_is(mpc.bus, mpce.bus, 12, [t 'bus']);
0586     t_is(mpc.branch, mpce.branch, 12, [t 'branch']);
0587     t_is(mpc.gen, mpce.gen, 12, [t 'gen']);
0588     t_is(mpc.gencost, mpce.gencost, 12, [t 'gencost']);
0589     t_is(mpc.A, mpce.A, 12, [t 'A']);
0590     t_is(mpc.N, mpce.N, 12, [t 'N']);
0591 end
0592 
0593 t_end;

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