A list,

Particle swarm Optimization (PSO) is an evolutionary computation technology. It comes from the study of predation behavior in flocks of birds. The basic idea of particle swarm optimization algorithm is to find the optimal solution through the cooperation and information sharing among individuals in the group. The advantage of PSO is that it is simple and easy to implement without many parameters adjustment. It has been widely used in function optimization, neural network training, fuzzy system control and other applications of genetic algorithms.

2. Analysis of particle swarm optimization

2.1 Basic Ideas

Particle swarm optimization (PSO) simulates a bird in a flock by designing a massless particle that has only two properties: speed and position. Speed represents how fast the bird moves, and position represents the direction of the bird. Each particle separately searches for the optimal solution in the search space, and records it as the current individual extreme value, and shares the individual extreme value with other particles in the whole particle swarm, and finds the optimal individual extreme value as the current global optimal solution of the whole particle swarm. All particles in a swarm adjust their speed and position based on the current individual extremum they find and the current global optimal solution shared by the whole swarm. The following GIF vividly shows the process of the PSO algorithm:



2 Update Rules

PSO initializes as a group of random particles (random solutions). Then find the optimal solution through iteration. At each iteration, the particle updates itself by tracking two “extreme values” (PBest, GBest). After finding these two optimal values, the particle updates its velocity and position by using the formula below.



The first part of formula (1) is called [memory term], which represents the influence of the magnitude and direction of the last speed. The second part of Formula (1) is called [self cognition term], which is a vector pointing from the current point to the particle’s own best point, indicating that the particle’s action comes from its own experience. The third part of Formula (1) is called [group cognition term], which is a vector from the current point to the best point of the population, reflecting the cooperation and knowledge sharing among particles. The particle is determined by its own experience and the best experience of its companions. Based on the above two formulas, the standard form of PSO is formed.



Formula (2) and Formula (3) are regarded as standard PSO algorithms.

3. Process and pseudocode of PSO algorithm

Ii. Source code

%% Optimization + PSO to solve location - path optimization problem2021years4month13Day:12:09clc; clear; close all; %% initializes population N =300; % Initial population d =6; % space dimension ger =60; % Max iteration limit =zeros(2.2);
limit(:,1) = [- 46000.  63000 ];  
limit(:,2) = [- 26000.  70000]; % set position parameter limit vlimit(1) = - 10000.; % Set speed limit vlimit(2) =10000 ;
wmax = 0.8;
wmin = 0.4; % inertia weight c1 =1; % Self-learning factor c2 =2; % group learning factor model=CreateModel(); % calls the model functionfor i = 1:d
  if mod(i,2) = =0
      x(:,i) = limit(2.1) + (limit(2.2) - limit(2.1)) * rand(N, 1); % The location of the initial populationelse
      x(:,i) = limit(1.1) + (limit(1.2) - limit(1.1)) * rand(N, 1); end end v = rand(N, d); % Initial population velocity xm = x; % Historical best location for each individual ym = zeros(1, d); % historical best location of population FXM =1./zeros(N,1); % Historical best fitness of each individual FYm = INF; % population history best fitness INF infinity %% population update iter =1;
record = zeros(ger, 2); % logger average=record;while iter <= ger
    fx=zeros(N,1);
    for i=1:N fx(i)= TourLength(model,x(i,:)) ; % Current fitness of an individual End intermediate_x=zeros(size(xm)); intermediate_x(1:N,:) = xm;
    intermediate_x(N + 1 : N + N,1 : d) =  x;

  for i=1:N*2
     intermediate_x(i,d+3) =150;
     intermediate_x(i,d+1:d+2)=Tour(model, intermediate_x(i,:)) ; % Current fitness of an individual End intermediate_x =... non_domination_sort_mod(intermediate_x,2, d);
    intermediate_x = replace_x(intermediate_x, 2, d, N);

    record(iter,:) = intermediate_x(1,d+1:d+2); % minimum value is denoted as average(iter,1)=sum(intermediate_x(:,d+1))/N;
    average(iter,2)=sum(intermediate_x(:,d+2))/N;
    ym=intermediate_x(1.1:d);
    fym=record(iter,:);
    
    disp(['the first',num2str(iter),'Next iteration''Minimum value:',num2str(record(iter,:)),'Emergency repair center coordinates:',num2str(ym)]);
    iter = iter+1;
    xm=intermediate_x(:,1:d); w=wmax-(wmax-wmin)*(ger-iter)/ger ; V = v * w + c1 * rand * (xm-x) + c2 * rand * (repmat(ym, N,1) - x); % speed update % boundary speed processingfor ii=1:N
        for jj=1:d       
     if v(ii,jj)>vlimit(2)  v(ii,jj)= vlimit(2);end
      if v(ii,jj)<vlimit(1)  v(ii,jj)= vlimit(1); end end end x = x + v; % position update % boundary position processingfor ii=1:N
        for jj=1:d         
             if mod(jj,2) = =0 
                 if x(ii,jj)>limit(2.2)  x(ii,jj)= limit(2.2);end
                   if x(ii,jj)<limit(2.1)  x(ii,jj)= limit(2.1);end
             else
             if  x(ii,jj)>limit(1.2)  x(ii,jj)= limit(1.2);end
              if x(ii,jj)<limit(1.1)  x(ii,jj)= limit(1.1); end end end end end Schedule = code(x, model); % call %% draw test results % fault point figure(1);
    x=model.trouble(1, :); y=model.trouble(2, :);for i=1:39
        xx=x(i);
        yy=y(i);
        [ch1]=plot( xx,yy,'ks'.'MarkerFaceColor'.'k'.'MarkerSize'.4); hold on
       text(xx , yy, num2str(i) ); % Mark with arrow hold on end % Draw emergency repair centerfor i=1:3
    xx=ym(i*2- 1);
    yy=ym(i*2);
    [ch2]= plot( xx ,yy ,'ko'.'MarkerFaceColor'.'k'.'LineWidth'.6);hold on
    text(xx , yy, num2str( i) ); % hold on end %% rand('seed'.0);
 C= unifrnd(  0.1.0.2,  model.Num_CenterSletectd , 3); % unIFrnd can create random contiguous evenly distributed arraysfor i = 1: model.Num_CenterSletectd
     Center = Schedule(i).Center;
     Client =  Schedule(i).Client ;
     xx=model.trouble(1, :); yy=model.trouble(2, :);for j= Client
        x = [ ym(i*2- 1) , xx(j ) ] ;
        y = [ ym(i*2)   , yy(j ) ] ;
 plot(   x ,y , The '-' ,'color' ,C(i, : ) , 'linewidth' , 1.5); Legend ([CH1, ch2], {'Point of failure'  ,'Location of power supply' }); %  'Location'.'SouthWestOutside'Comment placement xlabel('X/m'.'fontsize'.15.'fontname'.'Times new roman');
