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

add_var

PURPOSE ^

ADD_VAR Adds a set of variables to the model.

SYNOPSIS ^

function om = add_var(om, name, idx, varargin)

DESCRIPTION ^

ADD_VAR  Adds a set of variables to the model.
   OM.ADD_VAR(NAME, N, V0, VL, VU, VT)
   OM.ADD_VAR(NAME, N, V0, VL, VU)
   OM.ADD_VAR(NAME, N, V0, VL)
   OM.ADD_VAR(NAME, N, V0)
   OM.ADD_VAR(NAME, N)
   OM.ADD_VAR(NAME, DIM_LIST) (deprecated, use INIT_INDEXED_NAME instead)
   OM.ADD_VAR(NAME, IDX_LIST, N, V0, VL, VU, VT)
   OM.ADD_VAR(NAME, IDX_LIST, N, V0, VL, VU)
   OM.ADD_VAR(NAME, IDX_LIST, N, V0, VL)
   OM.ADD_VAR(NAME, IDX_LIST, N, V0)
   OM.ADD_VAR(NAME, IDX_LIST, 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,
   VL and VU are the lower and upper bounds on the variables and VT
   is the variable type. The accepted values for elements of VT are:
       'C' - continuous
       'I' - integer
       'B' - binary
   V0, VL and VU are N x 1 column vectors, VT is a scalar or a 1 x N row
   vector. The defaults for the last four arguments, which are all optional,
   are for all values to be initialized to zero (V0 = 0), unbounded
   (VL = -Inf, VU = Inf), and continuous (VT = 'C').

   Examples:
       om.add_var('V', nb, V0, Vmin, Vmax, 'C');

       om.init_indexed_name('x', {2, 3});
       for i = 1:2
         for j = 1:3
           om.add_var('x', {i, j}, nx(i,j), ...);
         end
       end

   See also OPT_MODEL, PARAMS_VAR.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function om = add_var(om, name, idx, varargin)
0002 %ADD_VAR  Adds a set of variables to the model.
0003 %   OM.ADD_VAR(NAME, N, V0, VL, VU, VT)
0004 %   OM.ADD_VAR(NAME, N, V0, VL, VU)
0005 %   OM.ADD_VAR(NAME, N, V0, VL)
0006 %   OM.ADD_VAR(NAME, N, V0)
0007 %   OM.ADD_VAR(NAME, N)
0008 %   OM.ADD_VAR(NAME, DIM_LIST) (deprecated, use INIT_INDEXED_NAME instead)
0009 %   OM.ADD_VAR(NAME, IDX_LIST, N, V0, VL, VU, VT)
0010 %   OM.ADD_VAR(NAME, IDX_LIST, N, V0, VL, VU)
0011 %   OM.ADD_VAR(NAME, IDX_LIST, N, V0, VL)
0012 %   OM.ADD_VAR(NAME, IDX_LIST, N, V0)
0013 %   OM.ADD_VAR(NAME, IDX_LIST, N)
0014 %
0015 %   Adds a set of variables to the model, where N is the number of
0016 %   variables in the set, V0 is the initial value of those variables,
0017 %   VL and VU are the lower and upper bounds on the variables and VT
0018 %   is the variable type. The accepted values for elements of VT are:
0019 %       'C' - continuous
0020 %       'I' - integer
0021 %       'B' - binary
0022 %   V0, VL and VU are N x 1 column vectors, VT is a scalar or a 1 x N row
0023 %   vector. The defaults for the last four arguments, which are all optional,
0024 %   are for all values to be initialized to zero (V0 = 0), unbounded
0025 %   (VL = -Inf, VU = Inf), and continuous (VT = 'C').
0026 %
0027 %   Examples:
0028 %       om.add_var('V', nb, V0, Vmin, Vmax, 'C');
0029 %
0030 %       om.init_indexed_name('x', {2, 3});
0031 %       for i = 1:2
0032 %         for j = 1:3
0033 %           om.add_var('x', {i, j}, nx(i,j), ...);
0034 %         end
0035 %       end
0036 %
0037 %   See also OPT_MODEL, PARAMS_VAR.
0038 
0039 %   MATPOWER
0040 %   Copyright (c) 2008-2017, Power Systems Engineering Research Center (PSERC)
0041 %   by Ray Zimmerman, PSERC Cornell
0042 %
0043 %   This file is part of MATPOWER.
0044 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0045 %   See https://matpower.org for more info.
0046 
0047 %% set up default args
0048 if iscell(idx) && isempty(varargin) %% just setting dimensions for indexed set
0049     om.init_indexed_name('var', name, idx);
0050 else
0051     if iscell(idx)
0052         N = varargin{1};
0053         args = varargin(2:end);
0054     else
0055         N = idx;
0056         idx = {};
0057         args = varargin;
0058     end
0059     nargs = length(args);
0060     
0061     v0 = []; vl = []; vu = []; vt = [];
0062     if nargs >= 1
0063         v0 = args{1};
0064         if nargs >= 2
0065             vl = args{2};
0066             if nargs >= 3
0067                 vu = args{3};
0068                 if nargs >= 4
0069                     vt = args{4};
0070                 end
0071             end
0072         end
0073     end
0074     if isempty(v0)
0075         v0 = zeros(N, 1);   %% init to zero by default
0076     end
0077     if isempty(vl)
0078         vl = -Inf(N, 1);    %% unbounded below by default
0079     end
0080     if isempty(vu)
0081         vu = Inf(N, 1);     %% unbounded above by default
0082     end
0083     if isempty(vt) && N > 0
0084         vt = 'C';           %% all continuous by default
0085     end
0086 
0087     %% add the named variable set
0088     om.add_named_set('var', name, idx, N, v0, vl, vu, vt);
0089 end

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