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

    function [status, msg] = checkSizes(optim)
%CHECKSIZES Check that the sizes of items are acceptable
%
%  [STATUS, MSG] = CHECKSIZES(OPTIM) checks that the algorithm will accept
%  the lengths of the free variables and the number of outputs from each
%  objective and constraint.
%
%  STATUS contains an integer code indicating whether the setup 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 string that
%  describes the problem and should be non-empty for a non-zero status.

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


status = 0;
msg = '';

% Check number of free values is ok
NFree = sum(pGetValueSizes(optim, optim.values));
[unused, mn, mx] = numVariables(optim.OptimSetup);
if NFree<mn
    status = 2;
    msg = 'The optimization contains too few free variables.';
elseif NFree>mx
    status = 2;
    msg = 'The optimization contains too many free variables.';
end

if status==2
    return
end


% Check number of objective values is ok
[InLen, pVal] = getvaluedatasizes(optim);
OutLen = i_getitemoutlengths(pVal, InLen, getObjectiveFunc(optim));
NObj = sum(OutLen);
[unused, mn, mx] = numObjectives(optim.OptimSetup);
if NObj<mn
    status = 2;
    msg = 'The optimization contains too few objective values.';
elseif NObj>mx
    status = 2;
    msg = ['The optimization contains too many objective values.', ...
        char(10), char(10), ...
        'If you are using a single objective optimization algorithm and ', ...
        'any ''Number of values'' is greater than 1, ', ...
        'change your objective to a Sum Objective.', char(10), char(10)', ...
        'For more information, see the Algorithm Restrictions section in ', ...
        'the CAGE Users Guide.'];
end

if status==2
    return
end

% Check number of constraint values is ok
OutLen = i_getitemoutlengths(pVal, InLen, getEnabledConstraints(optim));
NCon = sum(OutLen);
[unused, mn, mx] = numConstraints(optim.OptimSetup);
if NCon<mn
    status = 2;
    msg = 'The optimization contains too few constraint values.';
elseif NCon>mx
    status = 2;
    msg = 'The optimization contains too many constraint values.';
end




function OutLen = i_getitemoutlengths(pAllInp, InLen, items)
OutLen = zeros(size(items));
for n = 1:numel(items)
    pInputs = getInputs(items{n});
    InputIdx = findptrs(pInputs, pAllInp); 
    OutLen(n) = getNumOutputs(items{n}, InLen(InputIdx));
end