INT2EXT Converts internal to external bus numbering. This function has two forms, (1) the old form that operates on and returns individual matrices and (2) the new form that operates on and returns an entire MATPOWER case struct. 1. [BUS, GEN, BRANCH, AREAS] = INT2EXT(I2E, BUS, GEN, BRANCH, AREAS) [BUS, GEN, BRANCH] = INT2EXT(I2E, BUS, GEN, BRANCH) Converts from the consecutive internal bus numbers back to the originals using the mapping provided by the I2E vector returned from EXT2INT, where EXTERNAL_BUS_NUMBER = I2E(INTERNAL_BUS_NUMBER). Examples: [bus, gen, branch, areas] = int2ext(i2e, bus, gen, branch, areas); [bus, gen, branch] = int2ext(i2e, bus, gen, branch); 2. MPC = INT2EXT(MPC) If the input is a single MATPOWER case struct, then it restores all buses, generators and branches that were removed because of being isolated or off-line, and reverts to the original generator ordering and original bus numbering. This requires that the 'order' field created by EXT2INT be in place. Example: mpc = int2ext(mpc); See also EXT2INT, I2E_FIELD, I2E_DATA.
0001 function [bus, gen, branch, areas] = int2ext(i2e, bus, gen, branch, areas) 0002 %INT2EXT Converts internal to external bus numbering. 0003 % 0004 % This function has two forms, (1) the old form that operates on 0005 % and returns individual matrices and (2) the new form that operates 0006 % on and returns an entire MATPOWER case struct. 0007 % 0008 % 1. [BUS, GEN, BRANCH, AREAS] = INT2EXT(I2E, BUS, GEN, BRANCH, AREAS) 0009 % [BUS, GEN, BRANCH] = INT2EXT(I2E, BUS, GEN, BRANCH) 0010 % 0011 % Converts from the consecutive internal bus numbers back to the originals 0012 % using the mapping provided by the I2E vector returned from EXT2INT, 0013 % where EXTERNAL_BUS_NUMBER = I2E(INTERNAL_BUS_NUMBER). 0014 % 0015 % Examples: 0016 % [bus, gen, branch, areas] = int2ext(i2e, bus, gen, branch, areas); 0017 % [bus, gen, branch] = int2ext(i2e, bus, gen, branch); 0018 % 0019 % 2. MPC = INT2EXT(MPC) 0020 % 0021 % If the input is a single MATPOWER case struct, then it restores all 0022 % buses, generators and branches that were removed because of being 0023 % isolated or off-line, and reverts to the original generator ordering 0024 % and original bus numbering. This requires that the 'order' field 0025 % created by EXT2INT be in place. 0026 % 0027 % Example: 0028 % mpc = int2ext(mpc); 0029 % 0030 % See also EXT2INT, I2E_FIELD, I2E_DATA. 0031 0032 % MATPOWER 0033 % $Id: int2ext.m,v 1.18 2011/11/09 21:32:13 cvs Exp $ 0034 % by Ray Zimmerman, PSERC Cornell 0035 % Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC) 0036 % 0037 % This file is part of MATPOWER. 0038 % See http://www.pserc.cornell.edu/matpower/ for more info. 0039 % 0040 % MATPOWER is free software: you can redistribute it and/or modify 0041 % it under the terms of the GNU General Public License as published 0042 % by the Free Software Foundation, either version 3 of the License, 0043 % or (at your option) any later version. 0044 % 0045 % MATPOWER is distributed in the hope that it will be useful, 0046 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0047 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0048 % GNU General Public License for more details. 0049 % 0050 % You should have received a copy of the GNU General Public License 0051 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0052 % 0053 % Additional permission under GNU GPL version 3 section 7 0054 % 0055 % If you modify MATPOWER, or any covered work, to interface with 0056 % other modules (such as MATLAB code and MEX-files) available in a 0057 % MATLAB(R) or comparable environment containing parts covered 0058 % under other licensing terms, the licensors of MATPOWER grant 0059 % you additional permission to convey the resulting work. 0060 0061 if isstruct(i2e) 0062 mpc = i2e; 0063 if nargin == 1 0064 if ~isfield(mpc, 'order') 0065 error('int2ext: mpc does not have the ''order'' field required for conversion back to external numbering.'); 0066 end 0067 o = mpc.order; 0068 0069 if o.state == 'i' 0070 %% define names for columns to data matrices 0071 [PQ, PV, REF, NONE, BUS_I] = idx_bus; 0072 GEN_BUS = idx_gen; 0073 [F_BUS, T_BUS] = idx_brch; 0074 [AREA_I, PRICE_REF_BUS] = idx_area; 0075 0076 %% execute userfcn callbacks for 'int2ext' stage 0077 if isfield(mpc, 'userfcn') 0078 mpc = run_userfcn(mpc.userfcn, 'int2ext', mpc); 0079 end 0080 0081 %% save data matrices with internal ordering & restore originals 0082 o.int.bus = mpc.bus; 0083 o.int.branch = mpc.branch; 0084 o.int.gen = mpc.gen; 0085 mpc.bus = o.ext.bus; 0086 mpc.branch = o.ext.branch; 0087 mpc.gen = o.ext.gen; 0088 if isfield(mpc, 'gencost') 0089 o.int.gencost = mpc.gencost; 0090 mpc.gencost = o.ext.gencost; 0091 end 0092 if isfield(mpc, 'areas') 0093 o.int.areas = mpc.areas; 0094 mpc.areas = o.ext.areas; 0095 end 0096 if isfield(mpc, 'A') 0097 o.int.A = mpc.A; 0098 mpc.A = o.ext.A; 0099 end 0100 if isfield(mpc, 'N') 0101 o.int.N = mpc.N; 0102 mpc.N = o.ext.N; 0103 end 0104 0105 %% update data (in bus, branch and gen only) 0106 mpc.bus(o.bus.status.on, :) = o.int.bus; 0107 mpc.branch(o.branch.status.on, :) = o.int.branch; 0108 mpc.gen(o.gen.status.on, :) = o.int.gen(o.gen.i2e, :); 0109 if isfield(mpc, 'areas') 0110 mpc.areas(o.areas.status.on, :) = o.int.areas; 0111 end 0112 0113 %% revert to original bus numbers 0114 mpc.bus(o.bus.status.on, BUS_I) = ... 0115 o.bus.i2e( mpc.bus(o.bus.status.on, BUS_I) ); 0116 mpc.branch(o.branch.status.on, F_BUS) = ... 0117 o.bus.i2e( mpc.branch(o.branch.status.on, F_BUS) ); 0118 mpc.branch(o.branch.status.on, T_BUS) = ... 0119 o.bus.i2e( mpc.branch(o.branch.status.on, T_BUS) ); 0120 mpc.gen(o.gen.status.on, GEN_BUS) = ... 0121 o.bus.i2e( mpc.gen(o.gen.status.on, GEN_BUS) ); 0122 if isfield(mpc, 'areas') 0123 mpc.areas(o.areas.status.on, PRICE_REF_BUS) = ... 0124 o.bus.i2e( mpc.areas(o.areas.status.on, PRICE_REF_BUS) ); 0125 end 0126 0127 if isfield(o, 'ext') 0128 o = rmfield(o, 'ext'); 0129 end 0130 o.state = 'e'; 0131 mpc.order = o; 0132 else 0133 error('int2ext: mpc claims it is already using external numbering.'); 0134 end 0135 0136 bus = mpc; 0137 else %% convert extra data 0138 if ischar(bus) || iscell(bus) %% field 0139 warning('Calls of the form MPC = INT2EXT(MPC, ''FIELD_NAME'', ...) have been deprecated. Please replace INT2EXT with I2E_FIELD.'); 0140 if nargin > 3 0141 dim = branch; 0142 else 0143 dim = 1; 0144 end 0145 bus = i2e_field(mpc, bus, gen, dim); 0146 else %% value 0147 warning('Calls of the form VAL = INT2EXT(MPC, VAL, ...) have been deprecated. Please replace INT2EXT with I2E_DATA.'); 0148 if nargin > 4 0149 dim = areas; 0150 else 0151 dim = 1; 0152 end 0153 bus = i2e_data(mpc, bus, gen, branch, dim); 0154 end 0155 end 0156 else %% old form 0157 %% define names for columns to data matrices 0158 [PQ, PV, REF, NONE, BUS_I] = idx_bus; 0159 [GEN_BUS] = idx_gen; 0160 [F_BUS, T_BUS] = idx_brch; 0161 [AREA_I, PRICE_REF_BUS] = idx_area; 0162 0163 bus(:, BUS_I) = i2e( bus(:, BUS_I) ); 0164 gen(:, GEN_BUS) = i2e( gen(:, GEN_BUS) ); 0165 branch(:, F_BUS) = i2e( branch(:, F_BUS) ); 0166 branch(:, T_BUS) = i2e( branch(:, T_BUS) ); 0167 if nargin > 4 && nargout > 3 && ~isempty(areas) 0168 areas(:, PRICE_REF_BUS) = i2e( areas(:, PRICE_REF_BUS) ); 0169 end 0170 end