sa.asv

来自「simulated annealing code of dejong funct」· ASV 代码 · 共 67 行

ASV
67
字号

% ME6352 
% Global Optimization: Heuristic Method
% Simulated Annealing Project
        

                 %Date: Feb. 25th,2008
                 %Author: Jin Zhao






function [Xstar, fstar]=SA(tini,kb)
%parameter statment
%af=0.98; 
%t=af*t
t=tini+1;        
beta=-kb/t;                             %boltzmann constant kb                         
done=0;
gobacktostep1=-1;
p=0;
r=rand();
testf=0;
testX=0;

   [X,f1]=DeJong8;                     % step1 Choose starting design X, 
  
fmin=f1;
Xmin=X;
while ~done
    t=t-1;
    if t<=0.1                          %stopping criteria
    Xstar=Xmin;
    fstar=fmin;
    done=1;
    break;
else
  
    [testX,testf]=DeJong8;            %choose a random point
    if f1<testf
        p=1;
    else
        p=(-beta)*exp(f1-testf);
    end
    r=rand();                         %creat a random number
    if r<=p
        gobacktostep1=0;             %the step is accepted and the design vector is update
    else
        gobacktostep1=1;              
    end
 end
    if gobacktostep1==0
        X=testX;
        f1=testf;
        if f1<=fmin
            Xmin=X;
            fmin=f1;
        end
    else
        gobacktostep1==1;
        end
end


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?