www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptim/addBoundaryConstraint.m

    function optim = addBoundaryConstraint(optim, ObjectiveLabel)
%ADDBOUNDARYCONSTRAINT Adds a boundary constraint to the optimization
%
%   OPTIM = ADDBOUNDARYCONSTRAINT(OPTIM, OBJECTIVELABEL) adds a boundary
%   constraint to OPTIM. The boundary of the model in the specified
%   objective is used as the constraint.
%
%   See also CGOPTIM/ADDCONSTRAINT

%   Copyright 2007-2008 The MathWorks, Inc.

% Get model from objective
objFunc = getObjectiveFunc(optim, ObjectiveLabel);
pMod = getExpression(objFunc);

% Create a new point constraint returning a boundary evaluation
pConExpr = xregpointer(cgexprconstraint('Constraint', xregpointer, 'le', 0));
pConExpr.info = setevaluationmode(pConExpr.info, 1, 0);
pConExpr.info = setlhsexpr(pConExpr.info, pMod);
newCon = cgpointconstraint('Constraint', pConExpr);

% Try to set name to a sensible default
defName = getDefaultName(newCon);
label = generateLabel(optim.OptimSetup, defName, 'allowroot');
pConExpr.info = setname(pConExpr.info, label);

% Add the constraint
optim = addConstraint(optim, label, newCon);