资源简介
该算法用matlab工具实现粒子群(鸟群)算法收敛的动态过程
代码片段和文件信息
% 粒子群算法
% 标准函数测试
% 2005年10月
function PSO_test()
clear;
% select an optimization problem
NP_problem = 1;
switch NP_problem
case 0 % F6
% Shaffer‘ 2s F6 -100~100在x=0和y=0的条件下有fitness_max=1
uplimit = 10;
dnlimit = -10;
case 1
% Ras 函数,在x=0和y=0的条件下有最小值ras=0
uplimit = 1;
dnlimit = -1;
case 2
% Rosenbrock 函数,在x=1和y=1的条件下有最小值ros=0
uplimit = 2; % uplimit of each bit
dnlimit = -2; % dnlimit of each bit
end
% ---------- Initilization ----------
num_state = 2; % number of vectors
popsize = 30; % number of particles
max_gen = 400; % generation of evolution
max_v = 1; % maximum velocity
c1 = 2; % self learning factor
c2 = 0; % social learning factor
w_max = 0.9; % The maximum velocity coefficient
w_min = 0.4; % The minimum velocity coefficient
pbest = zeros(popsize1); % the best fitness among all selves
gbest = 0; % the best fitness among all
pid = []; % the particle corresponding to pbest
pgd = []; % the particle corresponding to gbest
% rand(‘seed‘1111); % remember the random seed
p = rand(popsizenum_state)*(uplimit-dnlimit)+dnlimit; % particle positions
% rand(‘seed‘2222); % remember the random seed
v = rand(popsizenum_state); % particle velocities
% start the inherit operation
t0 = clock;
% ---------- PSO Calculation Comparison and
评论
共有 条评论