


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, QQ] = OM.GET_IDX()
[VV, LL, NNE, NNI, QQ, NNC] = 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, ...);
VV = OM.GET_IDX('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 = 'qdc' => quadratic cost set
SET_TYPE = 'nnc' => nonlinear cost set
Examples:
[vv, ll, nne] = om.get_idx();
[vv, ll, qq] = om.get_idx('var', 'lin', 'qdc');
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, and ADD_NLN_COST.

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