PARAMS_VAR Returns initial value, lower bound and upper bound for opt variables. [V0, VL, VU] = OM.PARAMS_VAR() [V0, VL, VU] = OM.PARAMS_VAR(NAME) [V0, VL, VU] = OM.PARAMS_VAR(NAME, IDX) [V0, VL, VU, VT] = PARAMS_VAR(...) Returns the initial value V0, lower bound VL and upper bound VU for the full optimization variable vector, or for a specific named or named and indexed variable set. Optionally also returns a corresponding char vector VT of variable types, where 'C', 'I' and 'B' represent continuous integer and binary variables, respectively. Examples: [x, xmin, xmax] = om.params_var(); [Pg, Pmin, Pmax] = om.params_var('Pg'); [zij0, zijmin, zijmax, ztype] = om.params_var('z', {i, j}); See also OPT_MODEL.
0001 function [v0, vl, vu, vt] = params_var(om, name, idx) 0002 %PARAMS_VAR Returns initial value, lower bound and upper bound for opt variables. 0003 % [V0, VL, VU] = OM.PARAMS_VAR() 0004 % [V0, VL, VU] = OM.PARAMS_VAR(NAME) 0005 % [V0, VL, VU] = OM.PARAMS_VAR(NAME, IDX) 0006 % [V0, VL, VU, VT] = PARAMS_VAR(...) 0007 % Returns the initial value V0, lower bound VL and upper bound VU for 0008 % the full optimization variable vector, or for a specific named or named 0009 % and indexed variable set. Optionally also returns a corresponding char 0010 % vector VT of variable types, where 'C', 'I' and 'B' represent continuous 0011 % integer and binary variables, respectively. 0012 % 0013 % Examples: 0014 % [x, xmin, xmax] = om.params_var(); 0015 % [Pg, Pmin, Pmax] = om.params_var('Pg'); 0016 % [zij0, zijmin, zijmax, ztype] = om.params_var('z', {i, j}); 0017 % 0018 % See also OPT_MODEL. 0019 0020 % MATPOWER 0021 % Copyright (c) 2008-2017, Power Systems Engineering Research Center (PSERC) 0022 % by Ray Zimmerman, PSERC Cornell 0023 % 0024 % This file is part of MATPOWER. 0025 % Covered by the 3-clause BSD License (see LICENSE file for details). 0026 % See https://matpower.org for more info. 0027 0028 if nargout > 3 0029 have_vt = 1; 0030 else 0031 have_vt = 0; 0032 end 0033 if nargin < 2 0034 v0 = []; vl = []; vu = []; vt = char([]); 0035 %% calls to substruct() are relatively expensive, so we pre-build the 0036 %% structs for addressing cell and numeric array fields, updating only 0037 %% the subscripts before use 0038 sc = struct('type', {'.', '{}'}, 'subs', {'', 1}); %% cell array field 0039 for k = 1:om.var.NS 0040 name = om.var.order(k).name; 0041 idx = om.var.order(k).idx; 0042 if isempty(idx) 0043 v0 = [ v0; om.var.data.v0.(name) ]; 0044 vl = [ vl; om.var.data.vl.(name) ]; 0045 vu = [ vu; om.var.data.vu.(name) ]; 0046 if have_vt 0047 N = om.var.idx.N.(name); 0048 vt0 = om.var.data.vt.(name); 0049 if isscalar(vt0) && N > 1 0050 vt = [ vt char(vt0 * ones(1, N)) ]; 0051 else 0052 vt = [ vt vt0 ]; 0053 end 0054 end 0055 else 0056 % (calls to substruct() are relatively expensive ... 0057 % sc = substruct('.', name, '{}', idx); 0058 % ... so replace it with these more efficient lines) 0059 sc(1).subs = name; 0060 sc(2).subs = idx; 0061 v0 = [ v0; subsref(om.var.data.v0, sc) ]; 0062 vl = [ vl; subsref(om.var.data.vl, sc) ]; 0063 vu = [ vu; subsref(om.var.data.vu, sc) ]; 0064 if have_vt 0065 % (calls to substruct() are relatively expensive ... 0066 % sn = substruct('.', name, '()', idx); 0067 % ... so replace it with these more efficient lines) 0068 sn = sc; sn(2).type = '()'; 0069 N = subsref(om.var.idx.N, sn); 0070 vt0 = subsref(om.var.data.vt, sc); 0071 if isscalar(vt0) && N > 1 0072 vt = [ vt char(vt0 * ones(1, N)) ]; 0073 else 0074 if ~isempty(vt0) 0075 vt = [ vt vt0 ]; 0076 end 0077 end 0078 end 0079 end 0080 end 0081 else 0082 if isfield(om.var.idx.N, name) 0083 if nargin < 3 0084 v0 = om.var.data.v0.(name); 0085 vl = om.var.data.vl.(name); 0086 vu = om.var.data.vu.(name); 0087 if have_vt 0088 N = om.var.idx.N.(name); 0089 vt0 = om.var.data.vt.(name); 0090 if isscalar(vt0) && N > 1 0091 vt = char(vt0 * ones(1, N)); 0092 else 0093 vt = vt0; 0094 end 0095 end 0096 else 0097 % (calls to substruct() are relatively expensive ... 0098 % sc = substruct('.', name, '{}', idx); 0099 % ... so replace it with these more efficient lines) 0100 sc = struct('type', {'.', '{}'}, 'subs', {name, idx}); 0101 v0 = subsref(om.var.data.v0, sc); 0102 vl = subsref(om.var.data.vl, sc); 0103 vu = subsref(om.var.data.vu, sc); 0104 if have_vt 0105 % (calls to substruct() are relatively expensive ... 0106 % sn = substruct('.', name, '()', idx); 0107 % ... so replace it with these more efficient lines) 0108 sn = sc; sn(2).type = '()'; 0109 N = subsref(om.var.idx.N, sn); 0110 vt0 = subsref(om.var.data.vt, sc); 0111 if isscalar(vt0) && N > 1 0112 vt = char(vt0 * ones(1, N)); 0113 else 0114 vt = vt0; 0115 end 0116 end 0117 end 0118 else 0119 v0 = []; 0120 vl = []; 0121 vu = []; 0122 if have_vt 0123 vt = []; 0124 end 0125 end 0126 end