help optimization Simulated Annealing
显示 更早的评论
Hey, i have this programme but he didn t work somone know why ?
function T=f(xe,ye)
T=sin(xe)*sin(ye)+0.1*xe;
end
function w=g(xn,yn)
w=sin(xn)*sin(yn)+0.1*xn;
end
for xe= -4:4
for ye= -4:4
while (T>Tfinale && nb_iter< 5000)
xn=xe+ampli*rand;
yn=ye+ampli*rand;
if g(xn,yn) < f(xe,ye)
xe=xn;
ye=yn;
else
df= g(xn,yn)-f(xe,ye);
p=exp(-df/T);
if(p>rand)
xe=xn;
ye=yn;
end
end
T=lamda*T;
nb_iter = nb_iter+1;
end
end
end
回答(1 个)
Walter Roberson
2018-12-24
0 个投票
When you put a script and functions in the same file, the script must be the first thing in the file.
You do not initialize T or Tfinale or nb_iter or lamda
You appear to be accepting at random, as is done for simulated annealing, but you do not appear to be keeping track of the best position that was ever encountered.
1 个评论
Image Analyst
2018-12-24
And of course (my pet peeve) there are no comments describing what the code is doing. That leads to unmaintainable code.
类别
在 帮助中心 和 File Exchange 中查找有关 Simulated Annealing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!