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

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005