Home > matpower5.0 > t > t_islands.m

t_islands

PURPOSE ^

T_ISLANDS Tests for FIND_ISLANDS, EXTRACT_ISLANDS, CONNECTED_COMPONENTS and CASE_INFO.

SYNOPSIS ^

function t_islands(quiet)

DESCRIPTION ^

T_ISLANDS  Tests for FIND_ISLANDS, EXTRACT_ISLANDS, CONNECTED_COMPONENTS and CASE_INFO.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_islands(quiet)
0002 %T_ISLANDS  Tests for FIND_ISLANDS, EXTRACT_ISLANDS, CONNECTED_COMPONENTS and CASE_INFO.
0003 
0004 %   MATPOWER
0005 %   $Id: t_islands.m 2468 2014-12-15 16:22:31Z ray $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2012, 2014 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 num_tests = 236;
0038 
0039 t_begin(num_tests, quiet);
0040 
0041 %% define named indices into data matrices
0042 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0043     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0044 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0045     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0046     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0047 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0048     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0049     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0050 
0051 if quiet
0052     verbose = 0;
0053 else
0054     verbose = 0;
0055 end
0056 
0057 %% load cases
0058 casenames = {'case118', 'case30', 'case14', 'case9'};
0059 n = length(casenames);
0060 for k = 1:n
0061     mpc{k} = loadcase(casenames{k});
0062     
0063     %% add bus names
0064     nb = size(mpc{k}.bus, 1);
0065     mpc{k}.bus_name = cell(nb, 1);
0066     for b = 1:nb
0067         mpc{k}.bus_name{b} = sprintf('bus %d', mpc{k}.bus(b, BUS_I));
0068     end
0069     
0070     %% add gen emission.rate, genid
0071     ng = size(mpc{k}.gen, 1);
0072     mpc{k}.emission.rate = zeros(ng, 3);
0073     mpc{k}.genid1 = zeros(ng, 2);
0074     mpc{k}.genid2 = zeros(2, ng);
0075     for g = 1:ng
0076         mpc{k}.emission.rate(g,:) = g * [1 2 3];
0077         mpc{k}.genid1(g, :) = [g  mpc{k}.gen(g, PMAX)];
0078         mpc{k}.genid2(:, g) = [g; mpc{k}.gen(g, PMAX)];
0079     end
0080 end
0081 custom.bus{1} = { 'bus_name' };
0082 custom.gen{1} = { {'emission', 'rate'}, 'genid1' };
0083 custom.gen{2} = { 'genid2' };
0084 custom.branch{2} = { 'nonexistent' };
0085 
0086 % verbose = 2;
0087 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0088 
0089 %% run individual AC PFs
0090 t = 'individual PFs : success ';
0091 for k = 1:n
0092     r{k} = runpf(mpc{k}, mpopt);
0093     t_ok(r{k}.success, sprintf('%s %d', t, k));
0094 end
0095 
0096 %% stack the systems into one
0097 for k = 1:n
0098     offset = k * 1000;
0099     mpc{k}.bus(:, BUS_I)    = mpc{k}.bus(:, BUS_I)  + offset;
0100     mpc{k}.gen(:, GEN_BUS)  = mpc{k}.gen(:, GEN_BUS)    + offset;
0101     mpc{k}.branch(:, F_BUS) = mpc{k}.branch(:, F_BUS)   + offset;
0102     mpc{k}.branch(:, T_BUS) = mpc{k}.branch(:, T_BUS)   + offset;
0103 end
0104 
0105 mpc0 = mpc{1};
0106 for k = 2:n
0107     mpc0.bus        = [mpc0.bus;    mpc{k}.bus];
0108     mpc0.gen        = [mpc0.gen;    mpc{k}.gen];
0109     mpc0.branch     = [mpc0.branch; mpc{k}.branch];
0110     mpc0.gencost    = [mpc0.gencost; mpc{k}.gencost];
0111     
0112     mpc0.bus_name       = [mpc0.bus_name;       mpc{k}.bus_name];
0113     mpc0.emission.rate  = [mpc0.emission.rate;  mpc{k}.emission.rate];
0114     mpc0.genid1         = [mpc0.genid1;         mpc{k}.genid1];
0115     mpc0.genid2         = [mpc0.genid2          mpc{k}.genid2];
0116 end
0117 
0118 %% run AC OPF
0119 t = 'joint PF : ';
0120 r0 = runpf(mpc0, mpopt);
0121 t_ok(r0.success, [t 'success']);
0122 
0123 refs = find(mpc0.bus(:, BUS_TYPE) == REF);
0124 for k = 1:n
0125     ref = find(mpc{k}.bus(:, BUS_TYPE) == REF);
0126     gref0 = find(  mpc0.gen(:, GEN_BUS) ==   mpc0.bus(refs(k), BUS_I));
0127     gref  = find(mpc{k}.gen(:, GEN_BUS) == mpc{k}.bus(    ref, BUS_I));
0128 
0129     t_is(mpc0.gen(gref0, PG), mpc{k}.gen(gref, PG), 8, sprintf('%sslack PG %d', t, k));
0130 end
0131 
0132 %% extract the islands
0133 t = 'mpcs = extract_islands(mpc) : ';
0134 mpc1 = extract_islands(mpc0);
0135 t_ok(iscell(mpc1), [t 'iscell(mpcs)']);
0136 t_is(length(mpc1), n, 10, [t 'length(mpcs) == n']);
0137 for k = 1:n
0138     t_is(mpc1{k}.bus,     mpc{k}.bus,     10, sprintf('%smpcs{%d}.bus', t, k));
0139     t_is(mpc1{k}.gen,     mpc{k}.gen,     10, sprintf('%smpcs{%d}.gen', t, k));
0140     t_is(mpc1{k}.branch,  mpc{k}.branch,  10, sprintf('%smpcs{%d}.branch', t, k));
0141     t_is(mpc1{k}.gencost, mpc{k}.gencost, 10, sprintf('%smpcs{%d}.gencost', t, k));
0142     t_is(length(mpc1{k}.bus_name), length(mpc0.bus_name), 10, sprintf('%smpcs{%d}.bus_name dim', t, k));
0143     t_is(mpc1{k}.emission.rate, mpc0.emission.rate,     10, sprintf('%smpcs{%d}.emission.rate', t, k));
0144     t_is(mpc1{k}.genid1,        mpc0.genid1,            10, sprintf('%smpcs{%d}.genid1', t, k));
0145     t_is(mpc1{k}.genid2,        mpc0.genid2,            10, sprintf('%smpcs{%d}.genid2', t, k));
0146 end
0147 
0148 %% extract the islands, with custom fields
0149 t = 'mpcs = extract_islands(mpc, [], custom) : ';
0150 mpc1 = extract_islands(mpc0, [], custom);
0151 %mpc1 = extract_islands(mpc0, {}, [], custom);  %% this should work too
0152 t_ok(iscell(mpc1), [t 'iscell(mpcs)']);
0153 t_is(length(mpc1), n, 10, [t 'length(mpcs) == n']);
0154 for k = 1:n
0155     t_is(mpc1{k}.bus,     mpc{k}.bus,     10, sprintf('%smpcs{%d}.bus', t, k));
0156     t_is(mpc1{k}.gen,     mpc{k}.gen,     10, sprintf('%smpcs{%d}.gen', t, k));
0157     t_is(mpc1{k}.branch,  mpc{k}.branch,  10, sprintf('%smpcs{%d}.branch', t, k));
0158     t_is(mpc1{k}.gencost, mpc{k}.gencost, 10, sprintf('%smpcs{%d}.gencost', t, k));
0159     t_is(length(mpc1{k}.bus_name), length(mpc{k}.bus_name), 10, sprintf('%smpcs{%d}.bus_name dim', t, k));
0160     t_is(mpc1{k}.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpcs{%d}.emission.rate', t, k));
0161     t_is(mpc1{k}.genid1,        mpc{k}.genid1,            10, sprintf('%smpcs{%d}.genid1', t, k));
0162     t_is(mpc1{k}.genid2,        mpc{k}.genid2,            10, sprintf('%smpcs{%d}.genid2', t, k));
0163 end
0164 
0165 %% extract single island
0166 t = 'mpc3 = extract_islands(mpc, 3) : ';
0167 mpc3 = extract_islands(mpc0, 3);
0168 t_ok(isstruct(mpc3), [t 'isstruct(mpc3)']);
0169 k = 3;
0170 t_is(mpc3.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0171 t_is(mpc3.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0172 t_is(mpc3.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0173 t_is(mpc3.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0174 t_is(length(mpc3.bus_name), length(mpc0.bus_name), 10, sprintf('%smpc%d.bus_name dim', t, k));
0175 t_is(mpc3.emission.rate, mpc0.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0176 t_is(mpc3.genid1,        mpc0.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0177 t_is(mpc3.genid2,        mpc0.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0178 
0179 %% extract single island, with custom fields
0180 t = 'mpc3 = extract_islands(mpc, 3, custom) : ';
0181 mpc3 = extract_islands(mpc0, 3, custom);
0182 t_ok(isstruct(mpc3), [t 'isstruct(mpc3)']);
0183 k = 3;
0184 t_is(mpc3.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0185 t_is(mpc3.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0186 t_is(mpc3.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0187 t_is(mpc3.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0188 t_is(length(mpc3.bus_name), length(mpc{k}.bus_name), 10, sprintf('%smpc%d.bus_name dim', t, k));
0189 t_is(mpc3.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0190 t_is(mpc3.genid1,        mpc{k}.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0191 t_is(mpc3.genid2,        mpc{k}.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0192 
0193 %% find the islands
0194 t = 'groups = find_islands(mpc) : ';
0195 groups = find_islands(mpc0);
0196 t_ok(iscell(groups), [t 'iscell(groups)']);
0197 t_is(length(groups), n, 10, [t 'length(groups) == n']);
0198 base = 0;
0199 for k = 1:n
0200     nbk = size(mpc{k}.bus, 1);
0201     t_is(groups{k}, base+(1:nbk), 10, [t k]);
0202     base = base + nbk;
0203 end
0204 
0205 %% extract the islands
0206 t = 'mpcs = extract_islands(mpc, groups) : ';
0207 mpc2 = extract_islands(mpc0, groups);
0208 t_ok(iscell(mpc2), [t 'iscell(mpcs)']);
0209 t_is(length(mpc2), n, 10, [t 'length(mpcs) == n']);
0210 for k = 1:n
0211     t_is(mpc2{k}.bus,     mpc{k}.bus,     10, sprintf('%smpcs{%d}.bus', t, k));
0212     t_is(mpc2{k}.gen,     mpc{k}.gen,     10, sprintf('%smpcs{%d}.gen', t, k));
0213     t_is(mpc2{k}.branch,  mpc{k}.branch,  10, sprintf('%smpcs{%d}.branch', t, k));
0214     t_is(mpc2{k}.gencost, mpc{k}.gencost, 10, sprintf('%smpcs{%d}.gencost', t, k));
0215     t_is(length(mpc2{k}.bus_name), length(mpc0.bus_name), 10, sprintf('%smpcs{%d}.bus_name dim', t, k));
0216     t_is(mpc2{k}.emission.rate, mpc0.emission.rate,     10, sprintf('%smpcs{%d}.emission.rate', t, k));
0217     t_is(mpc2{k}.genid1,        mpc0.genid1,            10, sprintf('%smpcs{%d}.genid1', t, k));
0218     t_is(mpc2{k}.genid2,        mpc0.genid2,            10, sprintf('%smpcs{%d}.genid2', t, k));
0219 end
0220 
0221 %% extract the islands, with custom fields
0222 t = 'mpcs = extract_islands(mpc, groups, [], custom) : ';
0223 mpc2 = extract_islands(mpc0, groups, [], custom);
0224 t_ok(iscell(mpc2), [t 'iscell(mpcs)']);
0225 t_is(length(mpc2), n, 10, [t 'length(mpcs) == n']);
0226 for k = 1:n
0227     t_is(mpc2{k}.bus,     mpc{k}.bus,     10, sprintf('%smpcs{%d}.bus', t, k));
0228     t_is(mpc2{k}.gen,     mpc{k}.gen,     10, sprintf('%smpcs{%d}.gen', t, k));
0229     t_is(mpc2{k}.branch,  mpc{k}.branch,  10, sprintf('%smpcs{%d}.branch', t, k));
0230     t_is(mpc2{k}.gencost, mpc{k}.gencost, 10, sprintf('%smpcs{%d}.gencost', t, k));
0231     t_is(length(mpc2{k}.bus_name), length(mpc{k}.bus_name), 10, sprintf('%smpcs{%d}.bus_name dim', t, k));
0232     t_is(mpc2{k}.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpcs{%d}.emission.rate', t, k));
0233     t_is(mpc2{k}.genid1,        mpc{k}.genid1,            10, sprintf('%smpcs{%d}.genid1', t, k));
0234     t_is(mpc2{k}.genid2,        mpc{k}.genid2,            10, sprintf('%smpcs{%d}.genid2', t, k));
0235 end
0236 
0237 %% extract single island
0238 t = 'mpc4 = extract_islands(mpc, groups, 4) : ';
0239 mpc4 = extract_islands(mpc0, groups, 4);
0240 t_ok(isstruct(mpc4), [t 'isstruct(mpc4)']);
0241 k = 4;
0242 t_is(mpc4.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0243 t_is(mpc4.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0244 t_is(mpc4.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0245 t_is(mpc4.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0246 t_is(length(mpc4.bus_name), length(mpc0.bus_name), 10, sprintf('%smpc%d.bus_name dim', t, k));
0247 t_is(mpc4.emission.rate, mpc0.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0248 t_is(mpc4.genid1,        mpc0.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0249 t_is(mpc4.genid2,        mpc0.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0250 
0251 %% extract single island, with custom fields
0252 t = 'mpc4 = extract_islands(mpc, groups, 4, custom) : ';
0253 mpc4 = extract_islands(mpc0, groups, 4, custom);
0254 t_ok(isstruct(mpc4), [t 'isstruct(mpc4)']);
0255 k = 4;
0256 t_is(mpc4.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0257 t_is(mpc4.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0258 t_is(mpc4.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0259 t_is(mpc4.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0260 t_is(length(mpc4.bus_name), length(mpc{k}.bus_name), 10, sprintf('%smpc%d.bus_name dim', t, k));
0261 t_is(mpc4.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0262 t_is(mpc4.genid1,        mpc{k}.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0263 t_is(mpc4.genid2,        mpc{k}.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0264 
0265 %% extract 2 islands as single case
0266 t = 'mpc13 = extract_islands(mpc, [1;3]) : ';
0267 mpc13 = extract_islands(mpc0, [1;3]);
0268 mpc1 = extract_islands(mpc13, 1);
0269 mpc3 = extract_islands(mpc13, 2);
0270 k = 1;
0271 t_is(mpc1.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0272 t_is(mpc1.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0273 t_is(mpc1.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0274 t_is(mpc1.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0275 t_is(length(mpc1.bus_name), length(mpc0.bus_name), 10, sprintf('%smpc%d.bus_name dim', t, k));
0276 t_is(mpc1.emission.rate, mpc0.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0277 t_is(mpc1.genid1,        mpc0.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0278 t_is(mpc1.genid2,        mpc0.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0279 k = 3;
0280 t_is(mpc3.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0281 t_is(mpc3.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0282 t_is(mpc3.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0283 t_is(mpc3.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0284 t_is(length(mpc3.bus_name), length(mpc0.bus_name), 10, sprintf('%smpc%d.bus_name dim', t, k));
0285 t_is(mpc3.emission.rate, mpc0.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0286 t_is(mpc3.genid1,        mpc0.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0287 t_is(mpc3.genid2,        mpc0.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0288 
0289 %% extract 2 islands as single case, with custom fields
0290 t = 'mpc13 = extract_islands(mpc, [1;3], custom) : ';
0291 mpc13 = extract_islands(mpc0, [1;3], custom);
0292 mpc1 = extract_islands(mpc13, 1, custom);
0293 mpc3 = extract_islands(mpc13, 2, custom);
0294 k = 1;
0295 t_is(mpc1.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0296 t_is(mpc1.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0297 t_is(mpc1.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0298 t_is(mpc1.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0299 t_is(length(mpc1.bus_name), length(mpc{k}.bus_name), 10, sprintf('%smpc%d.bus_name dim', t, k));
0300 t_is(mpc1.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0301 t_is(mpc1.genid1,        mpc{k}.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0302 t_is(mpc1.genid2,        mpc{k}.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0303 k = 3;
0304 t_is(mpc3.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0305 t_is(mpc3.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0306 t_is(mpc3.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0307 t_is(mpc3.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0308 t_is(length(mpc3.bus_name), length(mpc{k}.bus_name), 10, sprintf('%smpc%d.bus_name dim', t, k));
0309 t_is(mpc3.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0310 t_is(mpc3.genid1,        mpc{k}.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0311 t_is(mpc3.genid2,        mpc{k}.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0312 
0313 %% case_info
0314 got_fname = sprintf('%s_%d.txt', 't_case_info_eg', fix(1e9*rand));
0315 exp_fname = sprintf('t_case_info_eg.txt');
0316 t = '[groups, isolated] = case_info(mpc) : ';
0317 [fd, msg] = fopen(got_fname, 'at');
0318 if fd == -1
0319     error(msg);
0320 else
0321     [groups, isolated] = case_info(mpc0, fd);
0322     fclose(fd);
0323 end
0324 t_ok(iscell(groups), [t 'iscell(groups)']);
0325 t_is(length(groups), n, 10, [t 'length(groups) == n']);
0326 base = 0;
0327 for k = 1:n
0328     nbk = size(mpc{k}.bus, 1);
0329     t_is(groups{k}, base+(1:nbk), 10, [t num2str(k)]);
0330     base = base + nbk;
0331 end
0332 got = fileread(got_fname);
0333 expected = fileread(exp_fname);
0334 if size(got, 1) ~= 1    %% transpose if needed for Octave 3.4
0335     got = got';
0336 end
0337 if size(expected, 1) ~= 1   %% transpose if needed for Octave 3.4
0338     expected = expected';
0339 end
0340 delete(got_fname);
0341 got = strrep(got, char([13 10]), char(10));             %% Win to Unix EOL chars
0342 got = regexprep(got, 'Elapsed time is (.*) seconds', 'Elapsed time is 0.00 seconds');
0343 expected = strrep(expected, char([13 10]), char(10));   %% Win to Unix EOL chars
0344 t_ok(strcmp(got, expected), [t 'text output']);
0345 
0346 t = '[groups, isolated] = find_islands(mpc) : ';
0347 mpc = loadcase('case30');
0348 mpc.branch(25, BR_STATUS) = 0;  %% 10-20
0349 mpc.branch(26, BR_STATUS) = 0;  %% 10-17
0350 mpc.branch(13, BR_STATUS) = 0;  %%  9-11, isolates bus 11
0351 mpc.branch(15, BR_STATUS) = 0;  %%  4-12, last tie between areas 1 and 2
0352 mpc.branch(32, BR_STATUS) = 0;  %% 23-24, last tie between areaa 2 and 3
0353 mpc.branch(21, BR_STATUS) = 0;  %% 16-17, isolates bus 17
0354 mpc.branch(24, BR_STATUS) = 0;  %% 19-20, isolates bus 20
0355 mpc.branch(12, BR_STATUS) = 0;  %%  6-10, tie between areas 1 and 3
0356 mpc.branch(14, BR_STATUS) = 0;  %%  9-10, tie between areas 1 and 3
0357 mpc.branch(36, BR_STATUS) = 0;  %% 27-28, tie between areas 1 and 3
0358 [groups, isolated] = find_islands(mpc);
0359 t_ok(iscell(groups), [t 'iscell(groups)']);
0360 t_is(length(groups), 3, 10, [t 'length(groups) == 3']);
0361 t_is(isolated, [11 17 20], 10, [t 'isolated']);
0362 t_is(sort([11     groups{1}]), find(mpc.bus(:, BUS_AREA) == 1)', 10, [t 'groups{1}']);
0363 t_is(             groups{2},   find(mpc.bus(:, BUS_AREA) == 3)', 10, [t 'groups{2}']);
0364 t_is(sort([17 20  groups{3}]), find(mpc.bus(:, BUS_AREA) == 2)', 10, [t 'groups{3}']);
0365 
0366 %% extract 2 islands as single case
0367 t = 'mpc1 = extract_islands(mpc, ''all'') : ';
0368 mpc1 = extract_islands(mpc, 'all');
0369 ibr = find( ~ismember(mpc.branch(:, F_BUS), isolated) & ...
0370             ~ismember(mpc.branch(:, T_BUS), isolated) );
0371 ig = find( ~ismember(mpc.gen(:, GEN_BUS), isolated) );
0372 mpc2 = mpc;
0373 mpc2.bus(isolated, :) = [];
0374 mpc2.branch = mpc.branch(ibr, :);
0375 mpc2.gen    = mpc.gen(ig, :);
0376 mpc2.gencost = mpc.gencost(ig, :);
0377 t_is(mpc1.bus,     mpc2.bus,     10, sprintf('%smpc.bus', t));
0378 t_is(mpc1.gen,     mpc2.gen,     10, sprintf('%smpc.gen', t));
0379 t_is(mpc1.branch,  mpc2.branch,  10, sprintf('%smpc.branch', t));
0380 t_is(mpc1.gencost, mpc2.gencost, 10, sprintf('%smpc.gencost', t));
0381 
0382 t_end;

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005