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
% -- -- -- -- -- - the main function source code - weekly scheduling (main) m) % -- -- -- -- -- - the basic Particle Swarm Optimization algorithm, Particle Swarm Optimization) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - % name: basic Particle Swarm Optimization algorithm (PSO) % -- -- -- -- -- - how it works: To solve the optimization problem (weekly scheduling) % -- -- -- -- -- - description: overall, parallelism, swarm intelligence algorithm of efficient % -- -- -- -- -- - original format -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- tic clear all; clc; formatshort; % % -- -- -- -- -- - a given initial condition of hydropower stations -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - % -- -- -- -- -- -- -- -- -- -- -- -- hydropower station1---------------------------------------
Vmax1=9015*10^4; % Reservoir capacity upper limit (m3) Vmin1=7000*10^4; % Lower limit of reservoir capacity (m3) H1=640; Initial water level of reservoir capacity (m) V1=(2.0554*H1^22413.5002*H1+709934.65) *10^4; % Relationship between reservoir capacity and water level h1=91; % Initial reservoir head (m) qr(:1:7) = [20.4 25.2 22.1 19.3 16.4 23.3 28.6]; % Incoming water flow from reservoir (m3/s) qMAX1 =44; % Upper limit of reservoir reference flow (m3/s) qMIN1 =0; % Lower limit of reservoir reference flow (m3/s) A1=9.8*10^3; % Reservoir output coefficient K1 =0.65; % generation efficiency t=8.64*10^4; % Reservoir power generation reference flow period (s) %----------- hydropower station2--------------------------------------
Vmax2=2080*10^4; % Reservoir capacity upper limit (m3) Vmin2=1530*10^4; % Lower limit of reservoir capacity (m3) H2=540; Initial water level of reservoir capacity (m) V2=(2.6408*H2^22763.6392*H2+724014.90) *10^4; % Relationship between reservoir capacity and water level h2=57; % Initial reservoir head (m) qr(:8:14) = [22.4 18.3 26.4 25.2 17.6 24.6 27.2]; % Incoming water flow from reservoir (m3/s) qMAX2 =32; % Upper limit of reservoir reference flow (m3/s) qMIN2 =0; % Lower limit of reservoir reference flow (m3/s) A2=9.8*10^3; % Reservoir output coefficient k2=0.6; % power generation efficiency %% Given particle swarm optimization initialization condition T=7; C1 = % cycle2; % learning factor1
c2=2; % learning factor2
w1=0.9; % inertia weight w2=0.4;
MaxIter=100; % Maximum number of iterations Iter=0;
vmax=2; % Maximum speed vmin=0; % Minimum speed N=20; Individual number % % initialization groups -- -- -- -- -- - initial population of individuals (can limit the scope of the position and velocity) here -- -- -- -- -- -- -- -- -- -- -- -- q = zeros (N,2*T); V =rand(N,2*T); % % speed random initialization -- -- -- -- -- - the source program fitness function (fitness. M) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Fx1 = sum (A1 (k1 * * q (:1:7).*h1*t/(3.6*10^10))') '; % reservoir1Fx2=sum((k2*A2*q(:,8:14).*h2*t/(3.6*10^10))') '; % reservoir2Total generating capacity (ten thousand kWh) Fx=Fx1+Fx2; % % reservoir total generating capacity (kWh) -- -- -- -- -- - the best location set the current particle -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Pbest = q; FPbest=Fx; % -- -- -- -- -- - to find the best particle initial particle -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -] [Fgbest, r = Max (Fx); E=Fgbest; % record the current global optimal value Best=q(r,:); % % % used to hold the optimal particle position -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- cycle -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --while(Iter<=MaxIter)
Iter=Iter+1; % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- update inertia weight and speed -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- w = ((w1, w2) * (MaxIter - Iter)/MaxIter) + w2. % typical linear decrement strategy % linear differential decrement strategy % increment then decrement strategy % Nonlinear inertia weight strategy R1=rand(N,2*T);
R2=rand(N,2*T); % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- particle velocity update -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- B = repmat (q (r), N,1); v=w*v+c1*R1.*(Pbest-q)+c2*R2.*(B-q); % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- particle velocity constraints -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- changev = v > vmax; v(find(changev))=vmax; changev=v<vmin; v(find(changev))=vmin; % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the particle flow update -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- q = q +1.0*v; % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the time reference flow constraints -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --for i=1:7
q1=q(:,i);
changeq1=q1>qmax1;
q1(find(changeq1))=qmax1;
changeq1=q1<qmin1;
q1(find(changeq1))=qmin1;
q(:,i)=q1;
end
for i=8:14q2=q(:,i); changeq2=q2>qmax1; q2(find(changeq2))=qmax1; changeq2=q2<qmin1; q2(find(changeq2))=qmin1; q(:,i)=q2; End % -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- capacity of all kinds of size (m3) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- qr1 = qr (:1:7);
qr2=qr(:,8:14);
Qr1=repmat(qr1,N,1); %---- Influent size Vs1=repmat(0,N,T+1); %---- Initial storage capacity of each period Vj1=repmat(0,N,T); %---- Storage capacity size at each period (first and last average) quit1=repmat(0,N,T); %---- Abandoned water size in each period Qr2=repmat(Qr2,N,1); %---- Influent size of each period Vs2=repmat(0,N,T+1); %---- Initial storage capacity of each period Vj2=repmat(0,N,T); %---- Storage capacity size at each period (first and last average) quit2=repmat(0,N,T); % % - will abandon all kinds of water size -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the time head size -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --for i=1:N
Vs1(i,1)=V1;
Vs2(i,1)=V2;
end
for i=1:N
for j=2:(T+1)
q1=q(:,1:7);
Vs1(i,j)=Vs1(i,(j- 1))+(Qr1(i,(j- 1))-q1(i,(j- 1)))*t;
if Vs1(i,j)>=Vmax1
quit1(i,j- 1)= Vs1(i,j)-Vmax1;
Vs1(i,j)=Vmax1;
end
if Vs1(i,j)<=Vmin1
q1(i,j- 1)=(Vs1(i,j)-Vmin1+Qr1(i,j- 1)*t)/(t);
Vs1(i,j)=Vmin1;
end
end
end
for i=1:N
for j=2:(T+1)
q2=q(:,8:14);
Vs2(i,j)=Vs2(i,(j- 1))+(Qr2(i,(j- 1))-q2(i,(j- 1)))*t+quit1(i,(j- 1))+q1(i,j- 1)*t;
if Vs2(i,j)>=Vmax2
quit2(i,j- 1)= Vs2(i,j)-Vmax2;
Vs2(i,j)=Vmax2;
end
if Vs2(i,j)<=Vmin2
q2(i,j- 1)=(Vs2(i,j)-Vmin2+Qr2(i,j- 1)*t)/(t);
Vs2(i,j)=Vmin2;
end
end
end
for i=1:N
for j=1:T
Vj1(i,j)=(Vs1(i,j)+Vs1(i,j+1)) /2;
Vj2(i,j)=(Vs2(i,j)+Vs2(i,j+1)) /2;
end
end
Copy the code
3. Operation results
Fourth, note
Version: 2014a need complete code or write plus QQ 1564658423