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

    function [status, msg] = checkConstraints(optim, idx)
%CHECKCONSTRAINTS Check the status for constraints
%
%  [STATUS, MSG] = CHECKCONSTRAINTS(OPTIM) returns a vector of status
%  codes and a cell array of associated messages, one for each constraint
%  item in the optimization.
%
%  [STATUS, MSG] = CHECKCONSTRAINTS(OPTIM, INDEX) returns the status and
%  messages for the specified constraints.  INDEX may be numerical indices
%  into the constraint list or a cell array of labels.
%
%  STATUS is a vector that contains integer codes indicating whether each
%  item is in an acceptable state.  A status of 0 indicates no problem, 1
%  indicates a warning issue and 2 indicates an critical problem.  MSG is a
%  cell array of strings that describes the problem and should be non-empty
%  for items that have a non-zero status.

%  Copyright 2005-2014 The MathWorks, Inc. and Ford Global Technologies, Inc.


if nargin<2
    idx = 1:length(optim.Constraints);
else
    if ~isnumeric(idx)
        idx = getConstraintIndex(optim.OptimSetup, idx);
    end
end

% check constraints
[status, msg] = pCheckItems(optim, optim.Constraints(idx), 'Constraint','Constraints');
    
% Disabled constraints are given a special warning message.
enstate = optim.ConstraintEnabled(idx);
if ~all(enstate)
    status(~enstate) = 1;
    msg(~enstate) = {'Constraint is disabled.'};
end