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

add_lin_constraint

PURPOSE ^

ADD_LIN_CONSTRAINT Adds a set of linear constraints to the model.

SYNOPSIS ^

function om = add_lin_constraint(om, name, idx, A, l, u, varsets)

DESCRIPTION ^

ADD_LIN_CONSTRAINT  Adds a set of linear constraints to the model.

   OM.ADD_LIN_CONSTRAINT(NAME, A, L, U);
   OM.ADD_LIN_CONSTRAINT(NAME, A, L, U, VARSETS);

   OM.ADD_LIN_CONSTRAINT(NAME, IDX_LIST, A, L, U);
   OM.ADD_LIN_CONSTRAINT(NAME, IDX_LIST, A, L, U, VARSETS);

   Linear constraints are of the form L <= A * x <= U, where x is a
   vector made of the vars specified in VARSETS (in the order given).
   This allows the A matrix to be defined only in terms of the relevant
   variables without the need to manually create a lot of zero columns.
   If VARSETS is empty, x is taken to be the full vector of all
   optimization variables. If L or U are empty, they are assumed to be
   appropriately sized vectors of -Inf and Inf, respectively.

   Indexed Named Sets
       A constraint set can be identified by a single NAME, as described
       above, such as 'Pmismatch', or by a name that is indexed by one
       or more indices, such as 'Pmismatch(3,4)'. For an indexed named
       set, before adding the constraint sets themselves, the dimensions
       of the indexed set must be set by calling INIT_INDEXED_NAME.

       The constraints are then added using the following, where
       all arguments are as described above, except IDX_LIST is a cell
       array of the indices for the particular constraint set being added.

       OM.ADD_LIN_CONSTRAINT(NAME, IDX_LIST, A, L, U);
       OM.ADD_LIN_CONSTRAINT(NAME, IDX_LIST, A, L, U, VARSETS);

   Examples:
       %% linear constraint
       om.add_lin_constraint('vl', Avl, lvl, uvl, {'Pg', 'Qg'});

       %% linear constraints with indexed named set 'R(i,j)'
       om.init_indexed_name('lin', 'R', {2, 3});
       for i = 1:2
         for j = 1:3
           om.add_lin_constraint('R', {i, j}, A{i,j}, ...);
         end
       end

   See also OPT_MODEL, PARAMS_LIN_CONSTRAINT.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function om = add_lin_constraint(om, name, idx, A, l, u, varsets)
0002 %ADD_LIN_CONSTRAINT  Adds a set of linear constraints to the model.
0003 %
0004 %   OM.ADD_LIN_CONSTRAINT(NAME, A, L, U);
0005 %   OM.ADD_LIN_CONSTRAINT(NAME, A, L, U, VARSETS);
0006 %
0007 %   OM.ADD_LIN_CONSTRAINT(NAME, IDX_LIST, A, L, U);
0008 %   OM.ADD_LIN_CONSTRAINT(NAME, IDX_LIST, A, L, U, VARSETS);
0009 %
0010 %   Linear constraints are of the form L <= A * x <= U, where x is a
0011 %   vector made of the vars specified in VARSETS (in the order given).
0012 %   This allows the A matrix to be defined only in terms of the relevant
0013 %   variables without the need to manually create a lot of zero columns.
0014 %   If VARSETS is empty, x is taken to be the full vector of all
0015 %   optimization variables. If L or U are empty, they are assumed to be
0016 %   appropriately sized vectors of -Inf and Inf, respectively.
0017 %
0018 %   Indexed Named Sets
0019 %       A constraint set can be identified by a single NAME, as described
0020 %       above, such as 'Pmismatch', or by a name that is indexed by one
0021 %       or more indices, such as 'Pmismatch(3,4)'. For an indexed named
0022 %       set, before adding the constraint sets themselves, the dimensions
0023 %       of the indexed set must be set by calling INIT_INDEXED_NAME.
0024 %
0025 %       The constraints are then added using the following, where
0026 %       all arguments are as described above, except IDX_LIST is a cell
0027 %       array of the indices for the particular constraint set being added.
0028 %
0029 %       OM.ADD_LIN_CONSTRAINT(NAME, IDX_LIST, A, L, U);
0030 %       OM.ADD_LIN_CONSTRAINT(NAME, IDX_LIST, A, L, U, VARSETS);
0031 %
0032 %   Examples:
0033 %       %% linear constraint
0034 %       om.add_lin_constraint('vl', Avl, lvl, uvl, {'Pg', 'Qg'});
0035 %
0036 %       %% linear constraints with indexed named set 'R(i,j)'
0037 %       om.init_indexed_name('lin', 'R', {2, 3});
0038 %       for i = 1:2
0039 %         for j = 1:3
0040 %           om.add_lin_constraint('R', {i, j}, A{i,j}, ...);
0041 %         end
0042 %       end
0043 %
0044 %   See also OPT_MODEL, PARAMS_LIN_CONSTRAINT.
0045 
0046 %   MATPOWER
0047 %   Copyright (c) 2008-2017, Power Systems Engineering Research Center (PSERC)
0048 %   by Ray Zimmerman, PSERC Cornell
0049 %
0050 %   This file is part of MATPOWER.
0051 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0052 %   See https://matpower.org for more info.
0053 
0054 %% initialize input arguments
0055 if iscell(idx)          %% indexed named set
0056     if nargin < 7
0057         varsets = {};
0058     end
0059 else                    %% simple named set
0060     if nargin < 6
0061         varsets = {};
0062     else
0063         varsets = u;
0064     end
0065     u = l;
0066     l = A;
0067     A = idx;
0068     idx = {};
0069 end
0070 
0071 [N, M] = size(A);
0072 if isempty(l)                   %% default l is -Inf
0073     l = -Inf(N, 1);
0074 end
0075 if isempty(u)                   %% default u is Inf
0076     u = Inf(N, 1);
0077 end
0078 
0079 %% check sizes
0080 if size(l, 1) ~= N || size(u, 1) ~= N
0081     error('@opt_model/add_lin_constraint: sizes of A, l and u must match');
0082 end
0083 
0084 %% convert varsets from cell to struct array if necessary
0085 varsets = om.varsets_cell2struct(varsets);
0086 nv = om.varsets_len(varsets);   %% number of variables
0087 
0088 %% check consistency of varsets with size of A
0089 if M ~= nv
0090     error('@opt_model/add_lin_constraint: number of columns of A does not match\nnumber of variables, A is %d x %d, nv = %d\n', N, M, nv);
0091 end
0092 
0093 %% add the named linear constraint set
0094 om.add_named_set('lin', name, idx, N, A, l, u, varsets);

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