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