www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/+cgsimfill/@EvalPoints/EvalPoints.m
classdef EvalPoints < handle & matlab.mixin.Copyable %EVALPOINTS object for managing evaluation points for feature filling problems % % V = EvalPoints( prop/value pairs ); % This class is used by cgsimfill.Feature % Copyright 2008-2012 The MathWorks, Inc. properties (Dependent) %EXPRESSIONS list of pointers to expressions being used in current %EVALPOINT set. Expressions %CONSTRAINT Constraint %VALUES values and links to be used % % {pVar1, Value1, pVar2, Value2} % By default normalizer values are used for table inputs and % nominal values are used for all other variables. % If F.IsGridData is true Values are used to define an % N-dimensional grid of points to evaluate the feature and model % over. If IsGridData is false then the values specify a data set. % It is also possible to specify a link expression instead of a value. % In this case the link expression is evaluated to specify the % values for that variable. Certain kinds of algebraic loops can % be defined using links. Algebraic loops are solved via a penalty % function or equality constraint. % Values can be excluded using Constraint. % % See also Constraint, IsGridData Values Inputs end properties (Access=private) pExpressions pConstraint end properties %ISGRIDDATA values define a grid of data to be used for % % The Constraint property can be used to exclude values at exteme % points on a grid (for example, using a boundary constraint of the % Model). IsGridData = true; %INPUTS inputs to all expressions in feature fill % % Feature, Model, Constraint, Links %ALLOWLOOPS AllowLoops = false; %LOOPS Loops = []; end properties(Dependent,SetAccess=private) LinkedVariables UnlinkedVariables %LINKS matrix [pVariables; pLinkExpressions] Links end properties(Dependent,Access=private) ValueStore; LinkInputStore; end properties(Access=private) pValueStore=mbccellstore; pLinkInputStore = mbccellstore; pInputs = mbcpointer(0,1); end properties(Access=private) StoreKey = guidarray(1); end properties(Transient,Access=private) Listeners = []; ValueStoreListener end methods function V = EvalPoints( varargin ) % cgsimfill.EvalPoints class constructor V.AllowLoops = getpref(mbcprefs('mbc'),'AllowFeatureFillLoops'); if nargin if isa(varargin{1}, 'cgsimfill.EvalPoints') V = varargin{1}; varargin(1) = []; end for i=1:2:length(varargin) V.(varargin{i}) = varargin{i+1}; end V.pInitializeDefaults(); V.pUpdateValueStore(); end end function val = get.Values( V) pValues = V.Inputs; val = { {}, {} }; if ~isempty( pValues ) VarNames = pveceval( pValues, @getname ); VarValues = pGetFromStore( V, pValues ); val = {VarNames, VarValues}; end end function vals = get.Expressions(V) vals = V.pExpressions; end function set.Expressions(V,vals) V.pExpressions = vals; iExpressionOrConstraintChanged( V ) end function val = get.Constraint(V) val = V.pConstraint ; end function set.Constraint(V,val) V.pConstraint = val; iExpressionOrConstraintChanged( V ); end function val = get.ValueStore(V) val = V.pValueStore; end function set.ValueStore(V,val) V.pValueStore = val; pUpdateLinkInputStore(V); end function set.LinkInputStore(V,val) V.pLinkInputStore = val; end function val = get.LinkInputStore(V) val = V.pLinkInputStore ; end %---------------------------------------------------------- function set.Values( V, val ) % Convert old {varname, varvalue} to calls to makeLink/setValue etc if ~isempty( val ) VarNames= val{1}; NewValues= val{2}; for n = 1:length( VarNames ) thisValue = NewValues{n}; thisVariable = V.pFindVariable( VarNames{n} ); if isempty( thisValue ) V.removeLink( thisVariable ); elseif isnumeric( thisValue ) || islogical( thisValue ) V.setValue( thisVariable, thisValue ); else V.makeLink( thisVariable, thisValue ); end end end end function val = get.LinkedVariables(V) val = pGetLinkedVariables(V); end function val = get.UnlinkedVariables(V) val = pGetUnlinkedVariables(V); end function pLink = get.Links(V) pVar = V.LinkedVariables; if isempty( pVar ) pLink = null( xregpointer, size( pVar ) ); else pLink = V.pGetFromStore( pVar ); pLink = [pLink{:}]; end end function set.Inputs(V,val) if isempty(val) && ~isa(val,'xregpointer'); val = mbcpointer(size(val)); end V.pInputs = val; end function v = get.Inputs(V) v = V.pInputs; end function V = mapptr(V,RefMap) % need to reference into store V.pExpressions= mapptr(V.pExpressions,RefMap); V.pConstraint= mapptr(V.pConstraint,RefMap); V.pInputs= mapptr(V.pInputs,RefMap); V.Loops= mapptr(V.Loops,RefMap); V.pValueStore= mapptr(V.pValueStore,RefMap); V.pLinkInputStore= mapptr(V.pLinkInputStore,RefMap); end function pDpt = getDependentPtrs(V) pDpt = [V.pExpressions(:) V.pInputs(:) V.Links(:)]; if ~isempty(V.pConstraint) qTemp = getDependentPtrs(V.pConstraint); pDpt = [pDpt;qTemp(:)]; end pDpt = unique(pDpt); pDpt(pDpt==0)=[]; end function InitializeDefaults( v ) pInitializeDefaults( v ); end end methods (Access=private) pInitializeDefaults( v ); pAddInputToStore(V, pVar, type); [isInput, inputType] = pFindInput(V, pVar); pVar = pFindVariable(V, variable); pInputs = pGetAllExpressionInputs( V ); [value, defaultvalue, islink] = pGetFromStore(V, pVar); pInputs = pGetInputs( V ); pLinked = pGetLinkedVariables(V) pUnlinked = pGetUnlinkedVariables(V) pSetInStore(V, pVar, value, location) pUpdateInputs(V) pUpdateLinkInputStore(V) pRemoveInputFromStore(V, pVar, type) pUpdateValueStore(V) end end %---------------------------------------------------------- function iExpressionOrConstraintChanged( V ) % Make changes in response to changes in the model/strategy or constraint. % When the model/feature/constraint has changed we need to : % 1) Remove any links that are no longer allowed. [pVars, pLinks] = V.getLinks(); for n=1:length( pVars ) if ~V.checkLink( pVars(n), pLinks(n) ) V.removeLink( pVars(n) ); end end % 2) make sure the ValueStore has the right variables in it. pUpdateValueStore(V); end %----------------------------------------------------------