www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgsumconstraint/cgsumconstraint.m
function obj = cgsumconstraint(varargin) %CGSUMCONSTRAINT Constructor for cgsumconstraint class % % OBJ = CGSUMCONSTRAINT(NAME, PEXPR, OP, BOUND) constructs a new % cgsumconstraint with the given name. This class implements a % constraint, where a weighted sum of PEXPR is bounded above (OP = 'le'), % below (OP = 'ge') or equal to (OP = 'eq') BOUND % % See also CGPOINTCONSTRAINT % Copyright 2005-2007 The MathWorks, Inc. and Ford Global Technologies, Inc. DoPostConstructionTasks = false; if nargin && isstruct(varargin{1}) s = varargin{1}; prnt = s.cgoptimconstraint; s = rmfield(s, 'cgoptimconstraint'); else if nargin<1 superargs = {'Constraint'}; else DoPostConstructionTasks = true; superargs = varargin(1); end if nargin<2 pExpr = mbcpointer(1); else pExpr = varargin{2}; end if nargin<3 op = 'le'; else op = varargin{3}; end if nargin<4 bound = 0; else bound = varargin{4}; end s = struct('Expression', pExpr, ... 'Weights', mbcpointer(1), ... 'CompOperator', str2func(op),... 'Bound', bound, ... 'DistanceScale', 1, ... 'Version', 2); prnt = cgoptimconstraint(superargs{:}); end obj = class(s, 'cgsumconstraint', prnt); if DoPostConstructionTasks % Only create weights if we are creating object and not loading it, as % we cannot rely on the heap being mapped at this point. obj.Weights = pCreateWeightsPtr(obj); % Update typical value for an element of the sum obj = updateranges(obj); end