help optimization Simulated Annealing
Show older comments
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
Answers (1)
Walter Roberson
on 24 Dec 2018
0 votes
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 Comment
Image Analyst
on 24 Dec 2018
And of course (my pet peeve) there are no comments describing what the code is doing. That leads to unmaintainable code.
Categories
Find more on Simulated Annealing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!