How to simulate annealing algorithm in matlab
This article mainly introduces the relevant knowledge of "how matlab simulated annealing algorithm". The editor shows you the operation process through actual cases, and the operation method is simple, fast and practical. I hope this article "matlab how to simulated annealing algorithm" can help you solve the problem.
Clc;clear;close all;%%T0=1000;% initial temperature Tend=1e-3;% termination temperature LT500;% number of iterations (chain length) Q = 0.9;% cooling rate
% load data load CityPosition1;%%D=Distanse (X);% Compute distance matrix N=size (DPower1);% number of cities%% initial solution S1=randperm (N);% randomly generate an initial route
%% draw the path graph of the random solution DrawPath (S1 Magi X)
Pause (0.0001)% outputs the path and total distance of the random solution disp ('a random value in the initial population:') OutputPath (S1); Rlength=PathLength (DmaeS1); disp (['total distance:', num2str (Rlength)])
% calculate the number of iterations TimeTime=ceil (double (solve (['1000 * (0.9) ^ XLBG Eng num2str (Tend)])); count=0;% iteration count Obj=zeros (Time,1);% Target value matrix initialization track=zeros (Time,N);% optimal route matrix initialization% iterative while T0 > Tendcount=count+1;% update iterations temp=zeros (Lmai Numa1); for karm1vl% generate new solution S2=NewAnswer (S1) %% Metropolis rule to determine whether to accept the new solution [S1Magi R] = Metropolis (S1Magazine S2Magazine T0);% Metropolis sampling algorithm temp (KMagi:) = [S1R];% record the next route and its distance end%% record the best route of each iteration [d0Magi index] = min (temp (:, end));% find out the best route at current temperature | if count==1 | d0