Home > matpower7.1 > extras > syngrid > lib > sgvm_SolnStash.m

sgvm_SolnStash

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 classdef sgvm_SolnStash < handle
0002 %SGVM_SOLNSTASH collection of successfully solved SGVM_INDCLASS object.
0003 %   S = SGVM_SOLNSTASH(N) sets up a stash object that will hold N individuals
0004 %   i.e, SGVM_INDCLASS objects.
0005 %
0006 %   The SGVM_SOLNSTASH is a helper class that keeps the best n individuals.
0007 
0008 %   SynGrid
0009 %   Copyright (c) 2018, Power Systems Engineering Research Center (PSERC)
0010 %   by Eran Schweitzer, Arizona State University
0011 %
0012 %   This file is part of SynGrid.
0013 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0014 
0015     properties
0016         size
0017         inds
0018         ids
0019         count
0020         maxobj
0021     end
0022     methods
0023         function obj = sgvm_SolnStash(n)
0024             obj.size = n;
0025             obj.inds = cell(1,n);
0026             obj.ids  = cell(1,n);
0027             obj.count = 0;
0028             obj.maxobj = Inf;
0029         end
0030 
0031         function update(obj, inds)
0032             for k = 1:length(inds)
0033             if (inds{k}.mpc.f < obj.maxobj) && ~ismember(inds{k}.id, obj.ids(1:obj.count))
0034                 if obj.count < obj.size
0035                         obj.count = obj.count + 1;
0036                     end
0037                     obj.inds{obj.count} = inds{k};
0038                     obj.ids{obj.count}  = inds{k}.id;
0039                 end
0040                 obj.sort();
0041                 if obj.count == obj.size
0042                     obj.maxobj = obj.inds{end}.mpc.f;
0043                 end
0044             end
0045         end
0046 
0047         function obj = sort(obj)
0048             [~, tmp] = sort(cellfun(@(x) x.mpc.f, obj.inds(1:obj.count)));
0049             obj.inds(1:obj.count) = obj.inds(tmp);
0050             obj.ids(1:obj.count)  = obj.ids(tmp);
0051         end
0052 
0053         function stats(obj)
0054             sgvm_collection_stats(obj, 'inds');
0055         end
0056     end
0057 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005