Simulated annealing algorithm implementation code

Simulated annealing algorithm: the main program to achieve the following:

In particular algorithm function, please click here https://s.wcd.im/v/43dvdZ36/

%main.m 文件
close all;
clear all;

= zuobiao [0.37 0.75 0.45 0.76 0.71 0.07 0.42 0.59 0.32 0.67 0.62 0.67 0.6 0.3 0.20 ...
0.35 0.27 0.94 0.82 0.37 0.61 0.42 0.6 0.39 0.53 0.4 0.63 0.5 0.98 0.68;
0.91 0.87 0.85 0.75 0.72 0.74 0.71 0.69 0.64 0.64 0.59 0.59 0.55 0.5 ... 0.55
0.45 0.43 0.42 0.38 0.27 0.26 0.25 0.23 0.19 0.19 0.13 0.08 0.04 0.02 0.85]
Plot (zuobiao (. 1, :), zuobiao (2, :), 'G *'), HOLD ON
Plot (zuobiao (. 1 , :), zuobiao (2, :))
length = max (size (zuobiao));
% from the initial request ..

% zhixu = randperm (length);% random sequence generated through a route point
% temp = zuobiao (1 , :);
% newzuobiao (. 1,:) = TEMP (zhixu);
% zuobiao TEMP = (2, :);
% newzuobiao (2,:) = TEMP (zhixu);
% newzuobiao;
% F = Juli (newzuobiao) ;
F = Juli (zuobiao);
-------------------------------------- parameters defining area%
% initial temperature of 10000
a tmax = 100 ;
Tmin = from 0.001;
% rate of temperature drop
Down = 0.95;

% function annealing algorithm ..
Figure
T = a tmax;
the while T> Tmin
for. 1 = n-: 5000
newzuobiao = newpath is (zuobiao, length);
Newf = Juli (newzuobiao) ;
IF Newf <F
zuobiao = newzuobiao;
F = Newf;
ELSEIF RAND <exp (- (Newf-F) / T)
zuobiao = newzuobiao;
F = Newf;
End
End
huatu = [zuobiao, zuobiao (:,. 1)];
Plot (huatu (. 1, :), huatu (2, :)); HOLD ON
Plot (huatu (. 1, :), huatu (2, :), 'RO'); text (0.1,0.1, [ 'total distance is', num2str (F)]); HOLD OFF
PAUSE (0.00001);
T = T * Down;
F;
end

% newpath.m file (random exchange of coordinates of two points)
% = newpath is zuobiao function (zuobiao, length)
%% random exchange coordinates of two points ..
% A = ceil (RAND (1,2) * length) ;
% Qian = A (. 1);
% HOU = A (2);
% TEMP = zuobiao (:, Qian);
% zuobiao (:, Qian) = zuobiao (:, HOU);
% zuobiao (:, HOU) = TEMP;

% juli.m file (total distance traveled some way surrounded by a circle)
% = Juli Lucheng function (zuobiao)
% length = max (size (zuobiao));
% S = 0;
% for I = 2 : length
% S = S + sqrt (SUM ((zuobiao (:, I) -zuobiao (:.,. 1-I)) ^ 2));
% End
% IF ~ length = 2
% S + S = sqrt (SUM ((zuobiao (:,. 1) -zuobiao (:, length)) ^ 2.));
% End
% Lucheng = S;

Guess you like

Origin www.cnblogs.com/weimingai/p/10980037.html