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

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