Implementation of particle swarm optimization (8)---hybrid particle swarm optimization algorithm

Source: Internet
Author: User

The hybrid particle swarm optimization algorithm combines the global particle swarm algorithm with the local particle swarm algorithm, and its speed is updated using the formula

where G (k+1) is the global version of the speed update formula, and L (k+1) is a local version of the speed update formula, the hybrid particle swarm optimization algorithm using the H (k+1) formula.

Position Update formula

Because the local version is combined with the global version, the initialization function of the particle swarm should be the same as that of the local version, which is not listed here, see the Localinitswarm function in the particle swarm algorithm (7).

The key is the single step update function of the hybrid particle swarm algorithm, the function name is HYBRIDSTEPPSO

The code is as follows:

function [Parswarm,optswarm]=hybridsteppso (Parswarm,optswarm,adaptfunc,particlescope,maxw,minw,loopcount, Curcount)% function Description: Hybrid particle swarm algorithm. Blends the global version with the local version. The basic particle swarm algorithm is one step update position, the speed of the algorithm%%[parswarm,optswarm]=localsteppsobycircle (PARSWARM,OPTSWARM,ADAPTFUNC,PARTICLESCOPE,MAXW Minw,loopcount,curcount)% Algorithm idea: The global version of the Speed update formula: VQ (k+1) =w*v (k) +c1*r1* (pg-w) +c2*r2* (pq-w)%pg for individual historical optimal, PQ is the global optimal% Speed update formula for local version: VL (k+1) =w*v (k) +c1*r1* (pg-w) +c2*r2* (pl-w) PL for neighborhood optimal% now Speed Update Formula vh=n*vq+ (1-N) *vl;n a number of 0 to 1 input parameters: Parswarm: Particle swarm matrix, containing the position of the particle, the velocity and the current target function value% input parameter: optswarm: Matrix of the optimal solution and the global optimal solution of a particle swarm member input parameter: particlescope: A particle in the calculation of the range of dimensions; Input parameters: Adaptfunc: Fitness function% input parameters: Loopcount: Total number of iterations% input parameter: Curcount: The number of current iterations% return value: The meaning is the same as the input of the same parameter%% usage: [parswarm,optswarm]= Localsteppsobycircle (parswarm,optswarm,adaptfunc,particlescope,maxw,minw,loopcount,curcount)% Exception: First ensure that the file in the MATLAB search path, and then see the relevant information. % compiled by: xxx% Preparation time: 2010.5.6% reference: xxx% reference: xxx%% modified record-------------------------------------------------------------- --%2010.5.6% modified by: XXX% add 2*unifrnd (0,1). *subtract1 (ROW, the unifrnd (0,1) random number in the:), greatly improving the performance by modifying the mixing factor, from small to large, starting from curcount/loopcount% modify the range of c1=2.05,c2=2.05% change speed range of 0.5 (half) per dimension According to the design of particle swarm optimization algorithm based on MATLAB% overall evaluation: Using this version of the adjustment coefficient, the effect is better% of fault tolerant control if nargin~=8 error (' input parameter number is incorrect. ' End If nargout~=2 error (' The number of outputs is too small to guarantee cyclic iterations. ') End% start Step update%*********************************************%***** change the following code to change the inertia factor change * * *%------------------ ---------------------------------------------------% Linear decrement strategy w=maxw-curcount* ((MAXW-MINW)/loopcount); %---------------------------------------------------------------------%w fixed invariant strategy%w=0.7; %---------------------------------------------------------------------% references: Chen Guimin, Jia Jian, Hanqi, particle swarm optimization algorithm for decreasing inertia weight value, Journal of Xi ' an Jiaotong University, 2006,1%w, descending by concave function%w= (MAXW-MINW) * (Curcount/loopcount) ^2+ (MINW-MAXW) * (2*curcount/loopcount) +maxw; %---------------------------------------------------------------------%w, decreasing in concave function%w=minw* (MAXW/MINW) ^ (1/(1 + 10*curcount/loopcount)); %***** Change the above code, you can change the inertia factor change * * *%*********************************************% change the following code can be changedThe value of variable mixing factor is-----------------------------------------------hybrid=curcount/loopcount; %-----------------------------------------------% gets the particle swarm size and the information of a particle dimension [parrow,parcol]=size (Parswarm); % gets the dimension of the particle parcol= (PARCOL-1)/2; Globlesubtract1=optswarm (1:parrow,:)-parswarm (:, 1:parcol);% particle's own historical optimal solution position minus particle current position localsubtract1=optswarm (1:parrow ,:)-parswarm (:, 1:parcol),% particle's own historical optimal solution position minus the particle current position localsubtract2=optswarm (parrow+1:end-1,:)-parswarm (:, 1:parcol); Particle neighborhood optimal solution position minus particle current position%*********************************************%***** change the following code to change the C1,C2 change * * * * * c1=2.05; c2=2.05; %---------------------------------------------------------------------%con=1; %c1=4-exp (-con*abs (Parswarm (:, 2*parcol+1))-adaptfunc (Optswarm (parrow+1,:)))%c2=4-c1;%------------------ ----------------------------------------------------%***** Change the above code, you can change the c1,c2 change * * * * *%************************** For Row=1:parrow globlesubtract2=optswarm (parrow*2+1,:)-parswarm (Row,1:parcol); The global optimal position minus the current position of each particle localtempv=w.*paRswarm (Row,parcol+1:2*parcol) +c1*unifrnd (0,1). *localsubtract1 (Row,:) +c2*unifrnd (0,1). *localsubtract2 (row,:); Globletempv=w.*parswarm (Row,parcol+1:2*parcol) +c1*unifrnd (0,1). *globlesubtract1 (Row,:) +c2*unifrnd (0,1). * GlobleSubTract2; tempv=hybrid.*globletempv+ (1-hybrid). *LOCALTEMPV; % limit speed code for H=1:parcol if TEMPV (:, h) >particlescope (h,2)/2.0 TEMPV (:, h) =particlescope (h,2)/2.0; End If TEMPV (:, h) <-particlescope (h,2)/2.0 TEMPV (:, h) = (-particlescope (h,2) +1e-10)/2.0; % plus 1e-10 prevents the fitness function from being updated by 0 except end-end% Parswarm (row,parcol+1:2*parcol) =TEMPV; %*********************************************%***** Change the following code, you can change the constraint factor change * * *%--------------------------------- ------------------------------------%a=1; %---------------------------------------------------------------------a=0.729; %***** Change the above code, you can change the constraint factor changes * * *%*********************************************% limit position of the range Temppos=parswarm (row,1: Parcol) +A*TEMPV; For H=1:parcol if Temppos (:, h) >particlescope (h,2) Temppos (:, h) =particlescope (h,2); End IF Temppos (:, h) <=particlescope (h,1) Temppos (:, h) =particlescope (h,1) +1e-10; End end% Update position parswarm (Row,1:parcol) =temppos; % calculates the new fitness value of each particle parswarm (row,2*parcol+1) =adaptfunc (Parswarm (Row,1:parcol)); If Parswarm (row,2*parcol+1) >adaptfunc (Optswarm (Row,1:parcol)) Optswarm (Row,1:parcol) =ParSwarm (Row,1:ParCol); End%for Loop ending% determines the range of neighborhood Linyurange=fix (PARROW/2); % determines the neighborhood range of the current iteration Jiange=ceil (Loopcount/linyurange); Linyu=ceil (Curcount/jiange); For Row=1:parrow if Row-linyu>0&&row+linyu<=parrow tempm =[parswarm (row-linyu:row-1,:); Parswarm (Row+1:row+linyu,:)]; [Maxvalue,linyurow]=max (TEMPM (:, 2*parcol+1)); If Maxvalue>adaptfunc (Optswarm (Parrow+row,:)) optswarm (Parrow+row,:) =tempm (linyurow,1:parcol); end else if Row-linyu<=0% The upper part of the line highlights the boundary, and the following will definitely not break the boundary if Row==1 tempm=[parswarm (parrow+row-linyu:end,:); Parswarm (Row+1:row+linyu,:)]; [Maxvalue,linyurow]=max (TEMPM (:, 2*parcol+1)); If Maxvalue>adaptfunc (Optswarm (Parrow+row,:)) optswarm (Parrow+row,:) =tempm (linyurow,1:parcol); end ELSE Tempm=[parswarm (1:ROW-1,:); Parswarm (Parrow+row-linyu:end,:); Parswarm (Row+1:row+linyu,:)]; [Maxvalue,linyurow]=max (TEMPM (:, 2*parcol+1)); If Maxvalue>adaptfunc (Optswarm (Parrow+row,:)) optswarm (Parrow+row,:) =tempm (linyurow,1:parcol); end end Else% The section below the line highlights the bounds that will never break the boundary if Row==parrow tempm=[parswarm (parrow-linyu:row-1,:); Parswarm (1:linyu,:)]; [Maxvalue,linyurow]=max (TEMPM (:, 2*parcol+1)); If Maxvalue>adaptfunc (Optswarm (Parrow+row,:)) optswarm (Parrow+row,:) =tempm (linyurow,1:parcol); end Else tempM=[ Parswarm (row-linyu:row-1,:); Parswarm (Row+1:end,:); Parswarm (1:linyu-(Parrow-row),:)]; [Maxvalue,linyurow]=max (TEMPM (:, 2*parcol+1)); If Maxvalue>adaptfunc (Optswarm (Parrow+row,:)) optswarm (Parrow+row,:) =tempm (Linyurow,1:parcol); %for% to find the maximum solution of the fitness function value in the matrix (number of rows), and make the global optimal Change [Maxvalue,row]=max (Parswarm (:, 2*parcol+1)); If Adaptfunc (Parswarm (Row,1:parcol)) >adaptfunc (Optswarm (parrow*2+1,:)) optswarm (parrow*2+1,:) =ParSwarm (row,1: PARCOL); End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.