Home > matpower5.0 > 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 %   $Id: compare_case.m 1884 2011-07-26 13:03:27Z cvs $
0010 %   by Ray Zimmerman, PSERC Cornell
0011 %   Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
0012 %
0013 %   This file is part of MATPOWER.
0014 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0015 %
0016 %   MATPOWER is free software: you can redistribute it and/or modify
0017 %   it under the terms of the GNU General Public License as published
0018 %   by the Free Software Foundation, either version 3 of the License,
0019 %   or (at your option) any later version.
0020 %
0021 %   MATPOWER is distributed in the hope that it will be useful,
0022 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0023 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0024 %   GNU General Public License for more details.
0025 %
0026 %   You should have received a copy of the GNU General Public License
0027 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0028 %
0029 %   Additional permission under GNU GPL version 3 section 7
0030 %
0031 %   If you modify MATPOWER, or any covered work, to interface with
0032 %   other modules (such as MATLAB code and MEX-files) available in a
0033 %   MATLAB(R) or comparable environment containing parts covered
0034 %   under other licensing terms, the licensors of MATPOWER grant
0035 %   you additional permission to convey the resulting work.
0036 
0037 %% define named indices into bus, gen, branch matrices
0038 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0039     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0040 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0041     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0042     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0043 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0044     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0045     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0046 
0047 %% read data & convert to internal bus numbering
0048 [baseMVA1, bus1, gen1, branch1] = loadcase(mpc1);
0049 [baseMVA2, bus2, gen2, branch2] = loadcase(mpc2);
0050 
0051 %% set sizes
0052 solvedPF = 0;
0053 solvedOPF = 0;
0054 Nb = VMIN;
0055 Ng = APF;
0056 Nl = ANGMAX;
0057 
0058 %% check for PF results
0059 if size(branch1, 2) >= QT && size(branch2, 2) >= QT
0060     solvedPF = 1;
0061     Nl = QT;
0062     %% check for OPF results
0063     if size(branch1, 2) >= MU_ST && size(branch2, 2) >= MU_ST
0064         solvedOPF = 1;
0065         Nb = MU_VMIN;
0066         Ng = MU_QMIN;
0067         Nl = MU_ST;
0068     end
0069 end
0070 
0071 %% set up index name matrices
0072     buscols = char( 'BUS_I', ...
0073                     'BUS_TYPE', ...
0074                     'PD', ...
0075                     'QD', ...
0076                     'GS', ...
0077                     'BS', ...
0078                     'BUS_AREA', ...
0079                     'VM', ...
0080                     'VA', ...
0081                     'BASE_KV', ...
0082                     'ZONE', ...
0083                     'VMAX', ...
0084                     'VMIN'  );
0085     gencols = char( 'GEN_BUS', ...
0086                     'PG', ...
0087                     'QG', ...
0088                     'QMAX', ...
0089                     'QMIN', ...
0090                     'VG', ...
0091                     'MBASE', ...
0092                     'GEN_STATUS', ...
0093                     'PMAX', ...
0094                     'PMIN', ...
0095                     'PC1', ...
0096                     'PC2', ...
0097                     'QC1MIN', ...
0098                     'QC1MAX', ...
0099                     'QC2MIN', ...
0100                     'QC2MAX', ...
0101                     'RAMP_AGC', ...
0102                     'RAMP_10', ...
0103                     'RAMP_30', ...
0104                     'RAMP_Q', ...
0105                     'APF'   );
0106     brcols = char(  'F_BUS', ...
0107                     'T_BUS', ...
0108                     'BR_R', ...
0109                     'BR_X', ...
0110                     'BR_B', ...
0111                     'RATE_A', ...
0112                     'RATE_B', ...
0113                     'RATE_C', ...
0114                     'TAP', ...
0115                     'SHIFT', ...
0116                     'BR_STATUS', ...
0117                     'ANGMIN', ...
0118                     'ANGMAX');
0119 if solvedPF
0120     brcols = char(  brcols, ...
0121                     'PF', ...
0122                     'QF', ...
0123                     'PT', ...
0124                     'QT'    );
0125     if solvedOPF
0126         buscols = char( buscols, ...
0127                         'LAM_P', ...
0128                         'LAM_Q', ...
0129                         'MU_VMAX', ...
0130                         'MU_VMIN'   );
0131         gencols = char( gencols, ...
0132                         'MU_PMAX', ...
0133                         'MU_PMIN', ...
0134                         'MU_QMAX', ...
0135                         'MU_QMIN'   );
0136         brcols = char(  brcols, ...
0137                         'MU_SF', ...
0138                         'MU_ST' );
0139     end
0140 end
0141 
0142 %% print results
0143 fprintf('----------------  --------------  --------------  --------------  -----\n');
0144 fprintf(' matrix / col         case 1          case 2        difference     row \n');
0145 fprintf('----------------  --------------  --------------  --------------  -----\n');
0146 
0147 %% bus comparison
0148 [temp, i] = max(abs(bus1(:, 1:Nb) - bus2(:, 1:Nb)));
0149 [v, gmax] = max(temp);
0150 i = i(gmax);
0151 fprintf('bus');
0152 nodiff = ' : no differences found';
0153 for j = 1:size(buscols, 1)
0154     [v, i] = max(abs(bus1(:, j) - bus2(:, j)));
0155     if v
0156         nodiff = '';
0157         if j == gmax, s = ' *'; else s = ''; end
0158         fprintf('\n  %-12s%16g%16g%16g%7d%s', buscols(j, :), bus1(i, j), bus2(i, j), v, i, s );
0159     end
0160 end
0161 fprintf('%s\n', nodiff);
0162 
0163 %% gen comparison
0164 [temp, i] = max(abs(gen1(:, 1:Ng) - gen2(:, 1:Ng)));
0165 [v, gmax] = max(temp);
0166 i = i(gmax);
0167 fprintf('\ngen');
0168 nodiff = ' : no differences found';
0169 for j = 1:size(gencols, 1)
0170     [v, i] = max(abs(gen1(:, j) - gen2(:, j)));
0171     if v
0172         nodiff = '';
0173         if j == gmax, s = ' *'; else s = ''; end
0174         fprintf('\n  %-12s%16g%16g%16g%7d%s', gencols(j, :), gen1(i, j), gen2(i, j), v, i, s );
0175     end
0176 end
0177 fprintf('%s\n', nodiff);
0178 
0179 %% branch comparison
0180 [temp, i] = max(abs(branch1(:, 1:Nl) - branch2(:, 1:Nl)));
0181 [v, gmax] = max(temp);
0182 i = i(gmax);
0183 fprintf('\nbranch');
0184 nodiff = ' : no differences found';
0185 for j = 1:size(brcols, 1)
0186     [v, i] = max(abs(branch1(:, j) - branch2(:, j)));
0187     if v
0188         nodiff = '';
0189         if j == gmax, s = ' *'; else s = ''; end
0190         fprintf('\n  %-12s%16g%16g%16g%7d%s', brcols(j, :), branch1(i, j), branch2(i, j), v, i, s );
0191     end
0192 end
0193 fprintf('%s\n', nodiff);

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005