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

    function [status, msg] = pCheckItems(optim, items, TypeStr, DSType)
%PCHECKITEMS Check the status for specified items
%
%  [STATUS, MSG] = PCHECKITEMS(OPTIM, ITEMS, TYPESTR, DSType) returns a vector of
%  status codes and a cell array of associated messages, one for each
%  optimization item in ITEMS.
%  TYPESTR is used for the status message (Objective/Constraint)
%  DSType is used to reference the cgoptimdataset (Objectives/Constraints)

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


nItems = length(items);
status = zeros(nItems,1);
msg = cell(nItems,1);

DS = optim.oppoints;

% Overall status of application point sets: this status will apply to
% any items that have an application point set
[AppPointStatus, AppPointMsg] = checkAppPointSetup(DS, optim);

dsTypeIsSpecified = nargin>=4;

for n = 1:length(items)
    % Check item parameters
    [status(n), msg{n}] = checkSetup(items{n});
    
    if status(n)<2
        % We only have a warning so far so check the input value sizes too
        %
        pV = getInputs(items{n});
        S = pGetValueSizes(optim, pV);
        [inpS, inpMsg] = checkInputSizes(items{n}, S);
        if any(inpS>status(n))
            % If the input check returns a "worse" status than the parameter
            % check then use it as the status return.
            status(n) = max(inpS);
            msg{n} = inpMsg;
        end
    end
    
    
    if status(n)<2 && dsTypeIsSpecified && ~isnull(DS.(DSType)(n))
        % Application point set checks apply to this item
   
        if AppPointStatus>status(n)
            % Use overall application point status as the return
            status(n) = AppPointStatus;
            msg{n} = AppPointMsg;
        end
        
        if status(n)<2
            % check application point sets for this item
            [DSstatus,DSmsg] = checkAppPointSet(DS, DS.(DSType)(n), optim);
            if DSstatus>status(n)
                % if AppPoint check was worse than the parameter check
                % check then use it as the status return.
                status(n) = DSstatus;
                msg{n} = DSmsg;
            end
        end
    end
    
    if status(n)==0
        % Final check only done if nothing has come up yet: check that the
        % item depends on a free variable
        if ~anymember(optim.values, pV)
            status(n) = 1;
            msg{n} = sprintf('%s does not depend on free variables', TypeStr);
        end
    end
    
end