Home > matpower7.0 > lib > 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 https://matpower.org for more info.
0013 
0014 if nargin < 1
0015     quiet = 0;
0016 end
0017 
0018 num_tests = 165;
0019 t_begin(num_tests, quiet);
0020 
0021 %% define named indices into data matrices
0022 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0023     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0024 
0025 %% for MATLAB versions prior to R2012a (v 7.14)
0026 if ~exist('isequaln')
0027     eval('isequaln = @isequalwithequalnans;');
0028 end
0029 
0030 if have_fcn('matlab', 'vnum') < 7.001
0031     t_skip(num_tests, 'test requires cellfun() construct not available before MATLAB 7.1');
0032 else
0033     mpce = loadcase('t_case_ext');
0034     mpci = loadcase('t_case_int');
0035     
0036     gen_i2e = [1 2 4];
0037 
0038     An = mpce.xbus;
0039     As = mpce.strbus;
0040 
0041     %%-----  get_reorder  -----
0042     k = [3; 7; 4; 1];
0043     t = 'get_reorder(A, k, 1) : numeric';
0044     t_is(get_reorder(An, k, 1), An(k, :), 12, t);
0045 
0046     t = 'get_reorder(A, k, 2) : numeric';
0047     t_is(get_reorder(An, k, 2), An(:, k), 12, t);
0048 
0049     %%-----  set_reorder  -----
0050     k = (2:2:10)';
0051     t = 'set_reorder(A, B, k, 1) : numeric';
0052     B = An(k, :) * -1;
0053     got = set_reorder(An, B, k, 1);
0054     ex = An;
0055     ex(k, :) = -ex(k, :);
0056     t_is(got, ex, 12, t);
0057 
0058     t = 'set_reorder(A, B, k, 2) : numeric';
0059     B = An(:, k) * -1;
0060     got = set_reorder(An, B, k, 2);
0061     ex = An;
0062     ex(:, k) = -ex(:, k);
0063     t_is(got, ex, 12, t);
0064 
0065     t = 'set_reorder(A, Bshort, k, 1) : numeric';
0066     k = (2:2:8)';
0067     B = An(k, 1:8) * -1;
0068     got = set_reorder(An, B, k, 1);
0069     ex = An;
0070     ex(k, 1:8) = -ex(k, 1:8);
0071     t_is(got, ex, 12, t);
0072 
0073     t = 'set_reorder(A, Bshort, k, 2) : numeric';
0074     B = An(1:8, k) * -1;
0075     got = set_reorder(An, B, k, 2);
0076     ex = An;
0077     ex(1:8, k) = -ex(1:8, k);
0078     t_is(got, ex, 12, t);
0079 
0080     t = 'set_reorder(A, Blong, k, 1) : numeric';
0081     k = (2:2:10)';
0082     B = An(k, :) * -1;
0083     B = [B B];
0084     got = set_reorder(An, B, k, 1);
0085     ex = [An zeros(size(An))];
0086     ex(k, :) = [-An(k, :) -An(k, :)];
0087     t_is(got, ex, 12, t);
0088 
0089     t = 'set_reorder(A, Blong, k, 2) : numeric';
0090     B = An(:, k) * -1;
0091     B = [B; B];
0092     got = set_reorder(An, B, k, 2);
0093     ex = [An; zeros(size(An))];
0094     ex(:, k) = [-An(:, k); -An(:, k)];
0095     t_is(got, ex, 12, t);
0096 
0097 
0098     %%-----  get_reorder (cell)  -----
0099     k = [3; 7; 4; 1];
0100     t = 'get_reorder(A, k, 1) : cell';
0101     t_is(cellfun(@str2num, get_reorder(As, k, 1)), cellfun(@str2num, As(k, :)), 12, t);
0102 
0103     t = 'get_reorder(A, k, 2) : cell';
0104     t_is(cellfun(@str2num, get_reorder(As, k, 2)), cellfun(@str2num, As(:, k)), 12, t);
0105 
0106     %%-----  set_reorder (cell)  -----
0107     k = (2:2:10)';
0108     t = 'set_reorder(A, B, k, 1) : cell';
0109     B = cellfun(@num2str, num2cell(An(k, :) * -1), 'UniformOutput', 0);
0110     got = set_reorder(As, B, k, 1);
0111     ex = As;
0112     ex(k, :) = cellfun(@num2str, num2cell(-cellfun(@str2num, ex(k, :))), 'UniformOutput', 0);
0113     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0114 
0115     t = 'set_reorder(A, B, k, 2) : cell';
0116     B = cellfun(@num2str, num2cell(An(:, k) * -1), 'UniformOutput', 0);
0117     got = set_reorder(As, B, k, 2);
0118     ex = As;
0119     ex(:, k) = cellfun(@num2str, num2cell(-cellfun(@str2num, ex(:, k))), 'UniformOutput', 0);
0120     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0121 
0122     t = 'set_reorder(A, Bshort, k, 1) : cell';
0123     k = (2:2:8)';
0124     B = cellfun(@num2str, num2cell(An(k, 1:8) * -1), 'UniformOutput', 0);
0125     got = set_reorder(As, B, k, 1);
0126     ex = As;
0127     ex(k, 1:8) = cellfun(@num2str, num2cell(-cellfun(@str2num, ex(k, 1:8))), 'UniformOutput', 0);
0128     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0129 
0130     t = 'set_reorder(A, Bshort, k, 2) : cell';
0131     B = cellfun(@num2str, num2cell(An(1:8, k) * -1), 'UniformOutput', 0);
0132     got = set_reorder(As, B, k, 2);
0133     ex = As;
0134     ex(1:8, k) = cellfun(@num2str, num2cell(-cellfun(@str2num, ex(1:8, k))), 'UniformOutput', 0);
0135     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0136 
0137     t = 'set_reorder(A, Blong, k, 1) : cell';
0138     k = (2:2:10)';
0139     B = cellfun(@num2str, num2cell(An(k, :) * -1), 'UniformOutput', 0);
0140     B = [B B];
0141     got = set_reorder(As, B, k, 1);
0142     ex = [As cell(size(As))];
0143     ex(k, :) = cellfun(@num2str, num2cell([-An(k, :) -An(k, :)]), 'UniformOutput', 0);
0144     for i = 1:size(got, 1)      %% replace [] with '-999' to make str2num happy
0145         for j = 1:size(got, 2)
0146             if isempty(got{i, j})
0147                 got{i, j} = '-999';
0148             end
0149             if isempty(ex{i, j})
0150                 ex{i, j} = '-999';
0151             end
0152         end
0153     end
0154     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0155 
0156     t = 'set_reorder(A, Blong, k, 2) : cell';
0157     B = cellfun(@num2str, num2cell(An(:, k) * -1), 'UniformOutput', 0);
0158     B = [B; B];
0159     got = set_reorder(As, B, k, 2);
0160     ex = [As; cell(size(As))];
0161     ex(:, k) = cellfun(@num2str, num2cell([-An(:, k); -An(:, k)]), 'UniformOutput', 0);
0162     for i = 1:size(got, 1)      %% replace [] with '-999' to make str2num happy
0163         for j = 1:size(got, 2)
0164             if isempty(got{i, j})
0165                 got{i, j} = '-999';
0166             end
0167             if isempty(ex{i, j})
0168                 ex{i, j} = '-999';
0169             end
0170         end
0171     end
0172     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0173 
0174     %%-----  mpc = ext2int/int2ext(mpc)  -----
0175     t = 'mpc = ext2int(mpc) : ';
0176     mpc = ext2int(mpce);
0177     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0178     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0179     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0180     t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0181     t_ok(isequaln(mpc.bus_name, mpci.bus_name), [t 'bus_name']);
0182     t_ok(isequaln(mpc.gentype, mpci.gentype), [t 'gentype']);
0183     t_ok(isequaln(mpc.genfuel, mpci.genfuel), [t 'genfuel']);
0184     t_is(mpc.A, mpci.A, 12, [t 'A']);
0185     t_is(mpc.N, mpci.N, 12, [t 'N']);
0186     t = 'mpc = ext2int(mpc) - repeat : ';
0187     mpc = ext2int(mpc);
0188     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0189     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0190     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0191     t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0192     t_ok(isequaln(mpc.bus_name, mpci.bus_name), [t 'bus_name']);
0193     t_ok(isequaln(mpc.gentype, mpci.gentype), [t 'gentype']);
0194     t_ok(isequaln(mpc.genfuel, mpci.genfuel), [t 'genfuel']);
0195     t_is(mpc.A, mpci.A, 12, [t 'A']);
0196     t_is(mpc.N, mpci.N, 12, [t 'N']);
0197     t = 'mpc = int2ext(mpc) : ';
0198     mpc = int2ext(mpc);
0199     t_is(mpc.bus, mpce.bus, 12, [t 'bus']);
0200     t_is(mpc.branch, mpce.branch, 12, [t 'branch']);
0201     t_is(mpc.gen, mpce.gen, 12, [t 'gen']);
0202     t_is(mpc.gencost, mpce.gencost, 12, [t 'gencost']);
0203     t_ok(isequaln(mpc.bus_name, mpce.bus_name), [t 'bus_name']);
0204     t_ok(isequaln(mpc.gentype, mpce.gentype), [t 'gentype']);
0205     t_ok(isequaln(mpc.genfuel, mpce.genfuel), [t 'genfuel']);
0206     t_is(mpc.A, mpce.A, 12, [t 'A']);
0207     t_is(mpc.N, mpce.N, 12, [t 'N']);
0208 
0209     %%-----  mpc = ext2int/int2ext(mpc, mpopt)  -----
0210     mpopt = mpoption();
0211     t = 'mpc = ext2int(mpc, mpopt) : ';
0212     mpc = ext2int(mpce, mpopt);
0213     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0214     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0215     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0216     t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0217     t_ok(isequaln(mpc.bus_name, mpci.bus_name), [t 'bus_name']);
0218     t_ok(isequaln(mpc.gentype, mpci.gentype), [t 'gentype']);
0219     t_ok(isequaln(mpc.genfuel, mpci.genfuel), [t 'genfuel']);
0220     t_is(mpc.A, mpci.A, 12, [t 'A']);
0221     t_is(mpc.N, mpci.N, 12, [t 'N']);
0222     t = 'mpc = ext2int(mpc, mpopt) - repeat : ';
0223     mpc = ext2int(mpc, mpopt);
0224     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0225     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0226     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0227     t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0228     t_ok(isequaln(mpc.bus_name, mpci.bus_name), [t 'bus_name']);
0229     t_ok(isequaln(mpc.gentype, mpci.gentype), [t 'gentype']);
0230     t_ok(isequaln(mpc.genfuel, mpci.genfuel), [t 'genfuel']);
0231     t_is(mpc.A, mpci.A, 12, [t 'A']);
0232     t_is(mpc.N, mpci.N, 12, [t 'N']);
0233     t = 'mpc = int2ext(mpc, mpopt) : ';
0234     mpc = int2ext(mpc, mpopt);
0235     t_is(mpc.bus, mpce.bus, 12, [t 'bus']);
0236     t_is(mpc.branch, mpce.branch, 12, [t 'branch']);
0237     t_is(mpc.gen, mpce.gen, 12, [t 'gen']);
0238     t_is(mpc.gencost, mpce.gencost, 12, [t 'gencost']);
0239     t_ok(isequaln(mpc.bus_name, mpce.bus_name), [t 'bus_name']);
0240     t_ok(isequaln(mpc.gentype, mpce.gentype), [t 'gentype']);
0241     t_ok(isequaln(mpc.genfuel, mpce.genfuel), [t 'genfuel']);
0242     t_is(mpc.A, mpce.A, 12, [t 'A']);
0243     t_is(mpc.N, mpce.N, 12, [t 'N']);
0244 
0245     %%-----  val = e2i_data/i2e_data(mpc, val, ...)  -----
0246     t = 'val = e2i_data(mpc, val, ''bus'')';
0247     mpc = ext2int(mpce);
0248     got = e2i_data(mpc, mpce.xbus, 'bus');
0249     ex = mpce.xbus;
0250     ex(6, :) = [];
0251     t_is(got, ex, 12, t);
0252     t = 'val = i2e_data(mpc, val, oldval, ''bus'')';
0253     tmp = ones(size(mpce.xbus));
0254     tmp(6, :) = mpce.xbus(6, :);
0255     got = i2e_data(mpc, ex, tmp, 'bus');
0256     t_is(got, mpce.xbus, 12, t);
0257 
0258     t = 'val = e2i_data(mpc, val, ''bus'', 2)';
0259     got = e2i_data(mpc, mpce.xbus, 'bus', 2);
0260     ex = mpce.xbus;
0261     ex(:, 6) = [];
0262     t_is(got, ex, 12, t);
0263     t = 'val = i2e_data(mpc, val, oldval, ''bus'', 2)';
0264     tmp = ones(size(mpce.xbus));
0265     tmp(:, 6) = mpce.xbus(:, 6);
0266     got = i2e_data(mpc, ex, tmp, 'bus', 2);
0267     t_is(got, mpce.xbus, 12, t);
0268 
0269     t = 'val = e2i_data(mpc, val, ''gen'')';
0270     got = e2i_data(mpc, mpce.xgen, 'gen');
0271     ex = mpce.xgen(gen_i2e, :);
0272     t_is(got, ex, 12, t);
0273     t = 'val = i2e_data(mpc, val, oldval, ''gen'')';
0274     tmp = ones(size(mpce.xgen));
0275     tmp(3, :) = mpce.xgen(3, :);
0276     got = i2e_data(mpc, ex, tmp, 'gen');
0277     t_is(got, mpce.xgen, 12, t);
0278 
0279     t = 'val = e2i_data(mpc, val, ''gen'', 2)';
0280     got = e2i_data(mpc, mpce.xgen, 'gen', 2);
0281     ex = mpce.xgen(:, gen_i2e);
0282     t_is(got, ex, 12, t);
0283     t = 'val = i2e_data(mpc, val, oldval, ''gen'', 2)';
0284     tmp = ones(size(mpce.xgen));
0285     tmp(:, 3) = mpce.xgen(:, 3);
0286     got = i2e_data(mpc, ex, tmp, 'gen', 2);
0287     t_is(got, mpce.xgen, 12, t);
0288 
0289     t = 'val = e2i_data(mpc, val, ''branch'')';
0290     got = e2i_data(mpc, mpce.xbranch, 'branch');
0291     ex = mpce.xbranch;
0292     ex(7, :) = [];
0293     t_is(got, ex, 12, t);
0294     t = 'val = i2e_data(mpc, val, oldval, ''branch'')';
0295     tmp = ones(size(mpce.xbranch));
0296     tmp(7, :) = mpce.xbranch(7, :);
0297     got = i2e_data(mpc, ex, tmp, 'branch');
0298     t_is(got, mpce.xbranch, 12, t);
0299 
0300     t = 'val = e2i_data(mpc, val, ''branch'', 2)';
0301     got = e2i_data(mpc, mpce.xbranch, 'branch', 2);
0302     ex = mpce.xbranch;
0303     ex(:, 7) = [];
0304     t_is(got, ex, 12, t);
0305     t = 'val = i2e_data(mpc, val, oldval, ''branch'', 2)';
0306     tmp = ones(size(mpce.xbranch));
0307     tmp(:, 7) = mpce.xbranch(:, 7);
0308     got = i2e_data(mpc, ex, tmp, 'branch', 2);
0309     t_is(got, mpce.xbranch, 12, t);
0310 
0311     t = 'val = e2i_data(mpc, val, {''branch'', ''gen'', ''bus''})';
0312     got = e2i_data(mpc, mpce.xrows, {'branch', 'gen', 'bus'});
0313     ex = [mpce.xbranch([1:6, 8:10], 1:4); mpce.xgen(gen_i2e, :); mpce.xbus([1:5, 7:10], 1:4); -ones(2, 4)];
0314     t_is(got, ex, 12, t);
0315     t = 'val = i2e_data(mpc, val, oldval, {''branch'', ''gen'', ''bus''})';
0316     tmp1 = ones(size(mpce.xbranch(:, 1:4)));
0317     tmp1(7, 1:4) = mpce.xbranch(7, 1:4);
0318     tmp2 = ones(size(mpce.xgen));
0319     tmp2(3, :) = mpce.xgen(3, :);
0320     tmp3 = ones(size(mpce.xbus(:, 1:4)));
0321     tmp3(6, 1:4) = mpce.xbus(6, 1:4);
0322     tmp = [tmp1; tmp2; tmp3];
0323     got = i2e_data(mpc, ex, tmp, {'branch', 'gen', 'bus'});
0324     t_is(got, mpce.xrows, 12, t);
0325 
0326     t = 'val = e2i_data(mpc, val, {''branch'', ''gen'', ''bus''}, 2)';
0327     got = e2i_data(mpc, mpce.xcols, {'branch', 'gen', 'bus'}, 2);
0328     ex = [mpce.xbranch([1:6, 8:10], 1:4); mpce.xgen(gen_i2e, :); mpce.xbus([1:5, 7:10], 1:4); -ones(2, 4)]';
0329     t_is(got, ex, 12, t);
0330     t = 'val = i2e_data(mpc, val, oldval, {''branch'', ''gen'', ''bus''}, 2)';
0331     tmp1 = ones(size(mpce.xbranch(:, 1:4)));
0332     tmp1(7, 1:4) = mpce.xbranch(7, 1:4);
0333     tmp2 = ones(size(mpce.xgen));
0334     tmp2(3, :) = mpce.xgen(3, :);
0335     tmp3 = ones(size(mpce.xbus(:, 1:4)));
0336     tmp3(6, 1:4) = mpce.xbus(6, 1:4);
0337     tmp = [tmp1; tmp2; tmp3]';
0338     got = i2e_data(mpc, ex, tmp, {'branch', 'gen', 'bus'}, 2);
0339     t_is(got, mpce.xcols, 12, t);
0340 
0341     %%-----  val = e2i_data/i2e_data(mpc, cell, ...)  -----
0342     t = 'val = e2i_data(mpc, cell, ''bus'')';
0343     mpc = ext2int(mpce);
0344     got = e2i_data(mpc, mpce.strbus, 'bus');
0345     ex = mpce.strbus;
0346     ex(6, :) = [];
0347     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0348     t = 'val = i2e_data(mpc, cell, oldval, ''bus'')';
0349     tmp = cell(size(mpce.strbus));
0350     tmp(6, :) = mpce.strbus(6, :);
0351     got = i2e_data(mpc, ex, tmp, 'bus');
0352     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strbus), 12, t);
0353 
0354     t = 'val = e2i_data(mpc, cell, ''bus'', 2)';
0355     got = e2i_data(mpc, mpce.strbus, 'bus', 2);
0356     ex = mpce.strbus;
0357     ex(:, 6) = [];
0358     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0359     t = 'val = i2e_data(mpc, cell, oldval, ''bus'', 2)';
0360     tmp = cell(size(mpce.strbus));
0361     tmp(:, 6) = mpce.strbus(:, 6);
0362     got = i2e_data(mpc, ex, tmp, 'bus', 2);
0363     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strbus), 12, t);
0364 
0365     t = 'val = e2i_data(mpc, cell, ''gen'')';
0366     got = e2i_data(mpc, mpce.strgen, 'gen');
0367     ex = mpce.strgen(gen_i2e, :);
0368     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0369     t = 'val = i2e_data(mpc, cell, oldval, ''gen'')';
0370     tmp = cell(size(mpce.strgen));
0371     tmp(3, :) = mpce.strgen(3, :);
0372     got = i2e_data(mpc, ex, tmp, 'gen');
0373     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strgen), 12, t);
0374 
0375     t = 'val = e2i_data(mpc, cell, ''gen'', 2)';
0376     got = e2i_data(mpc, mpce.strgen, 'gen', 2);
0377     ex = mpce.strgen(:, gen_i2e);
0378     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0379     t = 'val = i2e_data(mpc, cell, oldval, ''gen'', 2)';
0380     tmp = cell(size(mpce.strgen));
0381     tmp(:, 3) = mpce.strgen(:, 3);
0382     got = i2e_data(mpc, ex, tmp, 'gen', 2);
0383     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strgen), 12, t);
0384 
0385     t = 'val = e2i_data(mpc, cell, ''branch'')';
0386     got = e2i_data(mpc, mpce.strbranch, 'branch');
0387     ex = mpce.strbranch;
0388     ex(7, :) = [];
0389     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0390     t = 'val = i2e_data(mpc, cell, oldval, ''branch'')';
0391     tmp = cell(size(mpce.strbranch));
0392     tmp(7, :) = mpce.strbranch(7, :);
0393     got = i2e_data(mpc, ex, tmp, 'branch');
0394     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strbranch), 12, t);
0395 
0396     t = 'val = e2i_data(mpc, cell, ''branch'', 2)';
0397     got = e2i_data(mpc, mpce.strbranch, 'branch', 2);
0398     ex = mpce.strbranch;
0399     ex(:, 7) = [];
0400     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0401     t = 'val = i2e_data(mpc, cell, oldval, ''branch'', 2)';
0402     tmp = cell(size(mpce.strbranch));
0403     tmp(:, 7) = mpce.strbranch(:, 7);
0404     got = i2e_data(mpc, ex, tmp, 'branch', 2);
0405     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strbranch), 12, t);
0406 
0407     t = 'val = e2i_data(mpc, cell, {''branch'', ''gen'', ''bus''})';
0408     got = e2i_data(mpc, mpce.strrows, {'branch', 'gen', 'bus'});
0409     ex = [mpce.strbranch([1:6, 8:10], 1:4); mpce.strgen(gen_i2e, :); mpce.strbus([1:5, 7:10], 1:4); cellfun(@num2str, num2cell(-ones(2, 4)), 'UniformOutput', 0)];
0410     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0411     t = 'val = i2e_data(mpc, cell, oldval, {''branch'', ''gen'', ''bus''})';
0412     tmp1 = cell(size(mpce.strbranch(:, 1:4)));
0413     tmp1(7, 1:4) = mpce.strbranch(7, 1:4);
0414     tmp2 = cell(size(mpce.strgen));
0415     tmp2(3, :) = mpce.strgen(3, :);
0416     tmp3 = cell(size(mpce.strbus(:, 1:4)));
0417     tmp3(6, 1:4) = mpce.strbus(6, 1:4);
0418     tmp = [tmp1; tmp2; tmp3];
0419     got = i2e_data(mpc, ex, tmp, {'branch', 'gen', 'bus'});
0420     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strrows), 12, t);
0421 
0422     t = 'val = e2i_data(mpc, cell, {''branch'', ''gen'', ''bus''}, 2)';
0423     got = e2i_data(mpc, mpce.strcols, {'branch', 'gen', 'bus'}, 2);
0424     ex = [mpce.strbranch([1:6, 8:10], 1:4); mpce.strgen(gen_i2e, :); mpce.strbus([1:5, 7:10], 1:4); cellfun(@num2str, num2cell(-ones(2, 4)), 'UniformOutput', 0)]';
0425     t_is(cellfun(@str2num, got), cellfun(@str2num, ex), 12, t);
0426     t = 'val = i2e_data(mpc, cell, oldval, {''branch'', ''gen'', ''bus''}, 2)';
0427     tmp1 = cell(size(mpce.strbranch(:, 1:4)));
0428     tmp1(7, 1:4) = mpce.strbranch(7, 1:4);
0429     tmp2 = cell(size(mpce.strgen));
0430     tmp2(3, :) = mpce.strgen(3, :);
0431     tmp3 = cell(size(mpce.strbus(:, 1:4)));
0432     tmp3(6, 1:4) = mpce.strbus(6, 1:4);
0433     tmp = [tmp1; tmp2; tmp3]';
0434     got = i2e_data(mpc, ex, tmp, {'branch', 'gen', 'bus'}, 2);
0435     t_is(cellfun(@str2num, got), cellfun(@str2num, mpce.strcols), 12, t);
0436 
0437     %%-----  mpc = e2i_field/i2e_field(mpc, field, ...)  -----
0438     t = 'mpc = e2i_field(mpc, field, ''bus'')';
0439     mpc = ext2int(mpce);
0440     ex = mpce.xbus;
0441     ex(6, :) = [];
0442     got = e2i_field(mpc, 'xbus', 'bus');
0443     t_is(got.xbus, ex, 12, t);
0444     t = 'mpc = i2e_field(mpc, field, ''bus'')';
0445     got = i2e_field(got, 'xbus', 'bus');
0446     t_is(got.xbus, mpce.xbus, 12, t);
0447 
0448     t = 'mpc = e2i_field(mpc, field, ''bus'', 2)';
0449     ex = mpce.xbus;
0450     ex(:, 6) = [];
0451     got = e2i_field(mpc, 'xbus', 'bus', 2);
0452     t_is(got.xbus, ex, 12, t);
0453     t = 'mpc = i2e_field(mpc, field, ''bus'', 2)';
0454     got = i2e_field(got, 'xbus', 'bus', 2);
0455     t_is(got.xbus, mpce.xbus, 12, t);
0456 
0457     t = 'mpc = e2i_field(mpc, field, ''gen'')';
0458     ex = mpce.xgen(gen_i2e, :);
0459     got = e2i_field(mpc, 'xgen', 'gen');
0460     t_is(got.xgen, ex, 12, t);
0461     t = 'mpc = i2e_field(mpc, field, ''gen'')';
0462     got = i2e_field(got, 'xgen', 'gen');
0463     t_is(got.xgen, mpce.xgen, 12, t);
0464 
0465     t = 'mpc = e2i_field(mpc, field, ''gen'', 2)';
0466     ex = mpce.xgen(:, gen_i2e);
0467     got = e2i_field(mpc, 'xgen', 'gen', 2);
0468     t_is(got.xgen, ex, 12, t);
0469     t = 'mpc = i2e_field(mpc, field, ''gen'', 2)';
0470     got = i2e_field(got, 'xgen', 'gen', 2);
0471     t_is(got.xgen, mpce.xgen, 12, t);
0472 
0473     t = 'mpc = e2i_field(mpc, field, ''branch'')';
0474     ex = mpce.xbranch;
0475     ex(7, :) = [];
0476     got = e2i_field(mpc, 'xbranch', 'branch');
0477     t_is(got.xbranch, ex, 12, t);
0478     t = 'mpc = i2e_field(mpc, field, ''branch'')';
0479     got = i2e_field(got, 'xbranch', 'branch');
0480     t_is(got.xbranch, mpce.xbranch, 12, t);
0481 
0482     t = 'mpc = e2i_field(mpc, field, ''branch'', 2)';
0483     ex = mpce.xbranch;
0484     ex(:, 7) = [];
0485     got = e2i_field(mpc, 'xbranch', 'branch', 2);
0486     t_is(got.xbranch, ex, 12, t);
0487     t = 'mpc = i2e_field(mpc, field, ''branch'', 2)';
0488     got = i2e_field(got, 'xbranch', 'branch', 2);
0489     t_is(got.xbranch, mpce.xbranch, 12, t);
0490 
0491     t = 'mpc = e2i_field(mpc, field, {''branch'', ''gen'', ''bus''})';
0492     ex = [mpce.xbranch([1:6, 8:10], 1:4); mpce.xgen(gen_i2e, :); mpce.xbus([1:5, 7:10], 1:4); -ones(2, 4)];
0493     got = e2i_field(mpc, 'xrows', {'branch', 'gen', 'bus'});
0494     t_is(got.xrows, ex, 12, t);
0495     t = 'mpc = i2e_field(mpc, field, {''branch'', ''gen'', ''bus''})';
0496     got = i2e_field(got, 'xrows', {'branch', 'gen', 'bus'});
0497     t_is(got.xrows, mpce.xrows, 12, t);
0498 
0499     t = 'mpc = e2i_field(mpc, field, {''branch'', ''gen'', ''bus''}, 2)';
0500     ex = [mpce.xbranch([1:6, 8:10], 1:4); mpce.xgen(gen_i2e, :); mpce.xbus([1:5, 7:10], 1:4); -ones(2, 4)]';
0501     got = e2i_field(mpc, 'xcols', {'branch', 'gen', 'bus'}, 2);
0502     t_is(got.xcols, ex, 12, t);
0503     t = 'mpc = i2e_field(mpc, field, {''branch'', ''gen'', ''bus''})';
0504     got = i2e_field(got, 'xcols', {'branch', 'gen', 'bus'}, 2);
0505     t_is(got.xcols, mpce.xcols, 12, t);
0506 
0507     t = 'mpc = e2i_field(mpc, {''field1'', ''field2''}, ordering)';
0508     ex = mpce.x.more(gen_i2e, :);
0509     got = e2i_field(mpc, {'x', 'more'}, 'gen');
0510     t_is(got.x.more, ex, 12, t);
0511     t = 'mpc = i2e_field(mpc, {''field1'', ''field2''}, ordering)';
0512     got = i2e_field(got, {'x', 'more'}, 'gen');
0513     t_is(got.x.more, mpce.x.more, 12, t);
0514 
0515     t = 'mpc = e2i_field(mpc, {''field1'', ''field2''}, ordering, 2)';
0516     ex = mpce.x.more(:, gen_i2e);
0517     got = e2i_field(mpc, {'x', 'more'}, 'gen', 2);
0518     t_is(got.x.more, ex, 12, t);
0519     t = 'mpc = i2e_field(mpc, {''field1'', ''field2''}, ordering, 2)';
0520     got = i2e_field(got, {'x', 'more'}, 'gen', 2);
0521     t_is(got.x.more, mpce.x.more, 12, t);
0522 
0523     %%-----  mpc = e2i_field/i2e_field(mpc, cellfield, ...)  -----
0524     t = 'mpc = e2i_field(mpc, cellfield, ''bus'')';
0525     mpc = ext2int(mpce);
0526     ex = mpce.strbus;
0527     ex(6, :) = [];
0528     got = e2i_field(mpc, 'strbus', 'bus');
0529     t_is(cellfun(@str2num, got.strbus), cellfun(@str2num, ex), 12, t);
0530     t = 'mpc = i2e_field(mpc, cellfield, ''bus'')';
0531     got = i2e_field(got, 'strbus', 'bus');
0532     t_is(cellfun(@str2num, got.strbus), cellfun(@str2num, mpce.strbus), 12, t);
0533 
0534     t = 'mpc = e2i_field(mpc, cellfield, ''bus'', 2)';
0535     ex = mpce.strbus;
0536     ex(:, 6) = [];
0537     got = e2i_field(mpc, 'strbus', 'bus', 2);
0538     t_is(cellfun(@str2num, got.strbus), cellfun(@str2num, ex), 12, t);
0539     t = 'mpc = i2e_field(mpc, cellfield, ''bus'', 2)';
0540     got = i2e_field(got, 'strbus', 'bus', 2);
0541     t_is(cellfun(@str2num, got.strbus), cellfun(@str2num, mpce.strbus), 12, t);
0542 
0543     t = 'mpc = e2i_field(mpc, cellfield, ''gen'')';
0544     ex = mpce.strgen(gen_i2e, :);
0545     got = e2i_field(mpc, 'strgen', 'gen');
0546     t_is(cellfun(@str2num, got.strgen), cellfun(@str2num, ex), 12, t);
0547     t = 'mpc = i2e_field(mpc, cellfield, ''gen'')';
0548     got = i2e_field(got, 'strgen', 'gen');
0549     t_is(cellfun(@str2num, got.strgen), cellfun(@str2num, mpce.strgen), 12, t);
0550 
0551     t = 'mpc = e2i_field(mpc, cellfield, ''gen'', 2)';
0552     ex = mpce.strgen(:, gen_i2e);
0553     got = e2i_field(mpc, 'strgen', 'gen', 2);
0554     t_is(cellfun(@str2num, got.strgen), cellfun(@str2num, ex), 12, t);
0555     t = 'mpc = i2e_field(mpc, cellfield, ''gen'', 2)';
0556     got = i2e_field(got, 'strgen', 'gen', 2);
0557     t_is(cellfun(@str2num, got.strgen), cellfun(@str2num, mpce.strgen), 12, t);
0558 
0559     t = 'mpc = e2i_field(mpc, cellfield, ''branch'')';
0560     ex = mpce.strbranch;
0561     ex(7, :) = [];
0562     got = e2i_field(mpc, 'strbranch', 'branch');
0563     t_is(cellfun(@str2num, got.strbranch), cellfun(@str2num, ex), 12, t);
0564     t = 'mpc = i2e_field(mpc, cellfield, ''branch'')';
0565     got = i2e_field(got, 'strbranch', 'branch');
0566     t_is(cellfun(@str2num, got.strbranch), cellfun(@str2num, mpce.strbranch), 12, t);
0567 
0568     t = 'mpc = e2i_field(mpc, cellfield, ''branch'', 2)';
0569     ex = mpce.strbranch;
0570     ex(:, 7) = [];
0571     got = e2i_field(mpc, 'strbranch', 'branch', 2);
0572     t_is(cellfun(@str2num, got.strbranch), cellfun(@str2num, ex), 12, t);
0573     t = 'mpc = i2e_field(mpc, cellfield, ''branch'', 2)';
0574     got = i2e_field(got, 'strbranch', 'branch', 2);
0575     t_is(cellfun(@str2num, got.strbranch), cellfun(@str2num, mpce.strbranch), 12, t);
0576 
0577     t = 'mpc = e2i_field(mpc, cellfield, {''branch'', ''gen'', ''bus''})';
0578     ex = [mpce.strbranch([1:6, 8:10], 1:4); mpce.strgen(gen_i2e, :); mpce.strbus([1:5, 7:10], 1:4); cellfun(@num2str, num2cell(-ones(2, 4)), 'UniformOutput', 0)];
0579     got = e2i_field(mpc, 'strrows', {'branch', 'gen', 'bus'});
0580     t_is(cellfun(@str2num, got.strrows), cellfun(@str2num, ex), 12, t);
0581     t = 'mpc = i2e_field(mpc, cellfield, {''branch'', ''gen'', ''bus''})';
0582     got = i2e_field(got, 'strrows', {'branch', 'gen', 'bus'});
0583     t_is(cellfun(@str2num, got.strrows), cellfun(@str2num, mpce.strrows), 12, t);
0584 
0585     t = 'mpc = e2i_field(mpc, cellfield, {''branch'', ''gen'', ''bus''}, 2)';
0586     ex = [mpce.strbranch([1:6, 8:10], 1:4); mpce.strgen(gen_i2e, :); mpce.strbus([1:5, 7:10], 1:4); cellfun(@num2str, num2cell(-ones(2, 4)), 'UniformOutput', 0)]';
0587     got = e2i_field(mpc, 'strcols', {'branch', 'gen', 'bus'}, 2);
0588     t_is(cellfun(@str2num, got.strcols), cellfun(@str2num, ex), 12, t);
0589     t = 'mpc = i2e_field(mpc, cellfield, {''branch'', ''gen'', ''bus''})';
0590     got = i2e_field(got, 'strcols', {'branch', 'gen', 'bus'}, 2);
0591     t_is(cellfun(@str2num, got.strcols), cellfun(@str2num, mpce.strcols), 12, t);
0592 
0593     %%-----  more mpc = ext2int/int2ext(mpc)  -----
0594     t = 'mpc = ext2int(mpc) - bus/gen/branch only : ';
0595     mpce = loadcase('t_case_ext');
0596     mpci = loadcase('t_case_int');
0597     mpce = rmfield(mpce, 'gencost');
0598     mpce = rmfield(mpce, 'A');
0599     mpce = rmfield(mpce, 'N');
0600     mpci = rmfield(mpci, 'gencost');
0601     mpci = rmfield(mpci, 'A');
0602     mpci = rmfield(mpci, 'N');
0603     mpc = ext2int(mpce);
0604     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0605     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0606     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0607 
0608     t = 'mpc = ext2int(mpc) - Qg cost, no N : ';
0609     mpce = loadcase('t_case_ext');
0610     mpci = loadcase('t_case_int');
0611     mpce = rmfield(mpce, 'N');
0612     mpci = rmfield(mpci, 'N');
0613     mpce.gencost = [mpce.gencost; mpce.gencost];
0614     mpci.gencost = [mpci.gencost; mpci.gencost];
0615     mpc = ext2int(mpce);
0616     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0617     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0618     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0619     t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0620     t_is(mpc.A, mpci.A, 12, [t 'A']);
0621 
0622     t = 'mpc = ext2int(mpc) - A, N are DC sized : ';
0623     mpce = loadcase('t_case_ext');
0624     mpci = loadcase('t_case_int');
0625     eVmQgcols = [11:20 25:28]';
0626     iVmQgcols = [10:18 22:24]';
0627     mpce.A(:, eVmQgcols) = [];
0628     mpce.N(:, eVmQgcols) = [];
0629     mpci.A(:, iVmQgcols) = [];
0630     mpci.N(:, iVmQgcols) = [];
0631     mpc = ext2int(mpce);
0632     t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0633     t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0634     t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0635     t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0636     t_is(mpc.A, mpci.A, 12, [t 'A']);
0637     t_is(mpc.N, mpci.N, 12, [t 'N']);
0638 
0639     t = 'mpc = int2ext(mpc) - A, N are DC sized : ';
0640     mpc = int2ext(mpc);
0641     t_is(mpc.bus, mpce.bus, 12, [t 'bus']);
0642     t_is(mpc.branch, mpce.branch, 12, [t 'branch']);
0643     t_is(mpc.gen, mpce.gen, 12, [t 'gen']);
0644     t_is(mpc.gencost, mpce.gencost, 12, [t 'gencost']);
0645     t_is(mpc.A, mpce.A, 12, [t 'A']);
0646     t_is(mpc.N, mpce.N, 12, [t 'N']);
0647 
0648     t = 'mpc = ext2int(mpc) - all buses isolated : ';
0649     mpc = loadcase('t_case_ext');
0650     mpc.bus(:, BUS_TYPE) = NONE;
0651     try
0652         mpci = ext2int(mpc);
0653         t_is(size(mpci.bus, 1), 0, 12, [t 'internal case empty']);
0654     catch
0655         t_ok(0, [t 'unexpected fatal error']);
0656     end
0657 
0658     t = 'mpc = int2ext(mpc) - all buses isolated : ';
0659     try
0660         mpce = int2ext(mpci);
0661         t_is(mpc.bus, mpce.bus, 12, [t 'bus']);
0662         t_is(mpc.branch, mpce.branch, 12, [t 'branch']);
0663         t_is(mpc.gen, mpce.gen, 12, [t 'gen']);
0664         t_is(mpc.gencost, mpce.gencost, 12, [t 'gencost']);
0665         t_is(mpc.A, mpce.A, 12, [t 'A']);
0666         t_is(mpc.N, mpce.N, 12, [t 'N']);
0667     catch
0668         t_ok(0, [t 'unexpected fatal error']);
0669         t_skip(5, [t 'unexpected fatal error']);
0670     end
0671 end
0672 
0673 t_end;

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005