Home > matpower4.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,v 1.8 2010/04/26 19:45:25 ray Exp $
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 if solvedPF
0118     brcols = char(  brcols, ...
0119                     'PF', ...
0120                     'QF', ...
0121                     'PT', ...
0122                     'QT'    );
0123     if solvedOPF
0124         buscols = char( buscols, ...
0125                         'LAM_P', ...
0126                         'LAM_Q', ...
0127                         'MU_VMAX', ...
0128                         'MU_VMIN'   );
0129         gencols = char( gencols, ...
0130                         'MU_PMAX', ...
0131                         'MU_PMIN', ...
0132                         'MU_QMAX', ...
0133                         'MU_QMIN'   );
0134         brcols = char(  brcols, ...
0135                         'MU_SF', ...
0136                         'MU_ST' );
0137     end
0138 end
0139 
0140 %% print results
0141 fprintf('----------------  --------------  --------------  --------------  -----\n');
0142 fprintf(' matrix / col         case 1          case 2        difference     row \n');
0143 fprintf('----------------  --------------  --------------  --------------  -----\n');
0144 
0145 %% bus comparison
0146 [temp, i] = max(abs(bus1(:, 1:Nb) - bus2(:, 1:Nb)));
0147 [v, gmax] = max(temp);
0148 i = i(gmax);
0149 fprintf('bus');
0150 nodiff = ' : no differences found';
0151 for j = 1:size(buscols, 1)
0152     [v, i] = max(abs(bus1(:, j) - bus2(:, j)));
0153     if v
0154         nodiff = '';
0155         if j == gmax, s = ' *'; else s = ''; end
0156         fprintf('\n  %-12s%16g%16g%16g%7d%s', buscols(j, :), bus1(i, j), bus2(i, j), v, i, s );
0157     end
0158 end
0159 fprintf('%s\n', nodiff);
0160 
0161 %% gen comparison
0162 [temp, i] = max(abs(gen1(:, 1:Ng) - gen2(:, 1:Ng)));
0163 [v, gmax] = max(temp);
0164 i = i(gmax);
0165 fprintf('\ngen');
0166 nodiff = ' : no differences found';
0167 for j = 1:size(gencols, 1)
0168     [v, i] = max(abs(gen1(:, j) - gen2(:, j)));
0169     if v
0170         nodiff = '';
0171         if j == gmax, s = ' *'; else s = ''; end
0172         fprintf('\n  %-12s%16g%16g%16g%7d%s', gencols(j, :), gen1(i, j), gen2(i, j), v, i, s );
0173     end
0174 end
0175 fprintf('%s\n', nodiff);
0176 
0177 %% branch comparison
0178 [temp, i] = max(abs(branch1(:, 1:Nl) - branch2(:, 1:Nl)));
0179 [v, gmax] = max(temp);
0180 i = i(gmax);
0181 fprintf('\nbranch');
0182 nodiff = ' : no differences found';
0183 for j = 1:size(brcols, 1)
0184     [v, i] = max(abs(branch1(:, j) - branch2(:, j)));
0185     if v
0186         nodiff = '';
0187         if j == gmax, s = ' *'; else s = ''; end
0188         fprintf('\n  %-12s%16g%16g%16g%7d%s', brcols(j, :), branch1(i, j), branch2(i, j), v, i, s );
0189     end
0190 end
0191 fprintf('%s\n', nodiff);

Generated on Mon 26-Jan-2015 14:56:45 by m2html © 2005