Home > matpower7.1 > lib > compare_case.m

compare_case

PURPOSE ^

COMPARE_CASE Compares the bus, gen, branch matrices of 2 MATPOWER cases.

SYNOPSIS ^

function compare_case(mpc1, mpc2)

DESCRIPTION ^

COMPARE_CASE  Compares the bus, gen, branch matrices of 2 MATPOWER cases.
   COMPARE_CASE(MPC1, MPC2)
   Compares the bus, branch and gen matrices of two MATPOWER cases and
   prints a summary of the differences. For each column of the matrix it
   prints the maximum of any non-zero differences.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function compare_case(mpc1, mpc2)
0002 %COMPARE_CASE  Compares the bus, gen, branch matrices of 2 MATPOWER cases.
0003 %   COMPARE_CASE(MPC1, MPC2)
0004 %   Compares the bus, branch and gen matrices of two MATPOWER cases and
0005 %   prints a summary of the differences. For each column of the matrix it
0006 %   prints the maximum of any non-zero differences.
0007 
0008 %   MATPOWER
0009 %   Copyright (c) 1996-2016, Power Systems Engineering Research Center (PSERC)
0010 %   by Ray Zimmerman, PSERC Cornell
0011 %
0012 %   This file is part of MATPOWER.
0013 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0014 %   See https://matpower.org for more info.
0015 
0016 %% define named indices into bus, gen, branch matrices
0017 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0018     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0019 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0020     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0021     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0022 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0023     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0024     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0025 
0026 %% read data & convert to internal bus numbering
0027 [baseMVA1, bus1, gen1, branch1] = loadcase(mpc1);
0028 [baseMVA2, bus2, gen2, branch2] = loadcase(mpc2);
0029 
0030 %% set sizes
0031 solvedPF = 0;
0032 solvedOPF = 0;
0033 Nb = VMIN;
0034 Ng = APF;
0035 Nl = ANGMAX;
0036 
0037 %% check for PF results
0038 if size(branch1, 2) >= QT && size(branch2, 2) >= QT
0039     solvedPF = 1;
0040     Nl = QT;
0041     %% check for OPF results
0042     if size(branch1, 2) >= MU_ST && size(branch2, 2) >= MU_ST
0043         solvedOPF = 1;
0044         Nb = MU_VMIN;
0045         Ng = MU_QMIN;
0046         Nl = MU_ST;
0047     end
0048 end
0049 
0050 %% set up index name matrices
0051     buscols = char( 'BUS_I', ...
0052                     'BUS_TYPE', ...
0053                     'PD', ...
0054                     'QD', ...
0055                     'GS', ...
0056                     'BS', ...
0057                     'BUS_AREA', ...
0058                     'VM', ...
0059                     'VA', ...
0060                     'BASE_KV', ...
0061                     'ZONE', ...
0062                     'VMAX', ...
0063                     'VMIN'  );
0064     gencols = char( 'GEN_BUS', ...
0065                     'PG', ...
0066                     'QG', ...
0067                     'QMAX', ...
0068                     'QMIN', ...
0069                     'VG', ...
0070                     'MBASE', ...
0071                     'GEN_STATUS', ...
0072                     'PMAX', ...
0073                     'PMIN', ...
0074                     'PC1', ...
0075                     'PC2', ...
0076                     'QC1MIN', ...
0077                     'QC1MAX', ...
0078                     'QC2MIN', ...
0079                     'QC2MAX', ...
0080                     'RAMP_AGC', ...
0081                     'RAMP_10', ...
0082                     'RAMP_30', ...
0083                     'RAMP_Q', ...
0084                     'APF'   );
0085     brcols = char(  'F_BUS', ...
0086                     'T_BUS', ...
0087                     'BR_R', ...
0088                     'BR_X', ...
0089                     'BR_B', ...
0090                     'RATE_A', ...
0091                     'RATE_B', ...
0092                     'RATE_C', ...
0093                     'TAP', ...
0094                     'SHIFT', ...
0095                     'BR_STATUS', ...
0096                     'ANGMIN', ...
0097                     'ANGMAX');
0098 if solvedPF
0099     brcols = char(  brcols, ...
0100                     'PF', ...
0101                     'QF', ...
0102                     'PT', ...
0103                     'QT'    );
0104     if solvedOPF
0105         buscols = char( buscols, ...
0106                         'LAM_P', ...
0107                         'LAM_Q', ...
0108                         'MU_VMAX', ...
0109                         'MU_VMIN'   );
0110         gencols = char( gencols, ...
0111                         'MU_PMAX', ...
0112                         'MU_PMIN', ...
0113                         'MU_QMAX', ...
0114                         'MU_QMIN'   );
0115         brcols = char(  brcols, ...
0116                         'MU_SF', ...
0117                         'MU_ST' );
0118     end
0119 end
0120 
0121 %% print results
0122 fprintf('----------------  --------------  --------------  --------------  -----\n');
0123 fprintf(' matrix / col         case 1          case 2        difference     row \n');
0124 fprintf('----------------  --------------  --------------  --------------  -----\n');
0125 
0126 %% bus comparison
0127 [temp, i] = max(abs(bus1(:, 1:Nb) - bus2(:, 1:Nb)));
0128 [v, gmax] = max(temp);
0129 i = i(gmax);
0130 fprintf('bus');
0131 nodiff = ' : no differences found';
0132 for j = 1:size(buscols, 1)
0133     [v, i] = max(abs(bus1(:, j) - bus2(:, j)));
0134     if v
0135         nodiff = '';
0136         if j == gmax, s = ' *'; else s = ''; end
0137         fprintf('\n  %-12s%16g%16g%16g%7d%s', buscols(j, :), bus1(i, j), bus2(i, j), v, i, s );
0138     end
0139 end
0140 fprintf('%s\n', nodiff);
0141 
0142 %% gen comparison
0143 [temp, i] = max(abs(gen1(:, 1:Ng) - gen2(:, 1:Ng)));
0144 [v, gmax] = max(temp);
0145 i = i(gmax);
0146 fprintf('\ngen');
0147 nodiff = ' : no differences found';
0148 for j = 1:size(gencols, 1)
0149     [v, i] = max(abs(gen1(:, j) - gen2(:, j)));
0150     if v
0151         nodiff = '';
0152         if j == gmax, s = ' *'; else s = ''; end
0153         fprintf('\n  %-12s%16g%16g%16g%7d%s', gencols(j, :), gen1(i, j), gen2(i, j), v, i, s );
0154     end
0155 end
0156 fprintf('%s\n', nodiff);
0157 
0158 %% branch comparison
0159 [temp, i] = max(abs(branch1(:, 1:Nl) - branch2(:, 1:Nl)));
0160 [v, gmax] = max(temp);
0161 i = i(gmax);
0162 fprintf('\nbranch');
0163 nodiff = ' : no differences found';
0164 for j = 1:size(brcols, 1)
0165     [v, i] = max(abs(branch1(:, j) - branch2(:, j)));
0166     if v
0167         nodiff = '';
0168         if j == gmax, s = ' *'; else s = ''; end
0169         fprintf('\n  %-12s%16g%16g%16g%7d%s', brcols(j, :), branch1(i, j), branch2(i, j), v, i, s );
0170     end
0171 end
0172 fprintf('%s\n', nodiff);

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