Home > matpower4.0 > @opf_model > add_constraints.m

add_constraints

PURPOSE ^

ADD_CONSTRAINTS Adds a set of constraints to the model.

SYNOPSIS ^

function om = add_constraints(om, name, AorN, l, u, varsets)

DESCRIPTION ^

ADD_CONSTRAINTS  Adds a set of constraints to the model.
   OM = ADD_CONSTRAINTS(OM, NAME, A, L, U);
   OM = ADD_CONSTRAINTS(OM, NAME, A, L, U, VARSETS);
   OM = ADD_CONSTRAINTS(OM, NAME, N, 'NON-LINEAR');

   Linear constraints are of the form L <= A * x <= U, where
   x is a vector made of 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.

   For nonlinear constraints, the 3rd argument, N, is the number
   of constraints in the set. Currently, this is used internally
   by MATPOWER, but there is no way for the user to specify
   additional nonlinear constraints.

   Examples:
     om = add_constraints(om, 'vl', Avl, lvl, uvl, {'Pg', 'Qg'});
     om = add_constraints(om, 'Pmis', nb, 'nonlinear');

   See also OPF_MODEL, LINEAR_CONSTRAINTS.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function om = add_constraints(om, name, AorN, l, u, varsets)
0002 %ADD_CONSTRAINTS  Adds a set of constraints to the model.
0003 %   OM = ADD_CONSTRAINTS(OM, NAME, A, L, U);
0004 %   OM = ADD_CONSTRAINTS(OM, NAME, A, L, U, VARSETS);
0005 %   OM = ADD_CONSTRAINTS(OM, NAME, N, 'NON-LINEAR');
0006 %
0007 %   Linear constraints are of the form L <= A * x <= U, where
0008 %   x is a vector made of of the vars specified in VARSETS (in
0009 %   the order given). This allows the A matrix to be defined only
0010 %   in terms of the relevant variables without the need to manually
0011 %   create a lot of zero columns. If VARSETS is empty, x is taken
0012 %   to be the full vector of all optimization variables. If L or
0013 %   U are empty, they are assumed to be appropriately sized vectors
0014 %   of -Inf and Inf, respectively.
0015 %
0016 %   For nonlinear constraints, the 3rd argument, N, is the number
0017 %   of constraints in the set. Currently, this is used internally
0018 %   by MATPOWER, but there is no way for the user to specify
0019 %   additional nonlinear constraints.
0020 %
0021 %   Examples:
0022 %     om = add_constraints(om, 'vl', Avl, lvl, uvl, {'Pg', 'Qg'});
0023 %     om = add_constraints(om, 'Pmis', nb, 'nonlinear');
0024 %
0025 %   See also OPF_MODEL, LINEAR_CONSTRAINTS.
0026 
0027 %   MATPOWER
0028 %   $Id: add_constraints.m,v 1.7 2010/06/09 14:56:58 ray Exp $
0029 %   by Ray Zimmerman, PSERC Cornell
0030 %   Copyright (c) 2008-2010 by Power System Engineering Research Center (PSERC)
0031 %
0032 %   This file is part of MATPOWER.
0033 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0034 %
0035 %   MATPOWER is free software: you can redistribute it and/or modify
0036 %   it under the terms of the GNU General Public License as published
0037 %   by the Free Software Foundation, either version 3 of the License,
0038 %   or (at your option) any later version.
0039 %
0040 %   MATPOWER is distributed in the hope that it will be useful,
0041 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0042 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0043 %   GNU General Public License for more details.
0044 %
0045 %   You should have received a copy of the GNU General Public License
0046 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0047 %
0048 %   Additional permission under GNU GPL version 3 section 7
0049 %
0050 %   If you modify MATPOWER, or any covered work, to interface with
0051 %   other modules (such as MATLAB code and MEX-files) available in a
0052 %   MATLAB(R) or comparable environment containing parts covered
0053 %   under other licensing terms, the licensors of MATPOWER grant
0054 %   you additional permission to convey the resulting work.
0055 
0056 if nargin < 5       %% nonlinear
0057     %% prevent duplicate named constraint sets
0058     if isfield(om.nln.idx.N, name)
0059         error('@opf_model/add_constraints: nonlinear constraint set named ''%s'' already exists', name);
0060     end
0061 
0062     %% add info about this nonlinear constraint set
0063     om.nln.idx.i1.(name) = om.nln.N + 1;    %% starting index
0064     om.nln.idx.iN.(name) = om.nln.N + AorN; %% ending index
0065     om.nln.idx.N.(name)  = AorN;            %% number of constraints
0066     
0067     %% update number of nonlinear constraints and constraint sets
0068     om.nln.N  = om.nln.idx.iN.(name);
0069     om.nln.NS = om.nln.NS + 1;
0070 
0071     %% put name in ordered list of constraint sets
0072     om.nln.order{om.nln.NS} = name;
0073 else                %% linear
0074     %% prevent duplicate named constraint sets
0075     if isfield(om.lin.idx.N, name)
0076         error('@opf_model/add_constraints: linear constraint set named ''%s'' already exists', name);
0077     end
0078 
0079     if nargin < 6
0080         varsets = {};
0081     end
0082     [N, M] = size(AorN);
0083     if isempty(l)                   %% default l is -Inf
0084         l = -Inf * ones(N, 1);
0085     end
0086     if isempty(u)                   %% default u is Inf
0087         u = Inf * ones(N, 1);
0088     end
0089     if isempty(varsets)
0090         varsets = om.var.order;
0091     end
0092 
0093     %% check sizes
0094     if size(l, 1) ~= N || size(u, 1) ~= N
0095         error('@opf_model/add_constraints: sizes of A, l and u must match');
0096     end
0097     nv = 0;
0098     for k = 1:length(varsets)
0099         nv = nv + om.var.idx.N.(varsets{k});
0100     end
0101     if M ~= nv
0102         error('@opf_model/add_constraints: number of columns of A does not match\nnumber of variables, A is %d x %d, nv = %d\n', N, M, nv);
0103     end
0104 
0105     %% add info about this linear constraint set
0106     om.lin.idx.i1.(name)  = om.lin.N + 1;   %% starting index
0107     om.lin.idx.iN.(name)  = om.lin.N + N;   %% ending index
0108     om.lin.idx.N.(name)   = N;              %% number of constraints
0109     om.lin.data.A.(name)  = AorN;
0110     om.lin.data.l.(name)  = l;
0111     om.lin.data.u.(name)  = u;
0112     om.lin.data.vs.(name) = varsets;
0113     
0114     %% update number of vars and var sets
0115     om.lin.N  = om.lin.idx.iN.(name);
0116     om.lin.NS = om.lin.NS + 1;
0117     
0118     %% put name in ordered list of var sets
0119     om.lin.order{om.lin.NS} = name;
0120 end

Generated on Mon 26-Jan-2015 14:56:45 by m2html © 2005