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

params_lin_constraint

PURPOSE ^

PARAMS_LIN_CONSTRAINT Builds and returns linear constraint parameters.

SYNOPSIS ^

function [A, l, u, vs, i1, iN] = params_lin_constraint(om, name, idx)

DESCRIPTION ^

PARAMS_LIN_CONSTRAINT  Builds and returns linear constraint parameters.
   [A, L, U] = OM.PARAMS_LIN_CONSTRAINT()
   [A, L, U] = OM.PARAMS_LIN_CONSTRAINT(NAME)
   [A, L, U] = OM.PARAMS_LIN_CONSTRAINT(NAME, IDX)
   [A, L, U, VS] = OM.PARAMS_LIN_CONSTRAINT(...)
   [A, L, U, VS, I1, IN] = OM.PARAMS_LIN_CONSTRAINT(...)

   With no input parameters, it assembles and returns the parameters
   for the aggregate linear constraints from all linear constraint sets
   added using ADD_LIN_CONSTRAINT. The values of these parameters are
   cached for subsequent calls. The parameters are A, L and U where the
   linear constraint is of the form
       L <= A * x <= U

   If a NAME is provided then it simply returns the parameters for the
   corresponding named set. Likewise for indexed named sets specified
   by NAME and IDX. 

   An optional 4th output argument VS indicates the variable sets used by
   this cost set. The size of A will be consistent with VS.

   If NAME is provided, optional 5th and 6th output arguments I1 and IN
   indicate the starting and ending row indices of the corresponding
   constraint set in the full aggregate constraint matrix.

   Examples:
       [A, l, u] = om.params_lin_constraint();
       [A, l, u, vs, i1, i2] = om.params_lin_constraint('Pmis');

   See also OPT_MODEL, ADD_LIN_CONSTRAINT.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [A, l, u, vs, i1, iN] = params_lin_constraint(om, name, idx)
0002 %PARAMS_LIN_CONSTRAINT  Builds and returns linear constraint parameters.
0003 %   [A, L, U] = OM.PARAMS_LIN_CONSTRAINT()
0004 %   [A, L, U] = OM.PARAMS_LIN_CONSTRAINT(NAME)
0005 %   [A, L, U] = OM.PARAMS_LIN_CONSTRAINT(NAME, IDX)
0006 %   [A, L, U, VS] = OM.PARAMS_LIN_CONSTRAINT(...)
0007 %   [A, L, U, VS, I1, IN] = OM.PARAMS_LIN_CONSTRAINT(...)
0008 %
0009 %   With no input parameters, it assembles and returns the parameters
0010 %   for the aggregate linear constraints from all linear constraint sets
0011 %   added using ADD_LIN_CONSTRAINT. The values of these parameters are
0012 %   cached for subsequent calls. The parameters are A, L and U where the
0013 %   linear constraint is of the form
0014 %       L <= A * x <= U
0015 %
0016 %   If a NAME is provided then it simply returns the parameters for the
0017 %   corresponding named set. Likewise for indexed named sets specified
0018 %   by NAME and IDX.
0019 %
0020 %   An optional 4th output argument VS indicates the variable sets used by
0021 %   this cost set. The size of A will be consistent with VS.
0022 %
0023 %   If NAME is provided, optional 5th and 6th output arguments I1 and IN
0024 %   indicate the starting and ending row indices of the corresponding
0025 %   constraint set in the full aggregate constraint matrix.
0026 %
0027 %   Examples:
0028 %       [A, l, u] = om.params_lin_constraint();
0029 %       [A, l, u, vs, i1, i2] = om.params_lin_constraint('Pmis');
0030 %
0031 %   See also OPT_MODEL, ADD_LIN_CONSTRAINT.
0032 
0033 %   MATPOWER
0034 %   Copyright (c) 2008-2017, Power Systems Engineering Research Center (PSERC)
0035 %   by Ray Zimmerman, PSERC Cornell
0036 %
0037 %   This file is part of MATPOWER.
0038 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0039 %   See https://matpower.org for more info.
0040 
0041 if nargin > 1       %% individual set
0042     if nargin < 3
0043         idx = {};
0044     end
0045     if isempty(idx)
0046         if prod(size(om.lin.idx.i1.(name))) == 1
0047             A = om.lin.data.A.(name);
0048             l = om.lin.data.l.(name);
0049             u = om.lin.data.u.(name);
0050             if nargout > 3
0051                 vs = om.lin.data.vs.(name);
0052                 if nargout > 5
0053                     i1 = om.lin.idx.i1.(name);      %% starting row index
0054                     iN = om.lin.idx.iN.(name);      %% ending row index
0055                 end
0056             end
0057         else
0058             error('@opt_model/params_lin_constraint: linear constraint set ''%s'' requires an IDX arg', name);
0059         end
0060     else
0061         % (calls to substruct() are relatively expensive ...
0062         % s = substruct('.', name, '{}', idx);
0063         % ... so replace it with these more efficient lines)
0064         sc = struct('type', {'.', '{}'}, 'subs', {name, idx});
0065         A = subsref(om.lin.data.A, sc);
0066         l = subsref(om.lin.data.l, sc);
0067         u = subsref(om.lin.data.u, sc);
0068         if nargout > 3
0069             vs = subsref(om.lin.data.vs, sc);
0070             if nargout > 5
0071                 sn = sc; sn(2).type = '()';         %% num array field
0072                 i1 = subsref(om.lin.idx.i1, sn);    %% starting row index
0073                 iN = subsref(om.lin.idx.iN, sn);    %% ending row index
0074             end
0075         end
0076     end
0077 else                %% aggregate
0078     cache = om.lin.params;
0079     if isempty(cache)       %% build the aggregate
0080         nx = om.var.N;          %% number of variables
0081         nlin = om.lin.N;        %% number of linear constraints
0082         At = sparse(nx, nlin);  %% transpose of constraint matrix
0083         u = Inf(nlin, 1);       %% upper bound
0084         l = -u;                 %% lower bound
0085 
0086         %% fill in each piece
0087         for k = 1:om.lin.NS
0088             name = om.lin.order(k).name;
0089             idx  = om.lin.order(k).idx;
0090             [Ak, lk, uk, vs, i1, iN] = om.params_lin_constraint(name, idx);
0091             [mk, nk] = size(Ak);        %% size of Ak
0092             if mk
0093                 Akt_full = sparse(nx, nlin);
0094                 if isempty(vs)
0095                     if nk == nx     %% full size
0096                         Akt_full(:, i1:iN) = Ak';
0097                     else            %% vars added since adding this cost set
0098                         Ak_all_cols = sparse(mk, nx);
0099                         Ak_all_cols(:, 1:nk) = Ak;
0100                         Akt_full(:, i1:iN) = Ak_all_cols';
0101                     end
0102                 else
0103                     jj = om.varsets_idx(vs);    %% indices for var set
0104                     Ak_all_cols = sparse(mk, nx);
0105                     Ak_all_cols(:, jj) = Ak;
0106                     Akt_full(:, i1:iN) = Ak_all_cols';
0107                 end
0108                 At = At + Akt_full;
0109                 l(i1:iN) = lk;
0110                 u(i1:iN) = uk;
0111             end
0112         end
0113         A = At';
0114 
0115         %% cache aggregated parameters
0116         om.lin.params = struct('A', A, 'l', l, 'u', u);
0117     else                    %% return cached values
0118         A = cache.A;
0119         l = cache.l;
0120         u = cache.u;
0121     end
0122     if nargout > 3
0123         vs = {};
0124     end
0125 end

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