Home > matpower6.0 > @opt_model > describe_idx.m

describe_idx

PURPOSE ^

DESCRIBE_IDX Identifies variable, constraint and cost row indices.

SYNOPSIS ^

function label = describe_idx(om, idx_type, idxs)

DESCRIPTION ^

DESCRIBE_IDX  Identifies variable, constraint and cost row indices.
   LABEL = DESCRIBE_IDX(OM, IDX_TYPE, IDXS)

   Returns strings describing (name and index) the variable, constraint
   or cost row that corresponds to the indices in IDXS. IDX_TYPE must be
   one of the following: 'var', 'lin', 'nln', or 'cost', corresponding
   to indices for variables, linear constraints, non-linear 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 = describe_idx(om, 'var', 87));
       labels = describe_idx(om, '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(om, idx_type, idxs)
0002 %DESCRIBE_IDX  Identifies variable, constraint and cost row indices.
0003 %   LABEL = DESCRIBE_IDX(OM, IDX_TYPE, IDXS)
0004 %
0005 %   Returns strings describing (name and index) the variable, constraint
0006 %   or cost row that corresponds to the indices in IDXS. IDX_TYPE must be
0007 %   one of the following: 'var', 'lin', 'nln', or 'cost', corresponding
0008 %   to indices for variables, linear constraints, non-linear constraints
0009 %   and cost rows, respectively. The return value is a string if IDXS is
0010 %   a scalar, otherwise it is a cell array of strings of the same
0011 %   dimension as IDXS.
0012 %
0013 %   Examples:
0014 %       label = describe_idx(om, 'var', 87));
0015 %       labels = describe_idx(om, 'lin', [38; 49; 93]));
0016 %
0017 %   See also OPT_MODEL.
0018 
0019 %   MATPOWER
0020 %   Copyright (c) 2012-2016, 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 http://www.pserc.cornell.edu/matpower/ 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.(idx_type).N
0031         error('@opt_model/describe_idx: index exceeds maximum %s index (%d)', idx_type, om.(idx_type).N);
0032     end
0033     if ii < 1
0034         error('@opt_model/describe_idx: index must be positive');
0035     end
0036     for k = om.(idx_type).NS:-1:1
0037         name = om.(idx_type).order(k).name;
0038         idx = om.(idx_type).order(k).idx;
0039         if isempty(idx)
0040             if ii >= om.(idx_type).idx.i1.(name)
0041                 label{i} = sprintf('%s(%d)', name, ii - om.(idx_type).idx.i1.(name) + 1);
0042                 break;
0043             end
0044         else
0045             s = substruct('.', name, '()', idx);
0046             if ii >= subsref(om.(idx_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.(idx_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

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005