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
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
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에 대해 자세히 알아보기

질문:

2018년 12월 24일

댓글:

2018년 12월 24일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by