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

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