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

    function Dstatic = convertToStatic(DS, optim)
%PCOPYDATASETS Copy data from a list of datasets
%
%  DATA = PCOPYDATASETS(OBJ, PFACT, P_DS, P_INP) extracts data and the
%  associated factor pointers from a list of pointers to cgoppoint objects.
%  DATA is a cgstaticdataset array of the same length as P_DS.
%  cgstaticdataset contains mappings to the fixed variables in the data set
%  and the ability to interpolate between the optimization data and the
%  data set for application point sets.

%  Copyright 2009-2010 The MathWorks, Inc. and Ford Global Technologies, Inc.

% Data that is required from each dataset
[InputData, pAllInp] = getinitialvaluedata(optim);
pFixed = getfixedvalues(optim);

pDS = DS.Datasets;
pFact = DS.Variables;

opps = infoarray(pDS);

if isAppPointOptim(DS)
    % get operating point variables from optimization data
    [~,loc] = ismember(DS.OpPointVariables,pAllInp);
    Xop = cat(1,InputData{loc})';
    constraints = getConstraint(optim);
    objectives = getObjectiveFunc(optim);
    
    if ~isnull(DS.ModeVariable)
        [~,loc] = ismember(DS.ModeVariable,pAllInp);
        Xmode = InputData{loc}';
    else
        Xmode = [];
    end
    
end
Dstatic = cell(1,length(pDS));
for n = 1:length(pDS)
    % Only need to copy the data columns that are inputs to the optim or
    % have labels specified for their columns.
    DSName = getname(opps{n});
    
    pF = get(opps{n}, 'ptrlist');
    D = get(opps{n}, 'Data');
    
    % Find columns we want to take
    if isAppPointSet(DS,pDS(n))
        % data set is used in objective or constraint
        % We take operating point variables, defined variables and any
        % inputs that can be read from the dataset (e.g. weights)
        pDSvars = [cellfun( @getInputsFromDataset,  constraints(DS.Constraints==pDS(n)),'UniformOutput',false),...
            cellfun( @getInputsFromDataset,  objectives(DS.Objectives==pDS(n)), 'UniformOutput',false) ];
        pDSvars = unique( [pDSvars{:},pFact{n},DS.OpPointVariables,DS.ModeVariable] );
        pDSvars(isnull(pDSvars)) = [];
    else
        % all optimization variables and defined variables can be read from the data sets
        pDSvars = unique([pFact{n}, pAllInp]);
    end
    
    DSvars = pveceval(pDSvars,@getname);
    % see if we can find any more columns from matching by name
    [OK,ReqIdx] = ismember(get(opps{n},'factors'),DSvars);
    ReqIdx = ReqIdx(OK);
    
    pF = pF(OK);
    Data = D(:, OK);
    % find index into optimization inputs
    [~,FixedVarIdx] = ismember(DSvars(ReqIdx), pveceval(pAllInp,@getname));
    if ~isempty(pFact{n})
        % indices for defined variables
        [~,MatchedColIdx] = ismember(pveceval(pFact{n},@getname),DSvars(ReqIdx));
    else
        MatchedColIdx = [];
    end
    Dstatic{n} = cgstaticdataset(Data,DSName,FixedVarIdx,MatchedColIdx);    
    if isAppPointSet(DS,pDS(n))
        [OKOpVars,locOpVars] = ismember(DS.OpPointVariables,pF);
        if ~all(OKOpVars) || ...
                ~all(ismember(DS.OpPointVariables,pFixed))
            error(message('mbc:cgoptimdataset:InvalidState'))
        end
        if ~isempty(Xmode) && DS.UseMode(n)
            [OKMode,locMode] = ismember(DS.ModeVariable,pF);
            if ~OKMode
                error(message('mbc:cgoptimdataset:InvalidState1'))
            end
            % initalize interpolation between optimization data and data set
            Dstatic{n} = initializeInterpolation(Dstatic{n},Xop,locOpVars,Xmode,locMode);
        else
            % initalize interpolation between optimization data and data set
            Dstatic{n} = initializeInterpolation(Dstatic{n},Xop,locOpVars);
        end
        
    end
    

end

Dstatic = [Dstatic{:}];