DESCRIBE_IDX Identifies variable, constraint and cost row indices. LABEL = OM.DESCRIBE_IDX(SET_TYPE, IDXS) Returns strings describing (name and index) the variable, constraint or cost row that corresponds to the indices in IDXS. SET_TYPE must be one of the following: 'var', 'lin', 'nle', 'nli' or 'cost', corresponding to indices for variables, linear constraints, nonlinear equality constraints, nonlinear inequality constraints and cost rows, respectively. The return value is a string if IDXS is a scalar, otherwise it is a cell array of strings of the same dimension as IDXS. Examples: label = om.describe_idx('var', 87)); labels = om.describe_idx('lin', [38; 49; 93])); See also OPT_MODEL.
0001 function label = describe_idx(om, set_type, idxs) 0002 %DESCRIBE_IDX Identifies variable, constraint and cost row indices. 0003 % LABEL = OM.DESCRIBE_IDX(SET_TYPE, IDXS) 0004 % 0005 % Returns strings describing (name and index) the variable, constraint 0006 % or cost row that corresponds to the indices in IDXS. SET_TYPE must be 0007 % one of the following: 'var', 'lin', 'nle', 'nli' or 'cost', 0008 % corresponding to indices for variables, linear constraints, nonlinear 0009 % equality constraints, nonlinear inequality constraints and cost rows, 0010 % respectively. The return value is a string if IDXS is a scalar, 0011 % otherwise it is a cell array of strings of the same dimension as IDXS. 0012 % 0013 % Examples: 0014 % label = om.describe_idx('var', 87)); 0015 % labels = om.describe_idx('lin', [38; 49; 93])); 0016 % 0017 % See also OPT_MODEL. 0018 0019 % MATPOWER 0020 % Copyright (c) 2012-2017, Power Systems Engineering Research Center (PSERC) 0021 % by Ray Zimmerman, PSERC Cornell 0022 % 0023 % This file is part of MATPOWER. 0024 % Covered by the 3-clause BSD License (see LICENSE file for details). 0025 % See https://matpower.org for more info. 0026 0027 label = cell(size(idxs)); %% pre-allocate return cell array 0028 for i = 1:length(idxs(:)) 0029 ii = idxs(i); 0030 if ii > om.(set_type).N 0031 error('@opt_model/describe_idx: index exceeds maximum %s index (%d)', set_type, om.(set_type).N); 0032 end 0033 if ii < 1 0034 error('@opt_model/describe_idx: index must be positive'); 0035 end 0036 for k = om.(set_type).NS:-1:1 0037 name = om.(set_type).order(k).name; 0038 idx = om.(set_type).order(k).idx; 0039 if isempty(idx) 0040 if ii >= om.(set_type).idx.i1.(name) 0041 label{i} = sprintf('%s(%d)', name, ii - om.(set_type).idx.i1.(name) + 1); 0042 break; 0043 end 0044 else 0045 s = substruct('.', name, '()', idx); 0046 if ii >= subsref(om.(set_type).idx.i1, s) 0047 idxstr = sprintf('%d', idx{1}); 0048 for j = 2:length(idx) 0049 idxstr = sprintf('%s,%d', idxstr, idx{j}); 0050 end 0051 label{i} = sprintf('%s(%s)(%d)', name, idxstr, ... 0052 ii - subsref(om.(set_type).idx.i1, s) + 1); 0053 break; 0054 end 0055 end 0056 end 0057 end 0058 if isscalar(idxs) %% return scalar 0059 label = label{1}; 0060 end