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

    function con = upgrade(con, m)
%UPGRADE Upgrade a constraint to have model information
%
%  CON = UPGRADE(CON, M)
%
%  For old forms of the constraint, this method will take all the
%  appropriate information from the model, M, and update the
%  information in the constraint, CON. This includes updating
%  variable information and inverse coding any data stored in coded
%  units. The version number will also be updated by this method.
%
%  This method should be called from the LOADOBJ method of any object that holds
%  a constraint. Some objects may need to setup a post-load callback if they do
%  have an appropriate model at LOADOBJ time.
%
%  See also CONBASE/UPGRADE, CONLINEAR/LOADOBJ.

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

% The given constraint is A'*y <= b, where y is coded units. For y in coded
% units the corresponding point x in natural units is given by x = D*y + C where
% D is a diagonal matrix of half-widths and C a vector of centers of the range
% of the factors. Thus the constraint is
%
%                         A'*y <= b
%          A'*inv( D )*(x - C) <= b
%                A'*inv( D )*x <= b + A'*inv( D )*C
% i.e., 
%               new.A = A'*inv( D )
%               new.b = b + A'*inv( D )*C



if con.version == 1.5,
    m = pMakeFriend( con, m );
    % Upgrade parent
    con.conbase = upgrade( con.conbase, m );
    % Adjust A and b to take account of the change in coding
    [mn, mx] = range( m );
    if ~any( isinf( mn ) ) || ~any( isinf( mx ) ),
        D = (mx - mn)/2;
        C = (mx + mn)/2;
        con.b = con.b + sum( con.A .* C ./ D );
        con.A = con.A ./ D;
    end
    % Update version number
    con.version = 2.0;
end

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