% Differential Evolutionary algorithm program function DE t0 = cputime; % Timing %% Population initialization T = 1000; % Maximum number of iterations F0 = 0.5; % Mutation Rate N = 100; % Population size D = 10; % number of chromosomes in each individual, that is, the dimensionality of the problem to be asked CR = 0.3; % Crossover Rate Tmin = zeros (1,t); &nThe optimal value bestx = zeros (T,D) for the bsp; % of the adaptive function of each generation The optimal Solution value = zeros (1,N) for each generation of; % ; %% applicable degree function:rastrigr function minimum value function y = f (x) y = sum (x.^2 - 10.* cos (2.*pi.*x) + 10); end %% Generate initial population % set boundaries xmin = -5.12; xmax = 5.12; x0 = (xmax-xmin) *rand (n,d) + xMin; % N-by-D xg = x0; xg_next_1= zeros (N,D); % initialization, storage mutation operationIntermediate value N-by-d xg_next_2 = zeros (N,D); % Initialize, store cross-operation intermediate value n-by-d for t=1:t %% mutation Operation for i = 1:N % represents the first individual % produces j,k,p three different numbers dx = Randperm (N); r1 = &NBSP;DX (1); r2 = &NBSP;DX (2); r3 = &NBSP;DX (3); % to make sure it differs from I if r1 == i &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;R1&NBSP;&NBSP;=&NBSP;DX (4); else if r2 == i &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;R2&NBSP;=&NBSP;DX (4); else if r3 == i &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;R3&NBSP;=&NBSP;DX (4); end end end % self-applicable mutation operator suanzi = exp (1-t/(t + 1-t)); F = F0*2.^suanzi; % mutated individuals from three random parents &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;H&NBSP;=&NBSP;XG (R1,:) + f* (XG (R2,:) - &NBSP;XG (R3,:)); % examines individual variants, Prevent variation beyond the boundary for j = 1: d &nbSp; if h (j) >xMin & h (j) < xMax % within the boundaries xg _next_1 (I,j) = h (j); else % out of boundary range xg_next_1 (i,j) = (xMax - xmin) *rand + xmin; end end end %% cross-operation for i = 1: N dx = randperm (D); % [1,2,3,... D] Random sequence for j = 1: d &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF&NBSP;RAND&NBSP;<&NBSP;CR&NBSP;&NBSP;%&NBSP;&&NBSP;DX (1) ~= j % CR = 0.9 xg_next_2 (i,j) = XG_next_1 (i , j); else &nBsp; xg_next_2 (i,j) = xg (i,j); end end end %% Select operations for i = 1:n If f (Xg_next_2 (i,:)) <= f (XG (i,:)) xg (i,:) = xg_next_2 (i,:); end end %% finding the best value per generation for i = 1:N value (i) = f (XG (i,:)); end [value_min,pos_min] = min (value); % The minimum value of the objective function in generation tmin (t) = value_min; % Save the best individuals bestx (t,:) = xg (pos_min,:); trace (t,1) = t; trace (t,2) = value_min; t = t + 1; end %% Global Optimal value: Output [value_min,pos_min] = min ( Tmin); best_value = value_min Best_vector = bestx (Pos_min,:) fprintf (' The time spent by de is:%f \n ', cputime - t0); % plot the relationship between algebra and optimal function values plot (Trace (:, 1), Trace (:, 2)); end
Output Result:
Best_value =
0
Best_vector =
1.0E-08 *
-0.1568-0.1476-0.0155 0.0578-0.0721-0.1532 0.1067 0.0799-0.0818-0.0518
The de is time consuming: 2.640625
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/8C/9B/wKioL1hyRdKDVECHAArEeHwojdI881.bmp "title=" Untitled.bmp "alt=" Wkiol1hyrdkdvechaareehwojdi881.bmp "/>
This article from "It Technology Learning and communication" blog, declined reprint!
Fractal Evolutionary algorithm de