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

linear_constraints

PURPOSE ^

LINEAR_CONSTRAINTS Builds and returns the full set of linear constraints.

SYNOPSIS ^

function [A, l, u] = linear_constraints(om)

DESCRIPTION ^

LINEAR_CONSTRAINTS  Builds and returns the full set of linear constraints.
   [A, L, U] = LINEAR_CONSTRAINTS(OM)
   Builds the full set of linear constraints based on those added by
   ADD_CONSTRAINTS.

       L <= A * x <= U

   Example:
       [A, l, u] = linear_constraints(om);

   See also OPF_MODEL, ADD_CONSTRAINTS.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [A, l, u] = linear_constraints(om)
0002 %LINEAR_CONSTRAINTS  Builds and returns the full set of linear constraints.
0003 %   [A, L, U] = LINEAR_CONSTRAINTS(OM)
0004 %   Builds the full set of linear constraints based on those added by
0005 %   ADD_CONSTRAINTS.
0006 %
0007 %       L <= A * x <= U
0008 %
0009 %   Example:
0010 %       [A, l, u] = linear_constraints(om);
0011 %
0012 %   See also OPF_MODEL, ADD_CONSTRAINTS.
0013 
0014 %   MATPOWER
0015 %   $Id: linear_constraints.m,v 1.7 2010/04/26 19:45:25 ray Exp $
0016 %   by Ray Zimmerman, PSERC Cornell
0017 %   Copyright (c) 2008-2010 by Power System Engineering Research Center (PSERC)
0018 %
0019 %   This file is part of MATPOWER.
0020 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0021 %
0022 %   MATPOWER is free software: you can redistribute it and/or modify
0023 %   it under the terms of the GNU General Public License as published
0024 %   by the Free Software Foundation, either version 3 of the License,
0025 %   or (at your option) any later version.
0026 %
0027 %   MATPOWER is distributed in the hope that it will be useful,
0028 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0029 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0030 %   GNU General Public License for more details.
0031 %
0032 %   You should have received a copy of the GNU General Public License
0033 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0034 %
0035 %   Additional permission under GNU GPL version 3 section 7
0036 %
0037 %   If you modify MATPOWER, or any covered work, to interface with
0038 %   other modules (such as MATLAB code and MEX-files) available in a
0039 %   MATLAB(R) or comparable environment containing parts covered
0040 %   under other licensing terms, the licensors of MATPOWER grant
0041 %   you additional permission to convey the resulting work.
0042 
0043 
0044 %% initialize A, l and u
0045 nnzA = 0;
0046 for k = 1:om.lin.NS
0047     nnzA = nnzA + nnz(om.lin.data.A.(om.lin.order{k}));
0048 end
0049 A = sparse([], [], [], om.lin.N, om.var.N, nnzA);
0050 u = Inf * ones(om.lin.N, 1);
0051 l = -u;
0052 
0053 %% fill in each piece
0054 for k = 1:om.lin.NS
0055     name = om.lin.order{k};
0056     N = om.lin.idx.N.(name);
0057     if N                                %% non-zero number of rows to add
0058         Ak = om.lin.data.A.(name);          %% A for kth linear constrain set
0059         i1 = om.lin.idx.i1.(name);          %% starting row index
0060         iN = om.lin.idx.iN.(name);          %% ending row index
0061         vsl = om.lin.data.vs.(name);        %% var set list
0062         kN = 0;                             %% initialize last col of Ak used
0063         Ai = sparse(N, om.var.N);
0064         for v = 1:length(vsl)
0065             j1 = om.var.idx.i1.(vsl{v});    %% starting column in A
0066             jN = om.var.idx.iN.(vsl{v});    %% ending column in A
0067             k1 = kN + 1;                    %% starting column in Ak
0068             kN = kN + om.var.idx.N.(vsl{v});%% ending column in Ak
0069             Ai(:, j1:jN) = Ak(:, k1:kN);
0070         end
0071 
0072         A(i1:iN, :) = Ai;        
0073         l(i1:iN) = om.lin.data.l.(name);
0074         u(i1:iN) = om.lin.data.u.(name);
0075     end
0076 end

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