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

get_idx

PURPOSE ^

GET_IDX Returns the idx struct for the various set types.

SYNOPSIS ^

function varargout = get_idx(obj, varargin)

DESCRIPTION ^

GET_IDX  Returns the idx struct for the various set types.

   IDX = OBJ.GET_IDX(SET_TYPE)
   [IDX1, IDX2, ...] = OBJ.GET_IDX(SET_TYPE1, SET_TYPE2, ...)

   Returns a structure for each set type with the beginning and ending
   index value and the number of elements for each named block. The 'i1'
   field (that's a one) is a struct with all of the starting indices, 'iN'
   contains all the ending indices and 'N' contains all the sizes. Each is
   a struct whose fields are the named blocks.

   For example, if 'var' is the set type used for a vector x of optimization
   variables, and 'lin' is for a set of linear constraints, then the
   following examples illustrate how GET_IDX might be used.

   Examples:
       [vv, ll] = obj.get_idx('var', 'lin');

       For a variable block named 'z' we have ...
           vv.i1.z - starting index for 'z' in optimization vector x
           vv.iN.z - ending index for 'z' in optimization vector x
           vv.N.z  - number of elements in 'z'

       To extract a 'z' variable from x:
           z = x(vv.i1.z:vv.iN.z);

       To extract the multipliers on a linear constraint set
       named 'foo', where mu_l and mu_u are the full set of
       linear constraint multipliers:
           mu_l_foo = mu_l(ll.i1.foo:ll.iN.foo);
           mu_u_foo = mu_u(ll.i1.foo:ll.iN.foo);

       The number of linear constraints in a set named 'bar':
           nbar = ll.N.bar;
         (note: the following is preferable ...
           nbar = obj.getN('lin', 'bar');
         ... if you haven't already called get_idx to get ll.)

       If 'z', 'foo' and 'bar' are indexed sets, then you can
       replace them with something like 'z(i,j)', 'foo(i,j,k)'
       or 'bar(i)' in the examples above.

   The GET_IDX method can be overridden to also return the idx structs of
   set types in a pre-specified order when called without input arguments.

   E.g.
       vv = obj.get_idx()          % for variables
       [vv, ll] = obj.get_idx()    % for linear constraints

   See also OPT_MODEL, and its methods GET_IDX, ADD_VAR,
           ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT, ADD_QUAD_COST and
           ADD_NLN_COST.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = get_idx(obj, varargin)
0002 %GET_IDX  Returns the idx struct for the various set types.
0003 %
0004 %   IDX = OBJ.GET_IDX(SET_TYPE)
0005 %   [IDX1, IDX2, ...] = OBJ.GET_IDX(SET_TYPE1, SET_TYPE2, ...)
0006 %
0007 %   Returns a structure for each set type with the beginning and ending
0008 %   index value and the number of elements for each named block. The 'i1'
0009 %   field (that's a one) is a struct with all of the starting indices, 'iN'
0010 %   contains all the ending indices and 'N' contains all the sizes. Each is
0011 %   a struct whose fields are the named blocks.
0012 %
0013 %   For example, if 'var' is the set type used for a vector x of optimization
0014 %   variables, and 'lin' is for a set of linear constraints, then the
0015 %   following examples illustrate how GET_IDX might be used.
0016 %
0017 %   Examples:
0018 %       [vv, ll] = obj.get_idx('var', 'lin');
0019 %
0020 %       For a variable block named 'z' we have ...
0021 %           vv.i1.z - starting index for 'z' in optimization vector x
0022 %           vv.iN.z - ending index for 'z' in optimization vector x
0023 %           vv.N.z  - number of elements in 'z'
0024 %
0025 %       To extract a 'z' variable from x:
0026 %           z = x(vv.i1.z:vv.iN.z);
0027 %
0028 %       To extract the multipliers on a linear constraint set
0029 %       named 'foo', where mu_l and mu_u are the full set of
0030 %       linear constraint multipliers:
0031 %           mu_l_foo = mu_l(ll.i1.foo:ll.iN.foo);
0032 %           mu_u_foo = mu_u(ll.i1.foo:ll.iN.foo);
0033 %
0034 %       The number of linear constraints in a set named 'bar':
0035 %           nbar = ll.N.bar;
0036 %         (note: the following is preferable ...
0037 %           nbar = obj.getN('lin', 'bar');
0038 %         ... if you haven't already called get_idx to get ll.)
0039 %
0040 %       If 'z', 'foo' and 'bar' are indexed sets, then you can
0041 %       replace them with something like 'z(i,j)', 'foo(i,j,k)'
0042 %       or 'bar(i)' in the examples above.
0043 %
0044 %   The GET_IDX method can be overridden to also return the idx structs of
0045 %   set types in a pre-specified order when called without input arguments.
0046 %
0047 %   E.g.
0048 %       vv = obj.get_idx()          % for variables
0049 %       [vv, ll] = obj.get_idx()    % for linear constraints
0050 %
0051 %   See also OPT_MODEL, and its methods GET_IDX, ADD_VAR,
0052 %           ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT, ADD_QUAD_COST and
0053 %           ADD_NLN_COST.
0054 
0055 %   MP-Opt-Model
0056 %   Copyright (c) 2008-2020, Power Systems Engineering Research Center (PSERC)
0057 %   by Ray Zimmerman, PSERC Cornell
0058 %
0059 %   This file is part of MP-Opt-Model.
0060 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0061 %   See https://github.com/MATPOWER/mp-opt-model for more info.
0062 
0063 if nargin ~= 1
0064     for k = nargout:-1:1
0065         varargout{k} = obj.(varargin{k}).idx;
0066     end
0067 end

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