ylabel('Y/m'.'fontsize'.15.'fontname'.'Times new roman');
title('Emergency distribution map'); 
axis on
set(gcf,'color'[1 1 1]); % Set background color %% Draw power supply radius figure(2);
plot(model.trouble(1, : ), model.trouble(2, :),'ks'.'MarkerFaceColor'.'k'.'MarkerSize'.3); hold onfor i=1:3
    plot(ym(i*2- 1),ym(i*2),'ko'.'MarkerFaceColor'.'k'.'MarkerSize'.6); Hold on % Distribution map of emergency repair center, radius x= YM (I *2- 1);
    y=ym(i*2);
    r=model.point(3,i)*1000;
    theta=0:2*pi/3600:2*pi;
    Circle1=x+r*cos(theta);
    Circle2=y+r*sin(theta);
    plot(Circle1,Circle2,'k-'.'Linewidth'.1);
    axis equal
end
legend('Point of failure'  ,'Location of power supply'.'Radius of supply');
title('Emergency distribution map');
xlabel('X/m'.'fontsize'.15.'fontname'.'Times new roman');
ylabel('Y/m'.'fontsize'.15.'fontname'.'Times new roman');

   for i=1:N 
      xm(i,d+1:d+2)=Tour(model,xm(i,1:d)) ; End xm = non_domination_sort_mod(xm,2, d);
 function f  = replace_chromosome(intermediate_chromosome, M, V,pop)


[N, m] = size(intermediate_chromosome);

% Get the index for the population sort based on the rank
[temp,index] = sort(intermediate_chromosome(:,M + V + 1));

clear temp m

% Now sort the individuals based on the index
for i = 1 : N
    sorted_chromosome(i,:) = intermediate_chromosome(index(i),:);
end

% Find the maximum rank in the current population
max_rank = max(intermediate_chromosome(:,M + V + 1));

% Start adding each front based on rank and crowing distance until the
% whole population is filled.
previous_index = 0;
for i = 1 : max_rank
    % Get the index for current rank i.e the last the last element in the
    % sorted_chromosome with rank i. 
    current_index = max(find(sorted_chromosome(:,M + V + 1) == i));
    % Check to see if the population is filled if all the individuals with
    % rank i is added to the population. 
    if current_index > pop
        % If so then find the number of individuals with in with current
        % rank i.
        remaining = pop - previous_index;
        % Get information about the individuals in the current rank i.
        temp_pop = ...
            sorted_chromosome(previous_index + 1: current_index, :); % Sort the individuals with rank i in the descending order based on % the crowding distance. [temp_sort,temp_sort_index] =... sort(temp_pop(:, M + V +2),'descend');
        % Start filling individuals into the population in descending order
        % until the population is filled.
        for j = 1 : remaining
            f(previous_index + j,:) = temp_pop(temp_sort_index(j),:);
        end
        return;
    elseif current_index < pop
        % Add all the individuals with rank i into the population.
        f(previous_index + 1 : current_index, :) = ...
            sorted_chromosome(previous_index + 1 : current_index, :);
    else
        % Add all the individuals with rank i into the population.
        f(previous_index + 1 : current_index, :) = ...
            sorted_chromosome(previous_index + 1 : current_index, :);
        return;
    end
Copy the code

3. Operation results









Fourth, note

Complete code or write to add QQ 1564658423