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

varsets_len

PURPOSE ^

VARSETS_LEN Returns the total number of variables in VARSETS

SYNOPSIS ^

function nv = varsets_len(om, vs)

DESCRIPTION ^

VARSETS_LEN  Returns the total number of variables in VARSETS
   NV = OM.VARSETS_LEN(VARSETS)

   Returns the total number of elements in the optimization sub-vector
   specified by VARSETS.

   See also VARSETS_CELL2STRUCT

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function nv = varsets_len(om, vs)
0002 %VARSETS_LEN  Returns the total number of variables in VARSETS
0003 %   NV = OM.VARSETS_LEN(VARSETS)
0004 %
0005 %   Returns the total number of elements in the optimization sub-vector
0006 %   specified by VARSETS.
0007 %
0008 %   See also VARSETS_CELL2STRUCT
0009 
0010 %   MATPOWER
0011 %   Copyright (c) 2017, Power Systems Engineering Research Center (PSERC)
0012 %   by Ray Zimmerman, PSERC Cornell
0013 %
0014 %   This file is part of MATPOWER.
0015 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0016 %   See https://matpower.org for more info.
0017 
0018 persistent sn;
0019 if isempty(vs)
0020     nv = om.var.N;
0021 else
0022     nv = 0;
0023 
0024     %% calls to substruct() are relatively expensive, so we pre-build the
0025     %% struct for addressing numeric array fields, updating only
0026     %% the subscripts before use
0027     if isempty(sn)
0028         sn = struct('type', {'.', '()'}, 'subs', {'', 1});
0029     end
0030 
0031     for v = 1:length(vs)
0032         % (calls to substruct() are relatively expensive ...
0033         % sn = substruct('.', vs(v).name, '()', vs(v).idx);
0034         % ... so replace it with these more efficient lines)
0035         sn(1).subs = vs(v).name;
0036         sn(2).subs = vs(v).idx;
0037         N = subsref(om.var.idx.N, sn);
0038         nv = nv + sum(N(:));
0039     end
0040 end

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