您还没有登陆到CGPAD.COM   现在登录   注册新用户
搜索 CGPAD.COM
 
 
 
 浏览论坛    搜索论坛    规章制度    帮助  
社区成员: 23570   主题总数: 1374   回复总数: 3307   帖子总数: 4681   论坛跳转:  
 
 
论坛 数学软件 MATLAB (强大的数值、符号、图像、仿真等计算环境) 本版斑竹:招募中...
 
   帖子列表  原创作品  共享资源  
 
发表新主题
帖子搜索:  
 
A Simple Particle Swarm Optimization Implementation
查看:950  |  回复:1  |  创建:2009-06-12 08:51:17
 
SPAN (张友邦)
注册: 2008-04-24
积分: 12335 分
等级:
尘世如潮人如水 只叹江湖几人回
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Author: Zhang Youbang
% Time: 2009-06-11
% Version: 1.0
%
% This is a basic PSO algorithm implementation.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all
clear output
format compact

% some parameters
particle_number = 500; % total number of particles
iteration_number = 200; % the maximum iteration number
wmax = 20;
wmin = 0.01;
c1 = 2;
c2 = 2;
velocity_max = [15, 15];
velocity_init = [0, 0];

% initliaze particles
gbest_index = 1; % the global best particle's index

for progress = 1:iteration_number
  w(progress) = wmax - ((wmax - wmin) / iteration_number) * progress;
end

for progress = 1:iteration_number
  for i = 1:particle_number
    if progress == 1 % initialize the particle
      particles(i).location = [(rand - 0.5) * 10000, (rand - 0.5) * 10000];
      particles(i).fitness_value = pso_fittness_function(particles(i).location);
      
      particles(i).pbest_location = particles(i).location;
      particles(i).pbest_fitness_value = particles(i).fitness_value;

      particles(i).velocity = velocity_init; % just set it to zero
    elseif i ~= gbest_index % fly towards the global best fitted particle
      particles(i).velocity = w(progress) * particles(i).velocity + c1 * rand() * (particles(i).pbest_location - particles(i).location) + c2 * rand() * (particles(gbest_index).location - particles(i).location);
      
      % constraint velocity
      if particles(i).velocity(1) > velocity_max(1);particles(i).velocity(1) = velocity_max(1);end;
      if particles(i).velocity(1) < -velocity_max(1);particles(i).velocity(1) = -velocity_max(1);end;
      if particles(i).velocity(2) > velocity_max(2);particles(i).velocity(2) = velocity_max(2);end;
      if particles(i).velocity(2) < -velocity_max(2);particles(i).velocity(2) = -velocity_max(2);end;
      
      particles(i).location = particles(i).location + particles(i).velocity;
      particles(i).fitness_value = pso_fittness_function(particles(i).location);
    end

    % update local best location
    if particles(i).fitness_value < particles(i).pbest_fitness_value
      particles(i).pbest_location = particles(i).location;
      particles(i).pbest_fitness_value = particles(i).fitness_value;
    end

    % update global best fitted location
    if particles(i).pbest_fitness_value < particles(gbest_index).pbest_fitness_value
      gbest_index = i;
    end
  end % end of i
  
  % show the calculation progress
  [progress, particles(gbest_index).pbest_fitness_value]
end % end of n

% print the results
particles(gbest_index).pbest_location
particles(gbest_index).pbest_fitness_value


% end of this file




删除
 
编辑
 
标签:
 
附件:请登陆后查看附件内容!
 
声明:CGPAD文章版权属于作者,受法律保护。没有作者书面许可不得转载。
 
 <<上一页 1 下一页>>   

 注册: 2008-04-24
 积分: 12335 分
 等级:
 尘世如潮人如水 只叹江湖几人回


  2009-06-12 09:02:05 #1
If you want to see something more about the Particle Swarm Optimization, please go this address: http://www.swarmintelligence.org




 
 <<上一页 1 下一页>>   
 
 
版权所有 © 2005-2008 CGPAD.COM,湘ICP备07500998号,兼容浏览器:IE6IE7FireFoxOperaSafariChrome
Total Requests: 5275904, Total Visits: 3085111, Processing Time: 344ms,