RandData = round (80 * rand (25, 8 ));
Save. \ sj.txt randData-ascii
Clc, clear
Load sj.txt % load the data of the enemy's 100 targets
X = sj (:,); x = x (:);
Y = sj (:,); y = y (:);
Sj = [x y];
D1 = [70, 40];
Sj0 = [d1; sj; d1];
% Distance matrix d
Sj = sj0 * pi/180;
D = zeros (102 );
For I = 1:101
For j = I + :102
Temp = cos (sj (I, 1)-sj (j, 1) * cos (sj (I, 2) * cos (sj (j, 2 )) + sin (sj (I, 2) * sin (sj (j, 2 ));
D (I, j) = 6370 * acos (temp );
End
End
D = d + d'; L = 102; w = 50; dai = 100; % w indicates the population size.
% Select excellent parent generation A through improved Circle Algorithm
For k = 1: w
C = randperm (100 );
C1 = [1, c + 1,102];
Flag = 1;
While flag> 0
Flag = 0;
For m = 1: L-3
For n = m + 2: L-1
If d (c1 (m), c1 (n) + d (c1 (m + 1), c1 (n + 1) <d (c1 (m ), c1 (m + 1) + d (c1 (n), c1 (n + 1 ))
Flag = 1;
C1 (m + 1: n) = c1 (n:-1: m + 1 );
End
End
End
End
J (k, c1) =; % the value of column c1 of row k of matrix J is.
% J is the 50 excellent fathers
End
J = J/102;
J (:, 1) = 0; J (:, 102) = 1;
Rand ('state', sum (clock ));
% Genetic Algorithm Implementation Process
A = J;
For k = 1: dai % generates 0 ~ Encode a random series
B =;
C = randperm (w );
% Mating generates Child B
For I = 1: 2: w
F = 2 + floor (100 * rand (1); % randomly select the starting position of the exchange, which is different from the biological chromosome exchange.
% Exchange genes of adjacent Chromosomes
Temp = B (c (I), F: 102 );
B (c (I), F: 102) = B (c (I + 1), F: 102 );
B (c (I + 1), F: 102) = temp;
End
% Variations generate Child C
By = find (rand (1, w) <0.1 );
If length (by) = 0
By = floor (w * rand (1) + 1;
End
C = A (,:);
L3 = length ();
For j = 1: L3
Bw = 2 + floor (100 * rand ));
Bw = sort (bw );
C (j, :) = C (j, [1: bw (1)-1, bw (2) + 1: bw (3), bw (1 ): bw (2), bw (3) + 1:102]);
End
% Combine ABC
G = [A; B; C];
TL = size (G, 1); % TL is the number of rows of G
% Select an excellent breed as the new parent in the parent and child generations
[Dd, IX] = sort (G, 2); % dd is the result after the row is sorted in ascending order, and IX is the index value.
Temp (1: TL) = 0; % initialize tmp
For j = 1: TL
For I = 1:101
Temp (j) = temp (j) + d (IX (j, I), IX (j, I + 1); % find the path and
End
End
[DZ, IZ] = sort (temp );
A = G (IZ (1: w), :); % sort the first 50 as excellent parent to re-arrange
End
Path = IX (IZ (1 ),:)
Long = DZ (1)
% Toc
Xx = sj0 (path, 1); yy = sj0 (path, 2 );
Plot (xx, yy, '-O ')