function [x,endPop]=pso(bounds,w,c1,c2,termFns,termOps,evalFN,...
evalOps,startPop,pbest,gbest);
% PSO run a particle swarm algorithm
% [x,endPop,bestPop,trace]=pso(bounds,w,c1,c2,termFns,termOps,evalFn,evalOps,
% startPop,pbest,gbest);
%
% Output Arguments:
% x - the best solution found during the course of the run
% endPop - the final population
% bPop - a trace of the best population
% traceInfo - a matrix of best and means of the ga for each generation
%
% Input Arguments:
% bounds - a matrix of upper and lower bounds on the variables
% w - the inertia weight
% c1,c2 - the acceleration constants
% termFns - name of the .m termination function (['maxGenTerm'])
% termOps - options string to be passed to the termination function
% ([100]).
% evalFn - the name of the evaluation .m function
% evalOps - options to pass to the evaluation function ([NULL])
% startPop - a matrix of solutions that can be initialized
% from initialize.m
% pbest - the initial best solution of each particle
% gbest - the initial best solution of generation 1
% This program is written by Li Jun on Dec,15,2003.All rights reserved
D = size(bounds,1);
num = size(startPop,1);
gen = 1 ;
done = 0 ;
vnow = startPop(:,(D+1):2*D);
xnow = startPop(:,1:D);
xnew = xnow;
pb = pbest;
gb = gbest;
while(~done)
%Caculate the fitness value of position xnow
xnow=xnew;
for m=1:num
eval(['[sol,val]=' evalFN '(xnow(m,1:2),1);']);
value(m,1)=val;
end
%replace the pbest
for m=1:num
if pb(m,D+1) < value(m,1)
pb(m,1:D)=xnow(m,1:D);
pb(m,D+1)=value(m,1);
end
end
%replace the gbest
[maxval,col]=max(value);
if gb(D+1) < maxval
gb=[xnow(col,:),maxval];
bestg=gen;
end
%caculate the vnew and xnew
vnow = w*vnow+c1*rand*(pb(:,1:D)-xnow)+c2*rand*([gb(1)*ones(num,1),...
gb(2)*ones(num,1)]-xnow);
xnew = xnow+vnow;
if (100-gb(3)<1e-6) | (gen >= termOps)
done=1;
else
gen=gen+1;
w=w-0.01; % w declines linearly
fprintf(1,'%d ',gen);
end
end
endPop=[xnow,value];
x=gb;
fprintf(1,'\n w= %f',w);
fprintf(1,'\n bestgen= %d',bestg);
传统PSO算法及其初始化.zip_PSO_初始化
版权申诉
136 浏览量
2022-09-23
04:40:58
上传
评论
收藏 2KB ZIP 举报
小波思基
- 粉丝: 72
- 资源: 1万+
最新资源
- baseuavAntColonyOptimization-master.zip
- 碳排放权交易明细数据(2024年5月更新).xlsx
- 特殊文件属性命令chattr和lsattr
- HTML、CSS 和 JavaScript动态、交互式的网页 .txt
- b0cd8f9b23d4e5e381b6a8fd8ee0e907.JPG
- ff45d61c5900e45634cf4cac6cff61a1.JPG
- springboot.springboot.springboot.springboot.txt
- linux-进程与服务管理
- 毕业设计基于Django+MySQL+Redis实现简单的天气预报系统python源码.zip
- 基于Streamlit的口罩人脸识别系统python源码+模型+使用说明.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