www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregoptmgr/xregoptmgr.m

    function F = xregoptmgr(strategyFcn,ContextObj,costFcn)
%XREGOPTMGR Optimisation manager class
%
%  F=
%  contextImplementation(xregoptmgr,ContextObj,RunFcn,CostFcn,name,caller)
%
%  F= xregoptmgr(strategyFcn,ContextObj,costFcn)

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


% If the only input is a structure or an instance of this class, either
% perform an upgrade or return the object.
if nargin==1
    if isstruct(strategyFcn)
        F = strategyFcn;
        if ~isfield(F,'IsMaster')
            F.IsMaster = 1;
        end
        if ~isfield(F,'version')
            F.version = 1;
        end
        F = class(F,'xregoptmgr');
        return
    elseif isa(strategyFcn, 'xregoptmgr')
        F = strategyFcn;
        return
    end
end

% function handle to setup routine
F.algorithm = [];

% label
F.name  = '';

% context which the xregoptmgr works with
F.Context ='';

% [F,g]  = costFunc(x0,ContextObj,varargin)
%   g is gradient or jacobian and is not compulsory
F.costFunc = [];

% field to store algorithm setup options
F.foptions = [];

% function handles to run and setup functions
% API:
% [ContextObj,Cost,OK,varargout] = RunFcn(xregoptmgr,ContextObj,x0,varargin);
%   contextImplementation
% [ContextObj,Cost,OK,varargout] = RunFcn(ContextObj,xregoptmgr,x0,varargin);
F.RunFcn = [];

% array of function handles to alternative algorithms
%  [om,OK]= func(ContextObj,varargin)
%      should run without varargin?
%   the gui should check alternatives and provide a means of selecting algorithms
F.Alternatives = {};

% context constraint generator
% [LB,UB,A,c,nlfunc]  = constraintFunc(ContextObj,varargin)
F.ConstraintFunc = '';

% constraint store
F.Constraints = struct('LB',[],'UB',[],...  % bounds
    'A',[],'c',[],...                        % linear constraints
    'NLcon','');                             % nonlinear constraint function

F.IsMaster = 1;
F.version = 2;
F = class(F,'xregoptmgr');

if nargin>1
    if ischar(strategyFcn)
        % convert to function handle
        strategyFcn = str2func(strategyFcn);
    end
    F.algorithm = strategyFcn;
    if nargin>2
        if ischar(costFcn)
            % convert to function handle
            costFcn = str2func(costFcn);
        end
        F.costFunc = costFcn;
    end

    % set up strategy
    F = feval(strategyFcn,F,ContextObj);
    
    % store class definition in case this is required
    F.Context = class(ContextObj);
end