CLC,CLEARSJ=load ('Data3.txt') %load data for enemy 100 targets x=SJ (:, 1); Y=SJ (:, 2); D1=[70,40]; Sj0=[D1;SJ;D1]; % increased by one point [70,40] As the end-to-end SJ=sj0;d=zeros (102); %Distance Matrix D%Calculate the distance matrix by vectorization method amount= Size (sj,1); Dist_matrix=Zeros (amount, amount); COOR_X_TMP1= SJ (:, 1) * ones (1, amount); Coor_x_tmp2= Coor_x_tmp1';COOR_Y_TMP1 = SJ (:, 2) * ones (1, amount); Coor_y_tmp2= Coor_y_tmp1';Dist_matrix = sqrt ((COOR_X_TMP1-COOR_X_TMP2). ^2 + (COOR_Y_TMP1-COOR_Y_TMP2). ^2); %Matrix D that stores distances between cities=Dist_matrix;%Set parameter L=102; W=50;d ai=100;%selecting good parent A through improved circle algorithm forK=1: W C=randperm (100); %a sequence of numbers randomly C1 from 1 to 100 of these numbers.=[1,C+1,102]; % increase in tail 1,102Flag= 1; %Set Flag whileFlag>0 Flag=0; forM=1:l-3 forN=m+2:l-1ifD (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 J (K,C1)=1:102; %produced a W (50) Parent Aendj=j/102; J (:,1) =0; J (:,102) = 1; % tail is 0,1, with intermediate elements between them rand (' State', sum (clock));%Genetic algorithm implementation process a=J; forK=1:dai% generates 0~1 Random series encoding dai=100B=A; C=Randperm (w);%. Mating produces offspring b forI=1:2: w F=2+floor (100*rand (1)); Temp=b (c (i), f:102); %22 Pairing B (c (i), F:102) =b (c (i+1), f:102); B (c (I+1), f:102) =temp; End%. Mutation produces a descendant C by=find (rand (1,W) <0.1); ifLength (by) = =0 by=floor (W*rand (1)) +1; End C=A (by,:); L3=length (by); forJ=1: L3 BW=2+floor (100*rand (1,3)); 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%3. Select the fine variety in the parent and descendant as the new parent g=[A; B C]; G=[A; B C]; TL=size (g,1); [Dd,ix]=sort (g,2); temp (1:TL) =R; forJ=1: TL forI=1:101Temp (j)=temp (j) +d (ix (j,i), IX (j,i+1)); End end [Dz,iz]=sort (temp); %from small to large A=g (IZ (1:w),:); %Choose from 50 excellent Endpath=ix (IZ (1),:) long=dz (1) xx=sj0 (path,1); Yy=sj0 (path,2);p lot (Xx,yy,'- o')
[Mathematical Modeling (iii)] genetic algorithm and travel quotient problem