Home > matpower6.0 > @opt_model > getv.m

getv

PURPOSE ^

GETV Returns initial value, lower bound and upper bound for opt variables.

SYNOPSIS ^

function [v0, vl, vu, vt] = getv(om, name, idx)

DESCRIPTION ^

GETV  Returns initial value, lower bound and upper bound for opt variables.
   [V0, VL, VU] = GETV(OM)
   [V0, VL, VU] = GETV(OM, NAME)
   [V0, VL, VU] = GETV(OM, NAME, IDX)
   [V0, VL, VU, VT] = GETV(...)
   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] = getv(om);
       [Pg, Pmin, Pmax] = getv(om, 'Pg');
       [zij0, zijmin, zijmax, ztype] = getv(om, 'z', {i, j});
   
   See also OPT_MODEL.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [v0, vl, vu, vt] = getv(om, name, idx)
0002 %GETV  Returns initial value, lower bound and upper bound for opt variables.
0003 %   [V0, VL, VU] = GETV(OM)
0004 %   [V0, VL, VU] = GETV(OM, NAME)
0005 %   [V0, VL, VU] = GETV(OM, NAME, IDX)
0006 %   [V0, VL, VU, VT] = GETV(...)
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] = getv(om);
0015 %       [Pg, Pmin, Pmax] = getv(om, 'Pg');
0016 %       [zij0, zijmin, zijmax, ztype] = getv(om, 'z', {i, j});
0017 %
0018 %   See also OPT_MODEL.
0019 
0020 %   MATPOWER
0021 %   Copyright (c) 2008-2016, 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 http://www.pserc.cornell.edu/matpower/ 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     s1 = struct('type', {'.', '{}'}, 'subs', {'', 1});
0036     for k = 1:om.var.NS
0037         name = om.var.order(k).name;
0038         idx = om.var.order(k).idx;
0039         if isempty(idx)
0040             v0 = [ v0; om.var.data.v0.(name) ];
0041             vl = [ vl; om.var.data.vl.(name) ];
0042             vu = [ vu; om.var.data.vu.(name) ];
0043             if have_vt
0044                 N = om.var.idx.N.(name);
0045                 vt0 = om.var.data.vt.(name);
0046                 if isscalar(vt0) && N > 1 
0047                     vt = [ vt char(vt0 * ones(1, N)) ];
0048                 else
0049                     vt = [ vt vt0 ];
0050                 end
0051             end
0052         else
0053             % (calls to substruct() are relatively expensive ...
0054             % s1 = substruct('.', name, '{}', idx);
0055             % ... so replace it with these more efficient lines)
0056             s1(1).subs = name;
0057             s1(2).subs = idx;
0058             v0 = [ v0; subsref(om.var.data.v0, s1) ];
0059             vl = [ vl; subsref(om.var.data.vl, s1) ];
0060             vu = [ vu; subsref(om.var.data.vu, s1) ];
0061             if have_vt
0062                 % (calls to substruct() are relatively expensive ...
0063                 % s2 = substruct('.', name, '()', idx);
0064                 % ... so replace it with these more efficient lines)
0065                 s2 = s1;
0066                 s2(2).type = '()';
0067                 N = subsref(om.var.idx.N, s2);
0068                 vt0 = subsref(om.var.data.vt, s1);
0069                 if isscalar(vt0) && N > 1 
0070                     vt = [ vt char(vt0 * ones(1, N)) ];
0071                 else
0072                     if ~isempty(vt0)
0073                         vt = [ vt vt0 ];
0074                     end
0075                 end
0076             end
0077         end
0078     end
0079 else
0080     if isfield(om.var.idx.N, name)
0081         if nargin < 3
0082             v0 = om.var.data.v0.(name);
0083             vl = om.var.data.vl.(name);
0084             vu = om.var.data.vu.(name);
0085             if have_vt
0086                 N = om.var.idx.N.(name);
0087                 vt0 = om.var.data.vt.(name);
0088                 if isscalar(vt0) && N > 1 
0089                     vt = char(vt0 * ones(1, N));
0090                 else
0091                     vt = vt0;
0092                 end
0093             end
0094         else
0095             % (calls to substruct() are relatively expensive ...
0096             % s1 = substruct('.', name, '{}', idx);
0097             % ... so replace it with these more efficient lines)
0098             s1 = struct('type', {'.', '{}'}, 'subs', {name, idx});
0099             v0 = subsref(om.var.data.v0, s1);
0100             vl = subsref(om.var.data.vl, s1);
0101             vu = subsref(om.var.data.vu, s1);
0102             if have_vt
0103                 % (calls to substruct() are relatively expensive ...
0104                 % s2 = substruct('.', name, '()', idx);
0105                 % ... so replace it with these more efficient lines)
0106                 s2 = s1;
0107                 s2(2).type = '()';
0108                 N = subsref(om.var.idx.N, s2);
0109                 vt0 = subsref(om.var.data.vt, s1);
0110                 if isscalar(vt0) && N > 1 
0111                     vt = char(vt0 * ones(1, N));
0112                 else
0113                     vt = vt0;
0114                 end
0115             end
0116         end
0117     else
0118         v0 = [];
0119         vl = [];
0120         vu = [];
0121         if have_vt
0122             vt = [];
0123         end
0124     end
0125 end

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005