模擬退火算法(Simulated Annealing, SA)的思想借 鑒于固體的退火原理,當固體的溫度很高的時候,內(nèi)能比
較大,固體的內(nèi)部粒子處于快速無序運動,當溫度慢慢降 低的過程中,固體的內(nèi)能減小,粒子的慢慢趨于有序,最
終,當固體處于常溫時,內(nèi)能達到最小,此時,粒子最為 穩(wěn)定。模擬退火算法便是基于這樣的原理設計而成。
模擬退火算法過程
(1)隨機挑選一個單元k,并給它一個隨機的位移,求出系統(tǒng)因此而產(chǎn)生的能
量變化ΔEk。
(2)若ΔEk? 0,該位移可采納,而變化后的系統(tǒng)狀態(tài)可作為下次變化的起點;
若ΔEk>0,位移后的狀態(tài)可采納的概率為
式中T為溫度,然后從(0,1)區(qū)間均勻分布的隨機數(shù)中挑選一個數(shù)R,若R<Pk,
則將變化后的狀態(tài)作為下次的起點;否則,將變化前的狀態(tài)作為下次的起點。
(3)轉第(1)步繼續(xù)執(zhí)行,知道達到平衡狀態(tài)為止。
利用模擬退火算法工具箱求解問題:文章來源:http://www.zghlxwxcb.cn/news/detail-632655.html
%%
clc;clear;
%%普通的目標函數(shù)
fun = @dejong5fcn %目標函數(shù)
%[x,fval] = simulannealbnd(fun,[0,0])%[0,0]憑經(jīng)驗猜測的初始值,沒有的話,隨意寫就行
options = saoptimset('PlotFcns',{@saplotbestx,@saplotbestf,@saplotx,@saplotf})
x0 = [0,0];
lb = [-64,-64];%下限
ub = [64,64];%下限
[x,fval] = simulannealbnd(fun,x0,lb,ub,options);
%%
求:
% min f(x) = (4 - 2.1*x1^2 + x1^4/3)*x1^2 + x1*x2 + (-4 + 4*x2^2)*x2^2;
% 寫成函數(shù)形式
% function y = simple_objective(x)
% y = (4 - 2.1*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) + (-4 + 4*x(2)^2)*x(2)^2;
%%
fun = @simple_objective;%注意需要將其放在最前面
X0 = [0.5 0.5]; % 初始點
lb = [-64 -64];
ub = [64 64];
[x,fval,exitFlag,output] = simulannealbnd(fun,X0,lb,ub);
fprintf('The number of iterations was : %d\n', output.iterations);
fprintf('The number of function evaluations was : %d\n', output.funccount);
fprintf('The best function value found was : %g\n', fval);
%%
% 求:
% min f(x) = (a - b*x1^2 + x1^4/3)*x1^2 + x1*x2 + (-c + c*x2^2)*x2^2;
%
% 寫成函數(shù)形式
% function y = parameterized_objective(x,a,b,c)
% y = (a - b*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) + (-c + c*x(2)^2)*x(2)^2;
%%帶有常數(shù)的目標函數(shù)
a = 4; b = 2.1; c = 4; % define constant values
fun = @(x) parameterized_objective(x,a,b,c);
X0 = [0.5 0.5];
options = saoptimset('PlotFcns',{@saplotbestx,@saplotbestf,@saplotx,@saplotf})
[x,fval] = simulannealbnd(fun,X0,options)
%自定義目標函數(shù)1
function y = parameterized_objective(x,a,b,c)
y = (a - b*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) + (-c + c*x(2)^2)*x(2)^2;
end
%自定義目標函數(shù)2
function y = simple_objective(x)
y = (4 - 2.1*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) + (-4 + 4*x(2)^2)*x(2)^2;
end
運行效果文章來源地址http://www.zghlxwxcb.cn/news/detail-632655.html
到了這里,關于【數(shù)學建模學習(9):模擬退火算法】的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!