hw2 - 3. SA.m function [solution sbest] =

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
3. SA.m function [solution sbest] = SA(sinitial,Tinitial,alpha,beta,Minitial,maxiter) solution= zeros(maxiter,3); T= Tinitial; M= Minitial; scurrent= sinitial; sbest= scurrent; snew= scurrent; COSTcurrent= cost(scurrent); COSTbest= COSTcurrent; iter= 0; while (iter < maxiter) Mtemp= M; while (Mtemp>0) rnd= rand(); if (rnd > .5) snew(1)= neighbor(scurrent(1)); else snew(2)= neighbor(scurrent(2)); end COSTnew=cost(snew); deltaCOST=COSTnew-COSTcurrent; if (deltaCOST<0) scurrent= snew; COSTcurrent=COSTnew; if (COSTnew<COSTbest) sbest= snew; COSTbest=COSTnew; end else rnd2= rand(); if (rnd2<exp(-1*deltaCOST/T)) scurrent= snew; COSTcurrent=COSTnew; end end Mtemp=Mtemp-1; end iter= iter + M; T= alpha*T; M= beta*M; solution(time,1)= iter; solution(time,2)= COSTcurrent; solution(time,3)= COSTbest; end cost.m function [cost] = cost(S) if (size(x)~= [1 2])
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
display( 'input S must be a vector with 2 entries, s1 and s2' ) else s1= S(1); s2= S(2); if cost= (10^9)-(625-(s1-25)^2)*(1600-(s2- 10)^2)*sin(s1*pi/10)*sin(s2*pi/10);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/02/2011 for the course ORIE 5430 taught by Professor Shoemaker during the Fall '11 term at Cornell University (Engineering School).

Page1 / 5

hw2 - 3. SA.m function [solution sbest] =

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online