Home > matpower4.0 > t > t_ext2int2ext.m

t_ext2int2ext

PURPOSE ^

T_EXT2INT2EXT Tests EXT2INT and INT2EXT.

SYNOPSIS ^

function t_ext2int2ext(quiet)

DESCRIPTION ^

T_EXT2INT2EXT  Tests 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 and INT2EXT.
0003 
0004 %   MATPOWER
0005 %   $Id: t_ext2int2ext.m,v 1.6 2010/04/26 19:45:26 ray Exp $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2009-2010 by Power System Engineering Research Center (PSERC)
0008 %
0009 %   This file is part of MATPOWER.
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 %
0012 %   MATPOWER is free software: you can redistribute it and/or modify
0013 %   it under the terms of the GNU General Public License as published
0014 %   by the Free Software Foundation, either version 3 of the License,
0015 %   or (at your option) any later version.
0016 %
0017 %   MATPOWER is distributed in the hope that it will be useful,
0018 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0020 %   GNU General Public License for more details.
0021 %
0022 %   You should have received a copy of the GNU General Public License
0023 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0024 %
0025 %   Additional permission under GNU GPL version 3 section 7
0026 %
0027 %   If you modify MATPOWER, or any covered work, to interface with
0028 %   other modules (such as MATLAB code and MEX-files) available in a
0029 %   MATLAB(R) or comparable environment containing parts covered
0030 %   under other licensing terms, the licensors of MATPOWER grant
0031 %   you additional permission to convey the resulting work.
0032 
0033 if nargin < 1
0034     quiet = 0;
0035 end
0036 
0037 t_begin(85, quiet);
0038 
0039 if quiet
0040     verbose = 0;
0041 else
0042     verbose = 1;
0043 end
0044 
0045 %%-----  mpc = ext2int/int2ext(mpc)  -----
0046 t = 'mpc = ext2int(mpc) : ';
0047 mpce = loadcase('t_case_ext');
0048 mpci = loadcase('t_case_int');
0049 mpc = ext2int(mpce);
0050 t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0051 t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0052 t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0053 t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0054 t_is(mpc.areas, mpci.areas, 12, [t 'areas']);
0055 t_is(mpc.A, mpci.A, 12, [t 'A']);
0056 t_is(mpc.N, mpci.N, 12, [t 'N']);
0057 t = 'mpc = ext2int(mpc) - repeat : ';
0058 mpc = ext2int(mpc);
0059 t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0060 t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0061 t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0062 t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0063 t_is(mpc.areas, mpci.areas, 12, [t 'areas']);
0064 t_is(mpc.A, mpci.A, 12, [t 'A']);
0065 t_is(mpc.N, mpci.N, 12, [t 'N']);
0066 t = 'mpc = int2ext(mpc) : ';
0067 mpc = int2ext(mpc);
0068 t_is(mpc.bus, mpce.bus, 12, [t 'bus']);
0069 t_is(mpc.branch, mpce.branch, 12, [t 'branch']);
0070 t_is(mpc.gen, mpce.gen, 12, [t 'gen']);
0071 t_is(mpc.gencost, mpce.gencost, 12, [t 'gencost']);
0072 t_is(mpc.areas, mpce.areas, 12, [t 'areas']);
0073 t_is(mpc.A, mpce.A, 12, [t 'A']);
0074 t_is(mpc.N, mpce.N, 12, [t 'N']);
0075 
0076 %%-----  val = ext2int/int2ext(mpc, val, ...)  -----
0077 t = 'val = ext2int(mpc, val, ''bus'')';
0078 mpc = ext2int(mpce);
0079 got = ext2int(mpc, mpce.xbus, 'bus');
0080 ex = mpce.xbus;
0081 ex(6, :) = [];
0082 t_is(got, ex, 12, t);
0083 t = 'val = int2ext(mpc, val, oldval, ''bus'')';
0084 tmp = ones(size(mpce.xbus));
0085 tmp(6, :) = mpce.xbus(6, :);
0086 got = int2ext(mpc, ex, tmp, 'bus');
0087 t_is(got, mpce.xbus, 12, t);
0088 
0089 t = 'val = ext2int(mpc, val, ''bus'', 2)';
0090 got = ext2int(mpc, mpce.xbus, 'bus', 2);
0091 ex = mpce.xbus;
0092 ex(:, 6) = [];
0093 t_is(got, ex, 12, t);
0094 t = 'val = int2ext(mpc, val, oldval, ''bus'', 2)';
0095 tmp = ones(size(mpce.xbus));
0096 tmp(:, 6) = mpce.xbus(:, 6);
0097 got = int2ext(mpc, ex, tmp, 'bus', 2);
0098 t_is(got, mpce.xbus, 12, t);
0099 
0100 t = 'val = ext2int(mpc, val, ''gen'')';
0101 got = ext2int(mpc, mpce.xgen, 'gen');
0102 ex = mpce.xgen([4 2 1], :);
0103 t_is(got, ex, 12, t);
0104 t = 'val = int2ext(mpc, val, oldval, ''gen'')';
0105 tmp = ones(size(mpce.xgen));
0106 tmp(3, :) = mpce.xgen(3, :);
0107 got = int2ext(mpc, ex, tmp, 'gen');
0108 t_is(got, mpce.xgen, 12, t);
0109 
0110 t = 'val = ext2int(mpc, val, ''gen'', 2)';
0111 got = ext2int(mpc, mpce.xgen, 'gen', 2);
0112 ex = mpce.xgen(:, [4 2 1]);
0113 t_is(got, ex, 12, t);
0114 t = 'val = int2ext(mpc, val, oldval, ''gen'', 2)';
0115 tmp = ones(size(mpce.xgen));
0116 tmp(:, 3) = mpce.xgen(:, 3);
0117 got = int2ext(mpc, ex, tmp, 'gen', 2);
0118 t_is(got, mpce.xgen, 12, t);
0119 
0120 t = 'val = ext2int(mpc, val, ''branch'')';
0121 got = ext2int(mpc, mpce.xbranch, 'branch');
0122 ex = mpce.xbranch;
0123 ex(7, :) = [];
0124 t_is(got, ex, 12, t);
0125 t = 'val = int2ext(mpc, val, oldval, ''branch'')';
0126 tmp = ones(size(mpce.xbranch));
0127 tmp(7, :) = mpce.xbranch(7, :);
0128 got = int2ext(mpc, ex, tmp, 'branch');
0129 t_is(got, mpce.xbranch, 12, t);
0130 
0131 t = 'val = ext2int(mpc, val, ''branch'', 2)';
0132 got = ext2int(mpc, mpce.xbranch, 'branch', 2);
0133 ex = mpce.xbranch;
0134 ex(:, 7) = [];
0135 t_is(got, ex, 12, t);
0136 t = 'val = int2ext(mpc, val, oldval, ''branch'', 2)';
0137 tmp = ones(size(mpce.xbranch));
0138 tmp(:, 7) = mpce.xbranch(:, 7);
0139 got = int2ext(mpc, ex, tmp, 'branch', 2);
0140 t_is(got, mpce.xbranch, 12, t);
0141 
0142 t = 'val = ext2int(mpc, val, {''branch'', ''gen'', ''bus''})';
0143 got = ext2int(mpc, mpce.xrows, {'branch', 'gen', 'bus'});
0144 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)];
0145 t_is(got, ex, 12, t);
0146 t = 'val = int2ext(mpc, val, oldval, {''branch'', ''gen'', ''bus''})';
0147 tmp1 = ones(size(mpce.xbranch(:, 1:4)));
0148 tmp1(7, 1:4) = mpce.xbranch(7, 1:4);
0149 tmp2 = ones(size(mpce.xgen));
0150 tmp2(3, :) = mpce.xgen(3, :);
0151 tmp3 = ones(size(mpce.xbus(:, 1:4)));
0152 tmp3(6, 1:4) = mpce.xbus(6, 1:4);
0153 tmp = [tmp1; tmp2; tmp3];
0154 got = int2ext(mpc, ex, tmp, {'branch', 'gen', 'bus'});
0155 t_is(got, mpce.xrows, 12, t);
0156 
0157 t = 'val = ext2int(mpc, val, {''branch'', ''gen'', ''bus''}, 2)';
0158 got = ext2int(mpc, mpce.xcols, {'branch', 'gen', 'bus'}, 2);
0159 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)]';
0160 t_is(got, ex, 12, t);
0161 t = 'val = int2ext(mpc, val, oldval, {''branch'', ''gen'', ''bus''}, 2)';
0162 tmp1 = ones(size(mpce.xbranch(:, 1:4)));
0163 tmp1(7, 1:4) = mpce.xbranch(7, 1:4);
0164 tmp2 = ones(size(mpce.xgen));
0165 tmp2(3, :) = mpce.xgen(3, :);
0166 tmp3 = ones(size(mpce.xbus(:, 1:4)));
0167 tmp3(6, 1:4) = mpce.xbus(6, 1:4);
0168 tmp = [tmp1; tmp2; tmp3]';
0169 got = int2ext(mpc, ex, tmp, {'branch', 'gen', 'bus'}, 2);
0170 t_is(got, mpce.xcols, 12, t);
0171 
0172 %%-----  mpc = ext2int/int2ext(mpc, field, ...)  -----
0173 t = 'mpc = ext2int(mpc, field, ''bus'')';
0174 mpc = ext2int(mpce);
0175 ex = mpce.xbus;
0176 ex(6, :) = [];
0177 got = ext2int(mpc, 'xbus', 'bus');
0178 t_is(got.xbus, ex, 12, t);
0179 t = 'mpc = int2ext(mpc, field, ''bus'')';
0180 got = int2ext(got, 'xbus', 'bus');
0181 t_is(got.xbus, mpce.xbus, 12, t);
0182 
0183 t = 'mpc = ext2int(mpc, field, ''bus'', 2)';
0184 ex = mpce.xbus;
0185 ex(:, 6) = [];
0186 got = ext2int(mpc, 'xbus', 'bus', 2);
0187 t_is(got.xbus, ex, 12, t);
0188 t = 'mpc = int2ext(mpc, field, ''bus'', 2)';
0189 got = int2ext(got, 'xbus', 'bus', 2);
0190 t_is(got.xbus, mpce.xbus, 12, t);
0191 
0192 t = 'mpc = ext2int(mpc, field, ''gen'')';
0193 ex = mpce.xgen([4 2 1], :);
0194 got = ext2int(mpc, 'xgen', 'gen');
0195 t_is(got.xgen, ex, 12, t);
0196 t = 'mpc = int2ext(mpc, field, ''gen'')';
0197 got = int2ext(got, 'xgen', 'gen');
0198 t_is(got.xgen, mpce.xgen, 12, t);
0199 
0200 t = 'mpc = ext2int(mpc, field, ''gen'', 2)';
0201 ex = mpce.xgen(:, [4 2 1]);
0202 got = ext2int(mpc, 'xgen', 'gen', 2);
0203 t_is(got.xgen, ex, 12, t);
0204 t = 'mpc = int2ext(mpc, field, ''gen'', 2)';
0205 got = int2ext(got, 'xgen', 'gen', 2);
0206 t_is(got.xgen, mpce.xgen, 12, t);
0207 
0208 t = 'mpc = ext2int(mpc, field, ''branch'')';
0209 ex = mpce.xbranch;
0210 ex(7, :) = [];
0211 got = ext2int(mpc, 'xbranch', 'branch');
0212 t_is(got.xbranch, ex, 12, t);
0213 t = 'mpc = int2ext(mpc, field, ''branch'')';
0214 got = int2ext(got, 'xbranch', 'branch');
0215 t_is(got.xbranch, mpce.xbranch, 12, t);
0216 
0217 t = 'mpc = ext2int(mpc, field, ''branch'', 2)';
0218 ex = mpce.xbranch;
0219 ex(:, 7) = [];
0220 got = ext2int(mpc, 'xbranch', 'branch', 2);
0221 t_is(got.xbranch, ex, 12, t);
0222 t = 'mpc = int2ext(mpc, field, ''branch'', 2)';
0223 got = int2ext(got, 'xbranch', 'branch', 2);
0224 t_is(got.xbranch, mpce.xbranch, 12, t);
0225 
0226 t = 'mpc = ext2int(mpc, field, {''branch'', ''gen'', ''bus''})';
0227 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)];
0228 got = ext2int(mpc, 'xrows', {'branch', 'gen', 'bus'});
0229 t_is(got.xrows, ex, 12, t);
0230 t = 'mpc = int2ext(mpc, field, {''branch'', ''gen'', ''bus''})';
0231 got = int2ext(got, 'xrows', {'branch', 'gen', 'bus'});
0232 t_is(got.xrows, mpce.xrows, 12, t);
0233 
0234 t = 'mpc = ext2int(mpc, field, {''branch'', ''gen'', ''bus''}, 2)';
0235 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)]';
0236 got = ext2int(mpc, 'xcols', {'branch', 'gen', 'bus'}, 2);
0237 t_is(got.xcols, ex, 12, t);
0238 t = 'mpc = int2ext(mpc, field, {''branch'', ''gen'', ''bus''})';
0239 got = int2ext(got, 'xcols', {'branch', 'gen', 'bus'}, 2);
0240 t_is(got.xcols, mpce.xcols, 12, t);
0241 
0242 t = 'mpc = ext2int(mpc, {''field1'', ''field2''}, ordering)';
0243 ex = mpce.x.more([4 2 1], :);
0244 got = ext2int(mpc, {'x', 'more'}, 'gen');
0245 t_is(got.x.more, ex, 12, t);
0246 t = 'mpc = int2ext(mpc, {''field1'', ''field2''}, ordering)';
0247 got = int2ext(got, {'x', 'more'}, 'gen');
0248 t_is(got.x.more, mpce.x.more, 12, t);
0249 
0250 t = 'mpc = ext2int(mpc, {''field1'', ''field2''}, ordering, 2)';
0251 ex = mpce.x.more(:, [4 2 1]);
0252 got = ext2int(mpc, {'x', 'more'}, 'gen', 2);
0253 t_is(got.x.more, ex, 12, t);
0254 t = 'mpc = int2ext(mpc, {''field1'', ''field2''}, ordering, 2)';
0255 got = int2ext(got, {'x', 'more'}, 'gen', 2);
0256 t_is(got.x.more, mpce.x.more, 12, t);
0257 
0258 %%-----  more mpc = ext2int/int2ext(mpc)  -----
0259 t = 'mpc = ext2int(mpc) - bus/gen/branch only : ';
0260 mpce = loadcase('t_case_ext');
0261 mpci = loadcase('t_case_int');
0262 mpce = rmfield(mpce, 'gencost');
0263 mpce = rmfield(mpce, 'areas');
0264 mpce = rmfield(mpce, 'A');
0265 mpce = rmfield(mpce, 'N');
0266 mpci = rmfield(mpci, 'gencost');
0267 mpci = rmfield(mpci, 'areas');
0268 mpci = rmfield(mpci, 'A');
0269 mpci = rmfield(mpci, 'N');
0270 mpc = ext2int(mpce);
0271 t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0272 t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0273 t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0274 
0275 t = 'mpc = ext2int(mpc) - no areas/A : ';
0276 mpce = loadcase('t_case_ext');
0277 mpci = loadcase('t_case_int');
0278 mpce = rmfield(mpce, 'areas');
0279 mpce = rmfield(mpce, 'A');
0280 mpci = rmfield(mpci, 'areas');
0281 mpci = rmfield(mpci, 'A');
0282 mpc = ext2int(mpce);
0283 t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0284 t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0285 t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0286 t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0287 t_is(mpc.N, mpci.N, 12, [t 'N']);
0288 
0289 t = 'mpc = ext2int(mpc) - Qg cost, no N : ';
0290 mpce = loadcase('t_case_ext');
0291 mpci = loadcase('t_case_int');
0292 mpce = rmfield(mpce, 'N');
0293 mpci = rmfield(mpci, 'N');
0294 mpce.gencost = [mpce.gencost; mpce.gencost];
0295 mpci.gencost = [mpci.gencost; mpci.gencost];
0296 mpc = ext2int(mpce);
0297 t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0298 t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0299 t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0300 t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0301 t_is(mpc.areas, mpci.areas, 12, [t 'areas']);
0302 t_is(mpc.A, mpci.A, 12, [t 'A']);
0303 
0304 t = 'mpc = ext2int(mpc) - A, N are DC sized : ';
0305 mpce = loadcase('t_case_ext');
0306 mpci = loadcase('t_case_int');
0307 eVmQgcols = [11:20 25:28]';
0308 iVmQgcols = [10:18 22:24]';
0309 mpce.A(:, eVmQgcols) = [];
0310 mpce.N(:, eVmQgcols) = [];
0311 mpci.A(:, iVmQgcols) = [];
0312 mpci.N(:, iVmQgcols) = [];
0313 mpc = ext2int(mpce);
0314 t_is(mpc.bus, mpci.bus, 12, [t 'bus']);
0315 t_is(mpc.branch, mpci.branch, 12, [t 'branch']);
0316 t_is(mpc.gen, mpci.gen, 12, [t 'gen']);
0317 t_is(mpc.gencost, mpci.gencost, 12, [t 'gencost']);
0318 t_is(mpc.areas, mpci.areas, 12, [t 'areas']);
0319 t_is(mpc.A, mpci.A, 12, [t 'A']);
0320 t_is(mpc.N, mpci.N, 12, [t 'N']);
0321 t = 'mpc = int2ext(mpc) - A, N are DC sized : ';
0322 mpc = int2ext(mpc);
0323 t_is(mpc.bus, mpce.bus, 12, [t 'bus']);
0324 t_is(mpc.branch, mpce.branch, 12, [t 'branch']);
0325 t_is(mpc.gen, mpce.gen, 12, [t 'gen']);
0326 t_is(mpc.gencost, mpce.gencost, 12, [t 'gencost']);
0327 t_is(mpc.areas, mpce.areas, 12, [t 'areas']);
0328 t_is(mpc.A, mpce.A, 12, [t 'A']);
0329 t_is(mpc.N, mpce.N, 12, [t 'N']);
0330 
0331 t_end;

Generated on Mon 26-Jan-2015 14:56:45 by m2html © 2005