Home > matpower7.1 > lib > 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 https://matpower.org for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 num_tests = 308;
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_feature('octave')
0036     if have_feature('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 %% for MATLAB versions prior to R2012a (v 7.14)
0046 if ~exist('isequaln')
0047     eval('isequaln = @isequalwithequalnans;');
0048 end
0049 
0050 gt = gentypes();
0051 gf = genfuels();
0052 ngt = length(gt);
0053 ngf = length(gf);
0054 
0055 %% load cases
0056 casenames = {'case118', 'case30', 'case14', 'case9'};
0057 n = length(casenames);
0058 for k = 1:n
0059     mpc{k} = loadcase(casenames{k});
0060     
0061     %% add bus names, labels
0062     nb = size(mpc{k}.bus, 1);
0063     mpc{k}.bus_name = cell(nb, 1);
0064     mpc{k}.bus_label = cell(nb, 1);
0065     for b = 1:nb
0066         mpc{k}.bus_name{b} = sprintf('bus %d', mpc{k}.bus(b, BUS_I));
0067         mpc{k}.bus_label{b} = sprintf('--%d--', mpc{k}.bus(b, BUS_I));
0068     end
0069     
0070     %% add gen emission.rate, genid, gentype, genfuel
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     mpc{k}.gentype = cell(ng, 1);
0076     mpc{k}.genfuel = cell(ng, 1);
0077     for g = 1:ng
0078         mpc{k}.emission.rate(g,:) = g * [1 2 3];
0079         mpc{k}.genid1(g, :) = [g  mpc{k}.gen(g, PMAX)];
0080         mpc{k}.genid2(:, g) = [g; mpc{k}.gen(g, PMAX)];
0081         mpc{k}.gentype{g} = gt{mod(g-1, ngt) + 1};
0082         mpc{k}.genfuel{g} = gf{mod(g-1, ngf) + 1};
0083     end
0084 end
0085 custom.bus{1} = { 'bus_label' };
0086 custom.gen{1} = { {'emission', 'rate'}, 'genid1' };
0087 custom.gen{2} = { 'genid2' };
0088 custom.branch{2} = { 'nonexistent' };
0089 
0090 % verbose = 2;
0091 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0092 
0093 %% run individual AC PFs
0094 t = 'individual PFs : success ';
0095 for k = 1:n
0096     r{k} = runpf(mpc{k}, mpopt);
0097     t_ok(r{k}.success, sprintf('%s %d', t, k));
0098 end
0099 
0100 %% stack the systems into one
0101 for k = 1:n
0102     offset = k * 1000;
0103     mpc{k}.bus(:, BUS_I)    = mpc{k}.bus(:, BUS_I)  + offset;
0104     mpc{k}.gen(:, GEN_BUS)  = mpc{k}.gen(:, GEN_BUS)    + offset;
0105     mpc{k}.branch(:, F_BUS) = mpc{k}.branch(:, F_BUS)   + offset;
0106     mpc{k}.branch(:, T_BUS) = mpc{k}.branch(:, T_BUS)   + offset;
0107 end
0108 
0109 mpc0 = mpc{1};
0110 for k = 2:n
0111     mpc0.bus        = [mpc0.bus;    mpc{k}.bus];
0112     mpc0.gen        = [mpc0.gen;    mpc{k}.gen];
0113     mpc0.branch     = [mpc0.branch; mpc{k}.branch];
0114     mpc0.gencost    = [mpc0.gencost; mpc{k}.gencost];
0115     
0116     mpc0.bus_name       = [mpc0.bus_name;       mpc{k}.bus_name];
0117     mpc0.gentype        = [mpc0.gentype;        mpc{k}.gentype];
0118     mpc0.genfuel        = [mpc0.genfuel;        mpc{k}.genfuel];
0119     mpc0.bus_label      = [mpc0.bus_label;      mpc{k}.bus_label];
0120     mpc0.emission.rate  = [mpc0.emission.rate;  mpc{k}.emission.rate];
0121     mpc0.genid1         = [mpc0.genid1;         mpc{k}.genid1];
0122     mpc0.genid2         = [mpc0.genid2          mpc{k}.genid2];
0123 end
0124 
0125 %% run AC OPF
0126 t = 'joint PF : ';
0127 r0 = runpf(mpc0, mpopt);
0128 t_ok(r0.success, [t 'success']);
0129 
0130 refs = find(mpc0.bus(:, BUS_TYPE) == REF);
0131 for k = 1:n
0132     ref = find(mpc{k}.bus(:, BUS_TYPE) == REF);
0133     gref0 = find(  mpc0.gen(:, GEN_BUS) ==   mpc0.bus(refs(k), BUS_I));
0134     gref  = find(mpc{k}.gen(:, GEN_BUS) == mpc{k}.bus(    ref, BUS_I));
0135 
0136     t_is(mpc0.gen(gref0, PG), mpc{k}.gen(gref, PG), 8, sprintf('%sslack PG %d', t, k));
0137 end
0138 
0139 %% extract the islands
0140 t = 'mpcs = extract_islands(mpc) : ';
0141 mpc1 = extract_islands(mpc0);
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_ok(isequaln(mpc1{k}.bus_name, mpc{k}.bus_name), sprintf('%smpcs{%d}.bus_name', t, k));
0150     t_ok(isequaln(mpc1{k}.gentype, mpc{k}.gentype), sprintf('%smpcs{%d}.gentype', t, k));
0151     t_ok(isequaln(mpc1{k}.genfuel, mpc{k}.genfuel), sprintf('%smpcs{%d}.genfuel', t, k));
0152     t_ok(isequaln(mpc1{k}.bus_label, mpc0.bus_label), sprintf('%smpcs{%d}.bus_label', t, k));
0153     t_is(mpc1{k}.emission.rate, mpc0.emission.rate,     10, sprintf('%smpcs{%d}.emission.rate', t, k));
0154     t_is(mpc1{k}.genid1,        mpc0.genid1,            10, sprintf('%smpcs{%d}.genid1', t, k));
0155     t_is(mpc1{k}.genid2,        mpc0.genid2,            10, sprintf('%smpcs{%d}.genid2', t, k));
0156 end
0157 
0158 %% extract the islands, with custom fields
0159 t = 'mpcs = extract_islands(mpc, [], custom) : ';
0160 mpc1 = extract_islands(mpc0, [], custom);
0161 %mpc1 = extract_islands(mpc0, {}, [], custom);  %% this should work too
0162 t_ok(iscell(mpc1), [t 'iscell(mpcs)']);
0163 t_is(length(mpc1), n, 10, [t 'length(mpcs) == n']);
0164 for k = 1:n
0165     t_is(mpc1{k}.bus,     mpc{k}.bus,     10, sprintf('%smpcs{%d}.bus', t, k));
0166     t_is(mpc1{k}.gen,     mpc{k}.gen,     10, sprintf('%smpcs{%d}.gen', t, k));
0167     t_is(mpc1{k}.branch,  mpc{k}.branch,  10, sprintf('%smpcs{%d}.branch', t, k));
0168     t_is(mpc1{k}.gencost, mpc{k}.gencost, 10, sprintf('%smpcs{%d}.gencost', t, k));
0169     t_ok(isequaln(mpc1{k}.bus_name, mpc{k}.bus_name), sprintf('%smpcs{%d}.bus_name', t, k));
0170     t_ok(isequaln(mpc1{k}.gentype, mpc{k}.gentype), sprintf('%smpcs{%d}.gentype', t, k));
0171     t_ok(isequaln(mpc1{k}.genfuel, mpc{k}.genfuel), sprintf('%smpcs{%d}.genfuel', t, k));
0172     t_ok(isequaln(mpc1{k}.bus_label, mpc{k}.bus_label), sprintf('%smpcs{%d}.bus_label', t, k));
0173     t_is(mpc1{k}.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpcs{%d}.emission.rate', t, k));
0174     t_is(mpc1{k}.genid1,        mpc{k}.genid1,            10, sprintf('%smpcs{%d}.genid1', t, k));
0175     t_is(mpc1{k}.genid2,        mpc{k}.genid2,            10, sprintf('%smpcs{%d}.genid2', t, k));
0176 end
0177 
0178 %% extract single island
0179 t = 'mpc3 = extract_islands(mpc, 3) : ';
0180 mpc3 = extract_islands(mpc0, 3);
0181 t_ok(isstruct(mpc3), [t 'isstruct(mpc3)']);
0182 k = 3;
0183 t_is(mpc3.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0184 t_is(mpc3.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0185 t_is(mpc3.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0186 t_is(mpc3.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0187 t_ok(isequaln(mpc3.bus_name, mpc{k}.bus_name), sprintf('%smpc%d.bus_name', t, k));
0188 t_ok(isequaln(mpc3.gentype, mpc{k}.gentype), sprintf('%smpc%d.gentype', t, k));
0189 t_ok(isequaln(mpc3.genfuel, mpc{k}.genfuel), sprintf('%smpc%d.genfuel', t, k));
0190 t_ok(isequaln(mpc3.bus_label, mpc0.bus_label), sprintf('%smpc%d.bus_label', t, k));
0191 t_is(mpc3.emission.rate, mpc0.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0192 t_is(mpc3.genid1,        mpc0.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0193 t_is(mpc3.genid2,        mpc0.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0194 
0195 %% extract single island, with custom fields
0196 t = 'mpc3 = extract_islands(mpc, 3, custom) : ';
0197 mpc3 = extract_islands(mpc0, 3, custom);
0198 t_ok(isstruct(mpc3), [t 'isstruct(mpc3)']);
0199 k = 3;
0200 t_is(mpc3.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0201 t_is(mpc3.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0202 t_is(mpc3.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0203 t_is(mpc3.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0204 t_ok(isequaln(mpc3.bus_name, mpc{k}.bus_name), sprintf('%smpc%d.bus_name', t, k));
0205 t_ok(isequaln(mpc3.gentype, mpc{k}.gentype), sprintf('%smpc%d.gentype', t, k));
0206 t_ok(isequaln(mpc3.genfuel, mpc{k}.genfuel), sprintf('%smpc%d.genfuel', t, k));
0207 t_ok(isequaln(mpc3.bus_label, mpc{k}.bus_label), sprintf('%smpc%d.bus_label', t, k));
0208 t_is(mpc3.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0209 t_is(mpc3.genid1,        mpc{k}.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0210 t_is(mpc3.genid2,        mpc{k}.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0211 
0212 %% find the islands
0213 t = 'groups = find_islands(mpc) : ';
0214 groups = find_islands(mpc0);
0215 t_ok(iscell(groups), [t 'iscell(groups)']);
0216 t_is(length(groups), n, 10, [t 'length(groups) == n']);
0217 base = 0;
0218 for k = 1:n
0219     nbk = size(mpc{k}.bus, 1);
0220     t_is(groups{k}, base+(1:nbk), 10, sprintf('%s%d', t, k));
0221     base = base + nbk;
0222 end
0223 
0224 %% extract the islands
0225 t = 'mpcs = extract_islands(mpc, groups) : ';
0226 mpc2 = extract_islands(mpc0, groups);
0227 t_ok(iscell(mpc2), [t 'iscell(mpcs)']);
0228 t_is(length(mpc2), n, 10, [t 'length(mpcs) == n']);
0229 for k = 1:n
0230     t_is(mpc2{k}.bus,     mpc{k}.bus,     10, sprintf('%smpcs{%d}.bus', t, k));
0231     t_is(mpc2{k}.gen,     mpc{k}.gen,     10, sprintf('%smpcs{%d}.gen', t, k));
0232     t_is(mpc2{k}.branch,  mpc{k}.branch,  10, sprintf('%smpcs{%d}.branch', t, k));
0233     t_is(mpc2{k}.gencost, mpc{k}.gencost, 10, sprintf('%smpcs{%d}.gencost', t, k));
0234     t_ok(isequaln(mpc2{k}.bus_name, mpc{k}.bus_name), sprintf('%smpcs{%d}.bus_name', t, k));
0235     t_ok(isequaln(mpc2{k}.gentype, mpc{k}.gentype), sprintf('%smpcs{%d}.gentype', t, k));
0236     t_ok(isequaln(mpc2{k}.genfuel, mpc{k}.genfuel), sprintf('%smpcs{%d}.genfuel', t, k));
0237     t_ok(isequaln(mpc2{k}.bus_label, mpc0.bus_label), sprintf('%smpcs{%d}.bus_label', t, k));
0238     t_is(mpc2{k}.emission.rate, mpc0.emission.rate,     10, sprintf('%smpcs{%d}.emission.rate', t, k));
0239     t_is(mpc2{k}.genid1,        mpc0.genid1,            10, sprintf('%smpcs{%d}.genid1', t, k));
0240     t_is(mpc2{k}.genid2,        mpc0.genid2,            10, sprintf('%smpcs{%d}.genid2', t, k));
0241 end
0242 
0243 %% extract the islands, with custom fields
0244 t = 'mpcs = extract_islands(mpc, groups, [], custom) : ';
0245 mpc2 = extract_islands(mpc0, groups, [], custom);
0246 t_ok(iscell(mpc2), [t 'iscell(mpcs)']);
0247 t_is(length(mpc2), n, 10, [t 'length(mpcs) == n']);
0248 for k = 1:n
0249     t_is(mpc2{k}.bus,     mpc{k}.bus,     10, sprintf('%smpcs{%d}.bus', t, k));
0250     t_is(mpc2{k}.gen,     mpc{k}.gen,     10, sprintf('%smpcs{%d}.gen', t, k));
0251     t_is(mpc2{k}.branch,  mpc{k}.branch,  10, sprintf('%smpcs{%d}.branch', t, k));
0252     t_is(mpc2{k}.gencost, mpc{k}.gencost, 10, sprintf('%smpcs{%d}.gencost', t, k));
0253     t_ok(isequaln(mpc2{k}.bus_name, mpc{k}.bus_name), sprintf('%smpcs{%d}.bus_name', t, k));
0254     t_ok(isequaln(mpc2{k}.gentype, mpc{k}.gentype), sprintf('%smpcs{%d}.gentype', t, k));
0255     t_ok(isequaln(mpc2{k}.genfuel, mpc{k}.genfuel), sprintf('%smpcs{%d}.genfuel', t, k));
0256     t_ok(isequaln(mpc2{k}.bus_label, mpc{k}.bus_label), sprintf('%smpcs{%d}.bus_label', t, k));
0257     t_is(mpc2{k}.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpcs{%d}.emission.rate', t, k));
0258     t_is(mpc2{k}.genid1,        mpc{k}.genid1,            10, sprintf('%smpcs{%d}.genid1', t, k));
0259     t_is(mpc2{k}.genid2,        mpc{k}.genid2,            10, sprintf('%smpcs{%d}.genid2', t, k));
0260 end
0261 
0262 %% extract single island
0263 t = 'mpc4 = extract_islands(mpc, groups, 4) : ';
0264 mpc4 = extract_islands(mpc0, groups, 4);
0265 t_ok(isstruct(mpc4), [t 'isstruct(mpc4)']);
0266 k = 4;
0267 t_is(mpc4.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0268 t_is(mpc4.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0269 t_is(mpc4.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0270 t_is(mpc4.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0271 t_ok(isequaln(mpc4.bus_name, mpc{k}.bus_name), sprintf('%smpc%d.bus_name', t, k));
0272 t_ok(isequaln(mpc4.gentype, mpc{k}.gentype), sprintf('%smpc%d.gentype', t, k));
0273 t_ok(isequaln(mpc4.genfuel, mpc{k}.genfuel), sprintf('%smpc%d.genfuel', t, k));
0274 t_ok(isequaln(mpc4.bus_label, mpc0.bus_label), sprintf('%smpc%d.bus_label', t, k));
0275 t_is(mpc4.emission.rate, mpc0.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0276 t_is(mpc4.genid1,        mpc0.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0277 t_is(mpc4.genid2,        mpc0.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0278 
0279 %% extract single island, with custom fields
0280 t = 'mpc4 = extract_islands(mpc, groups, 4, custom) : ';
0281 mpc4 = extract_islands(mpc0, groups, 4, custom);
0282 t_ok(isstruct(mpc4), [t 'isstruct(mpc4)']);
0283 k = 4;
0284 t_is(mpc4.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0285 t_is(mpc4.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0286 t_is(mpc4.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0287 t_is(mpc4.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0288 t_ok(isequal(mpc4.bus_name, mpc{k}.bus_name), sprintf('%smpc%d.bus_name', t, k));
0289 t_ok(isequal(mpc4.gentype, mpc{k}.gentype), sprintf('%smpc%d.gentype', t, k));
0290 t_ok(isequal(mpc4.genfuel, mpc{k}.genfuel), sprintf('%smpc%d.genfuel', t, k));
0291 t_ok(isequal(mpc4.bus_label, mpc{k}.bus_label), sprintf('%smpc%d.bus_label', t, k));
0292 t_is(mpc4.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0293 t_is(mpc4.genid1,        mpc{k}.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0294 t_is(mpc4.genid2,        mpc{k}.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0295 
0296 %% extract 2 islands as single case
0297 t = 'mpc13 = extract_islands(mpc, [1;3]) : ';
0298 mpc13 = extract_islands(mpc0, [1;3]);
0299 mpc1 = extract_islands(mpc13, 1);
0300 mpc3 = extract_islands(mpc13, 2);
0301 k = 1;
0302 t_is(mpc1.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0303 t_is(mpc1.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0304 t_is(mpc1.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0305 t_is(mpc1.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0306 t_ok(isequal(mpc1.bus_name, mpc{k}.bus_name), sprintf('%smpc%d.bus_name', t, k));
0307 t_ok(isequal(mpc1.gentype, mpc{k}.gentype), sprintf('%smpc%d.gentype', t, k));
0308 t_ok(isequal(mpc1.genfuel, mpc{k}.genfuel), sprintf('%smpc%d.genfuel', t, k));
0309 t_ok(isequal(mpc1.bus_label, mpc0.bus_label), sprintf('%smpc%d.bus_label', t, k));
0310 t_is(mpc1.emission.rate, mpc0.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0311 t_is(mpc1.genid1,        mpc0.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0312 t_is(mpc1.genid2,        mpc0.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0313 k = 3;
0314 t_is(mpc3.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0315 t_is(mpc3.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0316 t_is(mpc3.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0317 t_is(mpc3.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0318 t_ok(isequaln(mpc3.bus_name, mpc{k}.bus_name), sprintf('%smpc%d.bus_name', t, k));
0319 t_ok(isequaln(mpc3.gentype, mpc{k}.gentype), sprintf('%smpc%d.gentype', t, k));
0320 t_ok(isequaln(mpc3.genfuel, mpc{k}.genfuel), sprintf('%smpc%d.genfuel', t, k));
0321 t_ok(isequaln(mpc3.bus_label, mpc0.bus_label), sprintf('%smpc%d.bus_label', t, k));
0322 t_is(mpc3.emission.rate, mpc0.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0323 t_is(mpc3.genid1,        mpc0.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0324 t_is(mpc3.genid2,        mpc0.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0325 
0326 %% extract 2 islands as single case, with custom fields
0327 t = 'mpc13 = extract_islands(mpc, [1;3], custom) : ';
0328 mpc13 = extract_islands(mpc0, [1;3], custom);
0329 mpc1 = extract_islands(mpc13, 1, custom);
0330 mpc3 = extract_islands(mpc13, 2, custom);
0331 k = 1;
0332 t_is(mpc1.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0333 t_is(mpc1.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0334 t_is(mpc1.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0335 t_is(mpc1.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0336 t_ok(isequaln(mpc1.bus_name, mpc{k}.bus_name), sprintf('%smpc%d.bus_name', t, k));
0337 t_ok(isequaln(mpc1.gentype, mpc{k}.gentype), sprintf('%smpc%d.gentype', t, k));
0338 t_ok(isequaln(mpc1.genfuel, mpc{k}.genfuel), sprintf('%smpc%d.genfuel', t, k));
0339 t_ok(isequaln(mpc1.bus_label, mpc{k}.bus_label), sprintf('%smpc%d.bus_label', t, k));
0340 t_is(mpc1.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0341 t_is(mpc1.genid1,        mpc{k}.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0342 t_is(mpc1.genid2,        mpc{k}.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0343 k = 3;
0344 t_is(mpc3.bus,     mpc{k}.bus,     10, sprintf('%smpc%d.bus', t, k));
0345 t_is(mpc3.gen,     mpc{k}.gen,     10, sprintf('%smpc%d.gen', t, k));
0346 t_is(mpc3.branch,  mpc{k}.branch,  10, sprintf('%smpc%d.branch', t, k));
0347 t_is(mpc3.gencost, mpc{k}.gencost, 10, sprintf('%smpc%d.gencost', t, k));
0348 t_ok(isequaln(mpc3.bus_name, mpc{k}.bus_name), sprintf('%smpc%d.bus_name', t, k));
0349 t_ok(isequaln(mpc3.gentype, mpc{k}.gentype), sprintf('%smpc%d.gentype', t, k));
0350 t_ok(isequaln(mpc3.genfuel, mpc{k}.genfuel), sprintf('%smpc%d.genfuel', t, k));
0351 t_ok(isequaln(mpc3.bus_label, mpc{k}.bus_label), sprintf('%smpc%d.bus_label', t, k));
0352 t_is(mpc3.emission.rate, mpc{k}.emission.rate,     10, sprintf('%smpc%d.emission.rate', t, k));
0353 t_is(mpc3.genid1,        mpc{k}.genid1,            10, sprintf('%smpc%d.genid1', t, k));
0354 t_is(mpc3.genid2,        mpc{k}.genid2,            10, sprintf('%smpc%d.genid2', t, k));
0355 
0356 %% case_info
0357 got_fname = sprintf('%s_%d.txt', 't_case_info_eg', fix(1e9*rand));
0358 exp_fname = sprintf('t_case_info_eg.txt');
0359 t = '[groups, isolated] = case_info(mpc) : ';
0360 [fd, msg] = fopen(got_fname, 'at');
0361 if fd == -1
0362     error(msg);
0363 else
0364     [groups, isolated] = case_info(mpc0, fd);
0365     fclose(fd);
0366 end
0367 t_ok(iscell(groups), [t 'iscell(groups)']);
0368 t_is(length(groups), n, 10, [t 'length(groups) == n']);
0369 base = 0;
0370 for k = 1:n
0371     nbk = size(mpc{k}.bus, 1);
0372     t_is(groups{k}, base+(1:nbk), 10, [t num2str(k)]);
0373     base = base + nbk;
0374 end
0375 got = fileread(got_fname);
0376 expected = fileread(exp_fname);
0377 if size(got, 1) ~= 1    %% transpose if needed for Octave 3.4
0378     got = got';
0379 end
0380 if size(expected, 1) ~= 1   %% transpose if needed for Octave 3.4
0381     expected = expected';
0382 end
0383 delete(got_fname);
0384 got = strrep(got, char([13 10]), char(10));             %% Win to Unix EOL chars
0385 got = regexprep(got, 'Elapsed time is (.*) seconds', 'Elapsed time is 0.00 seconds');
0386 expected = strrep(expected, char([13 10]), char(10));   %% Win to Unix EOL chars
0387 t_ok(strcmp(got, expected), [t 'text output']);
0388 
0389 t = '[groups, isolated] = find_islands(mpc) : ';
0390 mpc = loadcase('case30');
0391 mpc.branch(25, BR_STATUS) = 0;  %% 10-20
0392 mpc.branch(26, BR_STATUS) = 0;  %% 10-17
0393 mpc.branch(13, BR_STATUS) = 0;  %%  9-11, isolates bus 11
0394 mpc.branch(15, BR_STATUS) = 0;  %%  4-12, last tie between areas 1 and 2
0395 mpc.branch(32, BR_STATUS) = 0;  %% 23-24, last tie between areaa 2 and 3
0396 mpc.branch(21, BR_STATUS) = 0;  %% 16-17, isolates bus 17
0397 mpc.branch(24, BR_STATUS) = 0;  %% 19-20, isolates bus 20
0398 mpc.branch(12, BR_STATUS) = 0;  %%  6-10, tie between areas 1 and 3
0399 mpc.branch(14, BR_STATUS) = 0;  %%  9-10, tie between areas 1 and 3
0400 mpc.branch(36, BR_STATUS) = 0;  %% 27-28, tie between areas 1 and 3
0401 [groups, isolated] = find_islands(mpc);
0402 t_ok(iscell(groups), [t 'iscell(groups)']);
0403 t_is(length(groups), 3, 10, [t 'length(groups) == 3']);
0404 t_is(isolated, [11 17 20], 10, [t 'isolated']);
0405 t_is(sort([11     groups{1}]), find(mpc.bus(:, BUS_AREA) == 1)', 10, [t 'groups{1}']);
0406 t_is(             groups{2},   find(mpc.bus(:, BUS_AREA) == 3)', 10, [t 'groups{2}']);
0407 t_is(sort([17 20  groups{3}]), find(mpc.bus(:, BUS_AREA) == 2)', 10, [t 'groups{3}']);
0408 
0409 %% extract 2 islands as single case
0410 t = 'mpc1 = extract_islands(mpc, ''all'') : ';
0411 mpc1 = extract_islands(mpc, 'all');
0412 ibr = find( ~ismember(mpc.branch(:, F_BUS), isolated) & ...
0413             ~ismember(mpc.branch(:, T_BUS), isolated) );
0414 ig = find( ~ismember(mpc.gen(:, GEN_BUS), isolated) );
0415 mpc2 = mpc;
0416 mpc2.bus(isolated, :) = [];
0417 mpc2.branch = mpc.branch(ibr, :);
0418 mpc2.gen    = mpc.gen(ig, :);
0419 mpc2.gencost = mpc.gencost(ig, :);
0420 t_is(mpc1.bus,     mpc2.bus,     10, sprintf('%smpc.bus', t));
0421 t_is(mpc1.gen,     mpc2.gen,     10, sprintf('%smpc.gen', t));
0422 t_is(mpc1.branch,  mpc2.branch,  10, sprintf('%smpc.branch', t));
0423 t_is(mpc1.gencost, mpc2.gencost, 10, sprintf('%smpc.gencost', t));
0424 
0425 if have_feature('octave')
0426     warning(s1.state, file_in_path_warn_id);
0427 end
0428 
0429 t_end;

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005