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

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