% -------------------------------------------------------------------------
% Chicken Swarm Optimization (CSO) (demo)
% Programmed by Xian-Bing Meng
% Updated at Jun 21, 2015.
% Email: x.b.meng12@gmail.com
%
% This is a simple demo version only implemented the basic idea of CSO for
% solving the unconstrained problem, namely Sphere function.
% The details about CSO are illustratred in the following paper.
% Xian-Bing Meng, et al. A new bio-inspired algorithm: Chicken Swarm
% Optimization. The Fifth International Conference on Swarm Intelligence
%
% The parameters in CSO are presented as follows.
% FitFunc % The objective function
% M % Maxmimal generations (iterations)
% pop % Population size
% dim % Dimension
% G % How often the chicken swarm can be updated.
% rPercent % The population size of roosters accounts for "rPercent"
% percent of the total population size
% hPercent % The population size of hens accounts for "hPercent" percent
% of the total population size
% mPercent % The population size of mother hens accounts for "mPercent"
% percent of the population size of hens
%
% Using the default value,CSO can be executed using the following code.
% [ bestX, fMin ] = CSO
% -------------------------------------------------------------------------
%*************************************************************************
% Revision 1
% Revised at May 23, 2015
% 1.Note that the previous version of CSO doen't consider the situation that
% there maybe not exist hens in a group.
% We assume there exist at least one hen in each group.
%*************************************************************************
% Main programs
function [ bestX, fMin ] = CSO( FitFunc, M, pop, dim, G, rPercent, hPercent, mPercent )
% Display help
help CSO.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set the default parameters
if nargin < 1
FitFunc = @Sphere;
M = 1000;
pop = 100;
dim = 20;
G = 10;
rPercent = 0.15;
hPercent = 0.7;
mPercent = 0.5;
end
rNum = round( pop * rPercent ); % The population size of roosters
hNum = round( pop * hPercent ); % The population size of hens
cNum = pop - rNum - hNum; % The population size of chicks
mNum = round( hNum * mPercent ); % The population size of mother hens
lb= -100*ones( 1,dim ); % Lower bounds
ub= 100*ones( 1,dim ); % Upper bounds
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Initialization
for i = 1 : pop
x( i, : ) = lb + (ub - lb) .* rand( 1, dim );
fit( i ) = FitFunc( x( i, : ) );
end
pFit = fit; % The individual's best fitness value
pX = x; % The individual's best position corresponding to the pFit
[ fMin, bestIndex ] = min( fit ); % fMin denotes the global optimum
% bestX denotes the position corresponding to fMin
bestX = x( bestIndex, : );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Start the iteration.
for t = 1 : M
% This parameter is to describe how closely the chicks would follow
% their mother to forage for food. In fact, there exist cNum chicks,
% thus only cNum values of FL would be used.
FL = rand( pop, 1 ) .* 0.4 + 0.5;
% The chicken swarm'status about hierarchal order, dominance
% relationship, mother-child relationship, the roosters, hens and the
% chicks in a group will remain stable during a period of time. These
% statuses can be updated every several (G) time steps.The parameter G
% is used to simulate the situation that the chicken swarm have been
% changed, including some chickens have died, or the chicks have grown
% up and became roosters or hens, some mother hens have hatched new
% offspring (chicks) and so on.
if( mod( t, G ) == 1 )
[ ans, sortIndex ] = sort( pFit );
% How the chicken swarm can be divided into groups and the identity
% of the chickens (roosters, hens and chicks) can be determined all
% depend on the fitness values of the chickens themselves. Hence we
% use sortIndex(i) to describe the chicken, not the index i itself.
motherLib = randperm( hNum, mNum ) + rNum;
% Randomly select mNum hens which would be the mother hens.
% We assume that all roosters are stronger than the hens, likewise,
% hens are stronger than the chicks.In CSO, the strong is reflected
% by the good fitness value. Here, the optimization problems is
% minimal ones, thus the more strong ones correspond to the ones
% with lower fitness values.
% Given the fact the 1 : rNum chickens' fitness values maybe not
% the best rNum ones. Thus we use sortIndex( 1 : rNum ) to describe
% the roosters. In turn, sortIndex( (rNum + 1) :(rNum + 1 + hNum ))
% to describle the mother hens, .....chicks.
% Here motherLib include all the mother hens.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Randomly select each hen's mate, rooster. Hence we can determine
% which group each hen inhabits using "mate".Each rooster stands
% for a group.For simplicity, we assume that there exist only one
% rooster and at least one hen in each group.
mate = randpermF( rNum, hNum );
% Randomly select cNum chicks' mother hens
mother = motherLib( randi( mNum, cNum, 1 ) );
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1 : rNum % Update the rNum roosters' values.
% randomly select another rooster different from the i (th) one.
anotherRooster = randiTabu( 1, rNum, i, 1 );
if( pFit( sortIndex( i ) ) <= pFit( sortIndex( anotherRooster ) ) )
tempSigma = 1;
else
tempSigma = exp( ( pFit( sortIndex( anotherRooster ) ) - ...
pFit( sortIndex( i ) ) ) / abs( pFit( sortIndex( i ) )...
+ realmin ) );
end
x( sortIndex( i ), : ) = pX( sortIndex( i ), : ) .* ( 1 + ...
tempSigma .* randn( 1, dim ) );
x( sortIndex( i ), : ) = Bounds( x( sortIndex( i ), : ), lb, ub );
fit( sortIndex( i ) ) = FitFunc( x( sortIndex( i ), : ) );
end
for i = ( rNum + 1 ) : ( rNum + hNum ) % Update the hNum hens' values.
other = randiTabu( 1, i, mate( i - rNum ), 1 );
% randomly select another chicken different from the i (th)
% chicken's mate. Note that the "other" chicken's fitness value
% should be superior to that of the i (th) chicken. This means the
% i (th) chicken may steal the better food found by the "other"
% (th) chicken.
c1 = exp( ( pFit( sortIndex( i ) ) - pFit( sortIndex( mate( i - ...
rNum ) ) ) )/ abs( pFit( sortIndex( i ) ) + realmin ) );
c2 = exp( ( -pFit( sortIndex( i ) ) + pFit( sortIndex( other ) )));
x( sortIndex( i ), : ) = pX( sortIndex( i ), : ) + ( pX(...
sortIndex( mate( i - rNum ) ), : )- pX( sortIndex( i ), : ) )...
.* c1 .* rand( 1, dim ) + ( pX( sortIndex( other ), : ) - ...
pX( sortIndex( i ), : ) ) .* c2 .* rand( 1, dim );
x( sortIndex( i ), : ) = Bounds( x( sortIndex( i ), : ), lb, ub );
fit( sortIndex( i ) ) = FitFunc( x( sortIndex( i ), : ) );
end
for i = ( rNum + hNum + 1 ) : pop % Update the cNum chicks' values.
x( sortIndex( i ), : ) = pX( sortIndex( i ), : ) + ( pX(
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
鸡群优化算法和鸟群算法.rar (2个子文件)
CSO.m 10KB
BSA.m 8KB
共 2 条
- 1
资源评论
小风飞子
- 粉丝: 356
- 资源: 1822
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功