The genetic algorithm of TSP issues I made a player in these days, one of the questions I did using the genetic algorithm. Now I will organize it into the genetic algorithm for solving TSP issues: Traveling Saleman Problem, Abbreviation TSP : Knowing the mutual distance between N cities, existing salesmen must travel to this N cities, and each city can only access it once, and finally returns to the departure city. How to arrange his access to these cities, can the total length of the travel route? In terms of the terminology of Figure, it is assumed that there is a plurality of Figures g = (v, e), where V is a vertex set, and E is a bit set, and D = (Dij) is composed of the distance between the vertex I and the vertex j. The distance matrix, the travel business problem is to find a loop with the shortest distance through all the vertices and each vertex. This problem can be divided into symmetric travel provider issues (Dij = DJI, any I, J = 1, 2, 3, ..., N) and asymmetric travel providers (Dij ≠ Dji, any i, j = 1, 2 , 3, ..., n). If the city V = {V1, V2, V3, ..., VN} is T = (T1, T2, T3, ..., Ti, ..., TN), where ti∈V (i = 1, 2, 3, ..., n), and remember TN 1 = T1, the mathematical model of the travel provider problem is: min L = σD (t (i), t (i 1)) (i = 1, ..., n) The travel provider problem is a typical combination optimization problem, and it is an NP problem. Its possible path number and urban number N is an exponential growth, so it is generally difficult to find its best solution, this article adopts genetics The algorithm seeks its approximate solution. Genetic algorithm: Initialization process: use V1, V2, V3, ..., VN represents N city. Define an integer pop-size as a chromosome, and randomly produce a POP-Size initial chromosome, a random sequence consisting of an integer of 1 to 18. The calculation of adaptation f: Each chromosome Vi in the population, calculates its adaptation, f = σd (T (I), T (i 1)). Evaluation function EVAL (VI): used in the population Each chromosome Vi sets a probability to compare the possibility of the chromosome to the adaptability of other chromosomes in its population, both by roulette, and adaptive strength chromosome is selected to produce a background opportunity. Alpha ∈ (0, 1), the order-based evaluation function is EVAL (VI) = alpha * (1-alpha). ^ (i-1). [Random Planning and Fuzzy Planning] Select Procedure: The selection process is based on a rotating casher POP-SIZE, and each rotation is selected for a new population. The gambling wheel is chosen according to the adaptation of each chromosome. Step1, calculating the cumulative probability qi, q0 = 0; Qi = σEVAL (VJ) J = 1, ..., I; I = 1, ... Pop-size. Step2, from the interval (0, POP-SIZE) A random number R; STEP3, if Qi-1 The so-called Grefenstette coding is the location of the selected player in union (free of elimination) players, such as: 8 15 2 16 10 7 4 3 11 14 6 12 9 5 18 13 17 1 correspondence: 8 14 2 13 8 6 3 2 5 7 3 4 3 2 4 2 2 1. Crossing process: This article uses a conventional single point cross. To determine the parent of the cross-operated operation, from the POP-Size repeat the following process: generate a random number R from [0, 1], if the R % PM: Variation Probability% Alpha: Evaluation Function EVAL (VI) = Alpha * (1-Alpha). ^ (i-1).% BestPop: Return to the best group% Trace: Evolution track% -------- ------------------------------------------% #### @@@ ##all rights reserved! Welcome netizens to correct, improve! ## @@@ ####% e-mail: Tobysidney33@sohu.com% ################################################################################################################################################################################################################################################################################ ######################### = size (d, 2); n = Nargin; if n <2 DISP ('missing variables !!') DISP ('^ _ ^ Book ^ _ ^') Endif N <2 Termops = 500; Num = 50; PC = 0.25; CXOPS = 3; PM = 0.30; alpha = 0.10; Endif N <3 NUM = 50; PC = 0.25; cxOps = 3; PM = 0.30; alpha = 0.10; Endif n <4 pc = 0.25; cxOps = 3; PM = 0.30; alpha = 0.10; Endif N <5 cxops = 3; PM = 0.30; alpha = 0.10 Endif n <6 pm = 0.30; Alpha = 0.10; Endif N <7 alpha = 0.10; Endif iSempty (cxops) CXOPS = 3; END [T] = InitializeGA (Num, CityNum); for i = 1: Termops [L ] = f (d, t); [x, y] = Find (l == max (L)); trace (i) = - l (y (1)); bestpop = T (Y (1), ); [t] = SELECT (T, L, alpha); [g] = Grefenstette (T); [g1] = Crossover (G, PC, CXOPS); [g] = mutation (g1, pm);% uniform Variation [T] = CONGREFENSTETTTTTTTTTTTTTTTTTTTTTTTTTTTTTE (G); End -------------------------------------------------------------------------------------------------------------------------------- ------------------ Function [T] = Initializega (NUM, CityNUM) for i = 1: Num T (i,:) = Randperm (CityNum); END-- -------------------------------------------------- ------- Function [l] = f (d, t) [m, n] = size (t); for k = 1: M for i = 1: N-1 L (k, i) = d (t (k, i), t (k, i 1)); End L (k, n) = d (t (k, n ), t (k, 1)); l (k) = - sum (l (k, :)); end ----------------------- ------------------------------------ Function [t] = SELECT (T, L, Alpha) [ m, n] = size (l); t1 = T; [BeForeSort, Aftersort1] = Sort (L, 2);% FSort from L to ufor i = 1: n afterst1 (i) = AfTersort1 (N 1-I);% change endfor k = 1: n; t (k,:) = T1 (AfTersort (k), :); L1 (k) = L AfTersort (k)); endt1 = t; l = L1; for i = 1: size (an) = alpha * (1-alpha). ^ (i-1); endm = size , 1); q = cumsum (eval); qmax = max (q); fork = 1: m r = qmax * rand (1); for j = 1: m if j == 1 & r <= q (1) T (k, :) = t1 (1, :); elseif J ~ = 1 & r> Q (J-1) & r <= Q (J) T (K,:) = T1 (j, :); End end- ------------------------------------------------- Function [g] = GREFENSTETTTTE (T) [M, N] = Size (T); for K = 1: M t0 = 1: n; for i = 1: N for j = 1: Length (t0) IF T (K , i) == T0 (j) g (k, i) = j; T0 (j) = []; Break end end end--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------- Function [G] = Crossover (G, PC, CXOPS) [M, N] = Size (g); RAN = RAND (1, m); r = cxops; [x, ru] = find (ran