Home > matpower7.1 > mp-opt-model > lib > @mp_idx_manager > describe_idx.m

describe_idx

PURPOSE ^

DESCRIBE_IDX Identifies element indices for a give set type.

SYNOPSIS ^

function label = describe_idx(obj, set_type, idxs)

DESCRIPTION ^

DESCRIBE_IDX  Identifies element indices for a give set type.
   LABEL = OBJ.DESCRIBE_IDX(SET_TYPE, IDXS)

   Returns strings describing (name and index) the element of the
   specified set type (e.g. variable or constraint) that corresponds to
   the indices in IDXS. 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 = obj.describe_idx('var', 87));
       labels = obj.describe_idx('lin', [38; 49; 93]));

   See also OPT_MODEL.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005