Thuật Toán Tối Ưu Bầy Đàn PSO - 123doc

Code Mẫu Thuật Toán Tối Ưu Bầy Đàn Áp Dụng Cho Các Bài Toán Tối Ưu. Áp dụng đơn giản vào bài toán một cách dễ dàng. Đây là code mẫu theo lưu đồ giải thuật PSO, chỉ cần xác định được hàm mục tiêu, các ràng buộc là áp dụng được.

Trang 1

Code · March 2016

DOI: 10.13140/RG.2.1.1078.7608

CITATIONS

4

READS

114,791

1 author:

Some of the authors of this publication are also working on these related projects:

Application of operation research on solving electrical engineering problems View project

Networked Microgrids View project

Mahamad Nabab Alam

Indian Institute of Technology Roorkee

20PUBLICATIONS    134CITATIONS    

SEE PROFILE

Trang 2

Codes in MATLAB for Particle Swarm Optimization

Mahamad Nabab Alam, Research Scholar Particle swarm optimization (PSO) codes in MATLAB suitable for solving constrained optimization problem

Save the following codes in MATLAB script file (*.m) and save as ofun.m

-start

% objective function (minimization)

of=10*(x(1)-1)^2+20*(x(2)-2)^2+30*(x(3)-3)^2;

% constraints (all constraints must be converted into <=0 type)

% if there is no constraints then comments all c0 lines below

c0=[];

% defining penalty for each constraint

c(i)=1;

c(i)=0;

end

-end Save the following main program codes in MATLAB script file (*.m) as run_pso.m (any name can be used) and run

-start tic

clc

% pso parameters values

% pso main program -start

Trang 3

maxrun=10; % set maximum number of runs need to be

run

x0(i,j)=round(LB(j)+rand()*(UB(j)-LB(j)));

f0(i,1)=ofun(x0(i,:));

[fmin0,index0]=min(f0);

ite=1;

tolerance=1;

while ite<=maxite && tolerance>10^-12

+c2*rand()*(gbest(1,j)-x(i,j));

x(i,j)=x(i,j)+v(i,j);

x(i,j)=LB(j);

x(i,j)=UB(j);

f(i,1)=ofun(x(i,:));

Trang 4

3

pbest(i,:)=x(i,:);

f0(i,1)=f(i,1);

gbest=pbest(index,:);

fmin0=fmin;

tolerance=abs(ffmin(ite-100,run)-fmin0);

ite=ite+1;

gbest;

fvalue=10*(gbest(1)-1)^2+20*(gbest(2)-2)^2+30*(gbest(3)-3)^2;

fff(run)=fvalue;

rgbest(run,:)=gbest;

end

% pso main program -end

[bestfun,bestrun]=min(fff)

best_variables=rgbest(bestrun,:)

toc

% PSO convergence characteristic

%########################################################################## -end Enjoy with PSO;

******************************************************************************************

Từ khóa » Thuật Toán Tối ưu Hóa Bầy đàn