help optimization Simulated Annealing
Mostra commenti meno recenti
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
Risposte (1)
Walter Roberson
il 24 Dic 2018
0 voti
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 Commento
Image Analyst
il 24 Dic 2018
And of course (my pet peeve) there are no comments describing what the code is doing. That leads to unmaintainable code.
Categorie
Scopri di più su Simulated Annealing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!