Home > matpower5.1 > @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-2015 by Power System Engineering Research Center (PSERC)
0022 %   by Ray Zimmerman, PSERC Cornell
0023 %
0024 %   $Id: getv.m 2644 2015-03-11 19:34:22Z ray $
0025 %
0026 %   This file is part of MATPOWER.
0027 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0028 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0029 
0030 if nargout > 3
0031     have_vt = 1;
0032 else
0033     have_vt = 0;
0034 end
0035 if nargin < 2
0036     v0 = []; vl = []; vu = []; vt = char([]);
0037     s1 = struct('type', {'.', '{}'}, 'subs', {'', 1});
0038     for k = 1:om.var.NS
0039         name = om.var.order(k).name;
0040         idx = om.var.order(k).idx;
0041         if isempty(idx)
0042             v0 = [ v0; om.var.data.v0.(name) ];
0043             vl = [ vl; om.var.data.vl.(name) ];
0044             vu = [ vu; om.var.data.vu.(name) ];
0045             if have_vt
0046                 N = om.var.idx.N.(name);
0047                 vt0 = om.var.data.vt.(name);
0048                 if isscalar(vt0) && N > 1 
0049                     vt = [ vt char(vt0 * ones(1, N)) ];
0050                 else
0051                     vt = [ vt vt0 ];
0052                 end
0053             end
0054         else
0055             % (calls to substruct() are relatively expensive ...
0056             % s1 = substruct('.', name, '{}', idx);
0057             % ... so replace it with these more efficient lines)
0058             s1(1).subs = name;
0059             s1(2).subs = idx;
0060             v0 = [ v0; subsref(om.var.data.v0, s1) ];
0061             vl = [ vl; subsref(om.var.data.vl, s1) ];
0062             vu = [ vu; subsref(om.var.data.vu, s1) ];
0063             if have_vt
0064                 % (calls to substruct() are relatively expensive ...
0065                 % s2 = substruct('.', name, '()', idx);
0066                 % ... so replace it with these more efficient lines)
0067                 s2 = s1;
0068                 s2(2).type = '()';
0069                 N = subsref(om.var.idx.N, s2);
0070                 vt0 = subsref(om.var.data.vt, s1);
0071                 if isscalar(vt0) && N > 1 
0072                     vt = [ vt char(vt0 * ones(1, N)) ];
0073                 else
0074                     vt = [ vt vt0 ];
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 20-Mar-2015 18:23:34 by m2html © 2005