Home > matpower5.1 > @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-2015 by Power System Engineering Research Center (PSERC)
0021 %   by Ray Zimmerman, PSERC Cornell
0022 %
0023 %   $Id: describe_idx.m 2644 2015-03-11 19:34:22Z ray $
0024 %
0025 %   This file is part of MATPOWER.
0026 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0027 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0028 
0029 label = cell(size(idxs));       %% pre-allocate return cell array
0030 for i = 1:length(idxs(:))
0031     ii = idxs(i);
0032     if ii > om.(idx_type).N
0033         error('@opt_model/describe_idx: index exceeds maximum %s index (%d)', idx_type, om.(idx_type).N);
0034     end
0035     if ii < 1
0036         error('@opt_model/describe_idx: index must be positive');
0037     end
0038     for k = om.(idx_type).NS:-1:1
0039         name = om.(idx_type).order(k).name;
0040         idx = om.(idx_type).order(k).idx;
0041         if isempty(idx)
0042             if ii >= om.(idx_type).idx.i1.(name)
0043                 label{i} = sprintf('%s(%d)', name, ii - om.(idx_type).idx.i1.(name) + 1);
0044                 break;
0045             end
0046         else
0047             s = substruct('.', name, '()', idx);
0048             if ii >= subsref(om.(idx_type).idx.i1, s)
0049                 idxstr = sprintf('%d', idx{1});
0050                 for j = 2:length(idx)
0051                     idxstr = sprintf('%s,%d', idxstr, idx{j});
0052                 end
0053                 label{i} = sprintf('%s(%s)(%d)', name, idxstr, ...
0054                             ii - subsref(om.(idx_type).idx.i1, s) + 1);
0055                 break;
0056             end
0057         end
0058     end
0059 end
0060 if isscalar(idxs)               %% return scalar
0061     label = label{1};
0062 end

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005