ADD_VARS Adds a set of variables to the model. OM = ADD_VARS(OM, NAME, N, V0, VL, VU) OM = ADD_VARS(OM, NAME, N, V0, VL) OM = ADD_VARS(OM, NAME, N, V0) OM = ADD_VARS(OM, NAME, N) Adds a set of variables to the model, where N is the number of variables in the set, V0 is the initial value of those variables, and VL and VU are the lower and upper bounds on the variables. The defaults for the last three arguments, which are optional, are for all values to be initialized to zero (V0 = 0) and unbounded (VL = -Inf, VU = Inf). See also OPF_MODEL, GETV.
0001 function om = add_vars(om, name, N, v0, vl, vu) 0002 %ADD_VARS Adds a set of variables to the model. 0003 % OM = ADD_VARS(OM, NAME, N, V0, VL, VU) 0004 % OM = ADD_VARS(OM, NAME, N, V0, VL) 0005 % OM = ADD_VARS(OM, NAME, N, V0) 0006 % OM = ADD_VARS(OM, NAME, N) 0007 % 0008 % Adds a set of variables to the model, where N is the number of 0009 % variables in the set, V0 is the initial value of those variables, 0010 % and VL and VU are the lower and upper bounds on the variables. 0011 % The defaults for the last three arguments, which are optional, 0012 % are for all values to be initialized to zero (V0 = 0) and unbounded 0013 % (VL = -Inf, VU = Inf). 0014 % 0015 % See also OPF_MODEL, GETV. 0016 0017 % MATPOWER 0018 % $Id: add_vars.m,v 1.7 2010/04/26 19:45:25 ray Exp $ 0019 % by Ray Zimmerman, PSERC Cornell 0020 % Copyright (c) 2008-2010 by Power System Engineering Research Center (PSERC) 0021 % 0022 % This file is part of MATPOWER. 0023 % See http://www.pserc.cornell.edu/matpower/ for more info. 0024 % 0025 % MATPOWER is free software: you can redistribute it and/or modify 0026 % it under the terms of the GNU General Public License as published 0027 % by the Free Software Foundation, either version 3 of the License, 0028 % or (at your option) any later version. 0029 % 0030 % MATPOWER is distributed in the hope that it will be useful, 0031 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0032 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0033 % GNU General Public License for more details. 0034 % 0035 % You should have received a copy of the GNU General Public License 0036 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0037 % 0038 % Additional permission under GNU GPL version 3 section 7 0039 % 0040 % If you modify MATPOWER, or any covered work, to interface with 0041 % other modules (such as MATLAB code and MEX-files) available in a 0042 % MATLAB(R) or comparable environment containing parts covered 0043 % under other licensing terms, the licensors of MATPOWER grant 0044 % you additional permission to convey the resulting work. 0045 0046 %% prevent duplicate named var sets 0047 if isfield(om.var.idx.N, name) 0048 error('@opf_model/add_vars: variable set named ''%s'' already exists', name); 0049 end 0050 0051 %% initialize args and assign defaults 0052 if nargin < 6 0053 vu = []; 0054 if nargin < 5 0055 vl = []; 0056 if nargin < 4 0057 v0 = []; 0058 end 0059 end 0060 end 0061 if isempty(v0) 0062 v0 = zeros(N, 1); %% init to zero by default 0063 end 0064 if isempty(vl) 0065 vl = -Inf * ones(N, 1); %% unbounded below by default 0066 end 0067 if isempty(vu) 0068 vu = Inf * ones(N, 1); %% unbounded above by default 0069 end 0070 0071 %% add info about this var set 0072 om.var.idx.i1.(name) = om.var.N + 1; %% starting index 0073 om.var.idx.iN.(name) = om.var.N + N; %% ending index 0074 om.var.idx.N.(name) = N; %% number of vars 0075 om.var.data.v0.(name) = v0; %% initial value 0076 om.var.data.vl.(name) = vl; %% lower bound 0077 om.var.data.vu.(name) = vu; %% upper bound 0078 0079 %% update number of vars and var sets 0080 om.var.N = om.var.idx.iN.(name); 0081 om.var.NS = om.var.NS + 1; 0082 0083 %% put name in ordered list of var sets 0084 om.var.order{om.var.NS} = name;