GETN Returns the number of elements of a given set type. N = OBJ.GETN(SET_TYPE) N = OBJ.GETN(SET_TYPE, NAME) N = OBJ.GETN(SET_TYPE, NAME, IDX_LIST) Returns either the total number of elements of a given set type (e.g. variable, constraint, etc.) or the number corresponding to a specified named block, or indexed named set. Examples: N = obj.getN('var') : total number of variables N = obj.getN('lin') : total number of linear constraints N = obj.getN('var', name) : # of variables in named set N = obj.getN('lin', name) : # of linear constraints in named set N = obj.getN('var', name, idx) : # of variables in indexed named set See also OPT_MODEL.
0001 function N = getN(obj, set_type, name, idx) 0002 %GETN Returns the number of elements of a given set type. 0003 % N = OBJ.GETN(SET_TYPE) 0004 % N = OBJ.GETN(SET_TYPE, NAME) 0005 % N = OBJ.GETN(SET_TYPE, NAME, IDX_LIST) 0006 % 0007 % Returns either the total number of elements of a given set type 0008 % (e.g. variable, constraint, etc.) or the number corresponding to a 0009 % specified named block, or indexed named set. 0010 % 0011 % Examples: 0012 % N = obj.getN('var') : total number of variables 0013 % N = obj.getN('lin') : total number of linear constraints 0014 % N = obj.getN('var', name) : # of variables in named set 0015 % N = obj.getN('lin', name) : # of linear constraints in named set 0016 % N = obj.getN('var', name, idx) : # of variables in indexed named set 0017 % 0018 % See also OPT_MODEL. 0019 0020 % MP-Opt-Model 0021 % Copyright (c) 2008-2020, Power Systems Engineering Research Center (PSERC) 0022 % by Ray Zimmerman, PSERC Cornell 0023 % 0024 % This file is part of MP-Opt-Model. 0025 % Covered by the 3-clause BSD License (see LICENSE file for details). 0026 % See https://github.com/MATPOWER/mp-opt-model for more info. 0027 0028 if nargin < 3 0029 N = obj.(set_type).N; 0030 else 0031 if isfield(obj.(set_type).idx.N, name) 0032 if nargin < 4 || isempty(idx) 0033 N = obj.(set_type).idx.N.(name); 0034 else 0035 % s1 = substruct('.', name, '()', idx); 0036 sn = struct('type', {'.', '()'}, 'subs', {name, idx}); %% num array field 0037 N = subsref(obj.(set_type).idx.N, sn); 0038 end 0039 else 0040 N = 0; 0041 end 0042 end