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

    function con = contwostage( varargin )
%CONTWOSTAGE Two-stage constraint model
%
%  CON = CONTWOSTAGE
%  CON = CONTWOSTAGE( CIF )
%  CON = CONTWOSTAGE( LOCAL, GLOBAL )
%
%  CIF must have at least two factors.
%
%  See also CONBASE.

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


if nargin == 1 && isstruct( varargin{1}),
    %  CON = CONTWOSTAGE( STRUCT )
    % This is a special form to support the LOADOBJ method
    con = varargin{1};
    parent = con.conbase;
    con = mv_rmfield( con, 'conbase' );
elseif nargin==1 && isa(varargin{1},'contwostage')
    con = varargin{1};
    return
else
    % These forms require the object structure to be created
    
    if nargin == 2,        
        %  CON = CONTWOSTAGE( LOCAL, GLOBAL )
        localConstraint = varargin{1};
        globalModel     = varargin{2};

        lcif = getInputFactors( localConstraint );
        if isa( globalModel, 'xregmodel' ),
            gcif = coninputfactor( globalModel );
        elseif isa( globalModel, 'cell' ),
            gcif = coninputfactor( globalModel{1} );
        else
            error(message('mbc:contwostage:InvalidArgument'));
        end
    else
        % These are the forms that need a local constraint and a global
        % model set-up
        if nargin == 0,
            %  CON = CONTWOSTAGE
            cif = coninputfactor( 4 );
            lcif = cif([1,2]);
            gcif = cif([3,4]);

        elseif nargin == 1,
            %  CON = CONTWOSTAGE( CIF )
            cif = varargin{1};
            if length( cif ) < 2,
                error(message('mbc:contwostage:InvalidArgument1'));
            elseif length( cif ) >= 4,
                lcif = cif([1,2]);
                gcif = cif(3:end);
            else
                lcif = cif(1);
                gcif = cif(2:end);
            end

        else
            % Invalid input
            error(message('mbc:contwostage:InvalidArgument2'));
        end
        
        % Construct the local constraint and the global model
        if length( lcif ) < 2,
            localConstraint = conrange( lcif );
        else
            localConstraint = conellipsoid( lcif );
        end
        globalModel = makeXregmodel( gcif, 'xreginterprbf' );
    end

    % We need one global model for each feature of the constraint.
    if ~iscell( globalModel ),
        nr = nFeatures( localConstraint );
        [tmp{1:nr}] = deal( globalModel );
        globalModel = tmp;
    end

    % Create the object structure
    con = struct( ...
        'Version', 2, ...
        'Local', localConstraint, ...
        'Global', {globalModel}, ...
        'LocalFriend', [] );
    parent = conbase( [lcif, gcif]  );
end

% Instatiate class
con = orderfields( con );
con = class( con, 'contwostage', parent );

%------------------------------------------------------------------------------|
% EOF
%------------------------------------------------------------------------------|