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

    function varargout = getWeightedSolution(obj, varargin)
%GETWEIGHTEDSOLUTION Return weighted solutions.
%
%  [DATA, COLHEADS] = GETWEIGHTEDSOLUTION(OBJ, OPTION, VALUE) returns a
%  objective values for each solution which are the result of performing
%  the weighted sum over all the runs for each solution.   Named
%  option/value pairs may be specified to control the return value:
%
%    Option          |  Value description
%    ----------------+------------------------------------------------
%    OutputFormat    |  One of 'cell' or 'matrix.  When 'cell', the output
%                    |  data will be a (1-by-NItems) cell array with each
%                    |  cell containing all of the values for that item.
%                    |  ColNames will be a (1-by-NItems) cell array
%                    |  containing a label for each item.  When 'matrix',
%                    |  the output data will be a 2-D matrix that contains
%                    |  all of the items' data concatenated into a
%                    |  (NRuns-by-NItemValues) array.  ColNames will be a
%                    |  (1-by-NItemValues) cell array containing an
%                    |  appropriate label for every column.

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


% Get all objective values
[varargout{1:nargout}] = getAllSolutions(obj, varargin{:}, 'OutputContents', {'objectives'});

if ~isempty(varargout{1})
    % Apply weights
    if iscell(varargout{1})
        Nobj = numObjectives(obj.optimRunner);
        eInds = cumsum(Nobj);
        sInds = eInds + 1;
        sInds(end) = [];
        sInds = [1, sInds];
        for n = 1:length(varargout{1})
            varargout{1}{n} = i_weightandsum(varargout{1}{n}, ...
                obj.outputWeights(:, sInds(n):eInds(n)));
        end
    else
        varargout{1} = i_weightandsum(varargout{1}, obj.outputWeights);
    end 
end



function data = i_weightandsum(data, wts)
sz = size(data);
if numel(sz) < 3
    sz(3) = 1;
end
data = permute(sum(repmat(wts, [1 1 sz(3)]).*data, 1), [3 2 1]);