Home > matpower7.0 > lib > @opt_model > get_idx.m

get_idx

PURPOSE ^

GET_IDX Returns the idx struct for vars, lin/nonlin constraints, costs.

SYNOPSIS ^

function varargout = get_idx(om, varargin)

DESCRIPTION ^

GET_IDX  Returns the idx struct for vars, lin/nonlin constraints, costs.
   VV = OM.GET_IDX()
   [VV, LL] = OM.GET_IDX()
   [VV, LL, NNE] = OM.GET_IDX()
   [VV, LL, NNE, NNI] = OM.GET_IDX()
   [VV, LL, NNE, NNI, CC] = OM.GET_IDX()

   Returns a structure for each 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.

   Alternatively, you can specify the type of named set(s) directly
   as inputs ...

   [IDX1, IDX2, ...] = OM.GET_IDX(SET_TYPE1, SET_TYPE2, ...);
   [CC, VV] = OM.GET_IDX('cost', 'var');
   [LL, NNE, NNI] = OM.GET_IDX('lin', 'nle', 'nli');

   The specific type of named set being referenced is
   given by the SET_TYPE inputs, with the following valid options:
       SET_TYPE = 'var'   => variable set
       SET_TYPE = 'lin'   => linear constraint set
       SET_TYPE = 'nle'   => nonlinear equality constraint set
       SET_TYPE = 'nli'   => nonlinear inequality constraint set
       SET_TYPE = 'cost'  => cost set

   Examples:
       [vv, ll, nne] = om.get_idx();
       [vv, ll, cc] = om.get_idx('var', 'lin', 'cost');

       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 nonlinear equality constraints in a set named 'bar':
           nbar = nne.N.bar;
         (note: the following is preferable ...
           nbar = om.getN('nle', 'bar');
         ... if you haven't already called get_idx to get nne.)

       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.

   See also OPT_MODEL, ADD_VAR, ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT,
            ADD_QUAD_COST, ADD_NLN_COST and ADD_LEGACY_COST.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = get_idx(om, varargin)
0002 %GET_IDX  Returns the idx struct for vars, lin/nonlin constraints, costs.
0003 %   VV = OM.GET_IDX()
0004 %   [VV, LL] = OM.GET_IDX()
0005 %   [VV, LL, NNE] = OM.GET_IDX()
0006 %   [VV, LL, NNE, NNI] = OM.GET_IDX()
0007 %   [VV, LL, NNE, NNI, CC] = OM.GET_IDX()
0008 %
0009 %   Returns a structure for each with the beginning and ending
0010 %   index value and the number of elements for each named block.
0011 %   The 'i1' field (that's a one) is a struct with all of the
0012 %   starting indices, 'iN' contains all the ending indices and
0013 %   'N' contains all the sizes. Each is a struct whose fields are
0014 %   the named blocks.
0015 %
0016 %   Alternatively, you can specify the type of named set(s) directly
0017 %   as inputs ...
0018 %
0019 %   [IDX1, IDX2, ...] = OM.GET_IDX(SET_TYPE1, SET_TYPE2, ...);
0020 %   [CC, VV] = OM.GET_IDX('cost', 'var');
0021 %   [LL, NNE, NNI] = OM.GET_IDX('lin', 'nle', 'nli');
0022 %
0023 %   The specific type of named set being referenced is
0024 %   given by the SET_TYPE inputs, with the following valid options:
0025 %       SET_TYPE = 'var'   => variable set
0026 %       SET_TYPE = 'lin'   => linear constraint set
0027 %       SET_TYPE = 'nle'   => nonlinear equality constraint set
0028 %       SET_TYPE = 'nli'   => nonlinear inequality constraint set
0029 %       SET_TYPE = 'cost'  => cost set
0030 %
0031 %   Examples:
0032 %       [vv, ll, nne] = om.get_idx();
0033 %       [vv, ll, cc] = om.get_idx('var', 'lin', 'cost');
0034 %
0035 %       For a variable block named 'z' we have ...
0036 %           vv.i1.z - starting index for 'z' in optimization vector x
0037 %           vv.iN.z - ending index for 'z' in optimization vector x
0038 %           vv.N.z  - number of elements in 'z'
0039 %
0040 %       To extract a 'z' variable from x:
0041 %           z = x(vv.i1.z:vv.iN.z);
0042 %
0043 %       To extract the multipliers on a linear constraint set
0044 %       named 'foo', where mu_l and mu_u are the full set of
0045 %       linear constraint multipliers:
0046 %           mu_l_foo = mu_l(ll.i1.foo:ll.iN.foo);
0047 %           mu_u_foo = mu_u(ll.i1.foo:ll.iN.foo);
0048 %
0049 %       The number of nonlinear equality constraints in a set named 'bar':
0050 %           nbar = nne.N.bar;
0051 %         (note: the following is preferable ...
0052 %           nbar = om.getN('nle', 'bar');
0053 %         ... if you haven't already called get_idx to get nne.)
0054 %
0055 %       If 'z', 'foo' and 'bar' are indexed sets, then you can
0056 %       replace them with something like 'z(i,j)', 'foo(i,j,k)'
0057 %       or 'bar(i)' in the examples above.
0058 %
0059 %   See also OPT_MODEL, ADD_VAR, ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT,
0060 %            ADD_QUAD_COST, ADD_NLN_COST and ADD_LEGACY_COST.
0061 
0062 %   MATPOWER
0063 %   Copyright (c) 2008-2017, Power Systems Engineering Research Center (PSERC)
0064 %   by Ray Zimmerman, PSERC Cornell
0065 %
0066 %   This file is part of MATPOWER.
0067 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0068 %   See https://matpower.org for more info.
0069 
0070 if nargin == 1
0071     varargout{1} = om.var.idx;
0072     if nargout > 1
0073         varargout{2} = om.lin.idx;
0074         if nargout > 2
0075             varargout{3} = om.nle.idx;
0076             if nargout > 3
0077                 varargout{4} = om.nli.idx;
0078                 if nargout > 4
0079                     varargout{5} = om.cost.idx;
0080                 end
0081             end
0082         end
0083     end
0084 else
0085     for k = nargout:-1:1
0086         varargout{k} = om.(varargin{k}).idx;
0087     end
0088 end

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005