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

    function [seldata, colnames, ptrlist, coninds] = getExportData(obj, pOut, pPROJ, validOnly)
%GETEXPORTDATA Get the optimization results to export
%
%   [SELDATA, COLNAMES, PTRLIST, CONINDS] = GETEXPORTDATA(OBJ, pOUT,
%   pPROJ) retrieves the selected optimal solutions from the supplied
%   CGOPTIMOUTPUT object (pointed at by POUT). The valid CAGE expressions
%   are evaluated at the optimal settings in the OPTIMOUT object. A pointer
%   to the CAGE Project (pPROJ) must also be specified.
%
%   INPUTS:
%   OBJ: GETEXPORTDATA object
%   pOUT: Pointer to CGOPTIMOUTPUT object used for table filling
%   pPROJ: Pointer to CAGE project that variables, models and optimization
%   results reside in
%
%   OUTPUTS:
%   SELDATA: Nrun*MAX(LENGTH(FREEVAR))-by-Ninput matrix of output data
%   COLNAMES: 1-by-Nitems cell array of item names
%   PTRLIST: 1-by-Nitems vector of pointers to optim items
%   CONINDS: Nrun*MAX(LENGTH(FREEVAR))-by-1 logical matrix denoting constraint
%   status, feasible = TRUE.
%   Note that Nitems = Ninput + Nexpr
%
%   [...] = GETEXPORTDATA(OBJ, pOUT, pPROJ, VALIDONLY) retrieves the
%   selected optimal solutions for the valid inputs only

%   Copyright 2005-2009 The MathWorks, Inc.

% Return data for all inputs unless validOnly is specified
if nargin < 4
    validOnly = false;
end

% Get all expressions
[pInputs, inputNames] = getInputExpression(obj, pOut, pPROJ, validOnly);
[pExprs, exprNames] = getValidExpression(obj, pOut, pPROJ);

% Initalise outputs
colnames = [inputNames, exprNames];
ptrlist = [pInputs, pExprs];
seldata = [];
coninds = [];

% Get optimal fixed/free data from optimout. Note that we are assuming that
% the fixed/free variable lengths are either 1 or N. Mixed variable lengths
% are not supported.
if obj.UseAllSolutions
    [indata, inNames] = getAllSolutions(pOut.info, ...
        'OutputContents', {'FreeVars', 'FixedVars'});
else
    [indata, inNames] = getSelectedSolution(pOut.info, ...
        'OutputContents', {'FreeVars', 'FixedVars'});
end    
if any(cellfun('isempty', indata))
    return
end
freelen = cellfun('size', indata, 2);
unitfree = (freelen == 1);
Nfree = max(freelen);
indata(unitfree) = cellfun(@(x) repmat(x, 1, Nfree), ...
    indata(unitfree), 'UniformOutput', false);
if obj.UseAllSolutions
    indata = cellfun(@(x) permute(x,[3 2 1]), indata, 'UniformOutput', false);
end
indata = cellfun(@(x) x(:), indata, 'UniformOutput', false);

% Create selected data matrix. We now only return the fixed and free
% variable data. Data for models is evaluated when required by the child
% classes.
[isinProj, idxInput] = ismember(inNames, inputNames);
nInput = length(pInputs);
seldata = cell(1, nInput);
seldata(idxInput(isinProj)) = indata(isinProj);
seldata = cell2mat(seldata);

% Return constraint status for each point
coninds = pGetConstraintStatus(pOut, Nfree,obj.UseAllSolutions);