help optimization Simulated Annealing
Mostrar comentarios más antiguos
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
Respuestas (1)
Walter Roberson
el 24 de Dic. de 2018
0 votos
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 comentario
Image Analyst
el 24 de Dic. de 2018
And of course (my pet peeve) there are no comments describing what the code is doing. That leads to unmaintainable code.
Categorías
Más información sobre Simulated Annealing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!