您当前的位置: 首页 >  ar

Better Bench

暂无认证

  • 5浏览

    0关注

    695博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

布谷鸟算法(Cuckoo Search,CS)MATLAB案例详细解析

Better Bench 发布时间:2020-07-11 15:30:08 ,浏览量:5

目录
  • 一、布谷鸟算法理论
  • 二、CS算法应用于函数优化
    • 1.流程图
    • 3.代码解析
      • 3.1 主函数 Csmain.m
      • 3.2 Levy飞行 func_levy.m
      • 3.3 与上一代比较,返回较优的鸟巢 func_bestNestPop.m
      • 3.4 根据发现概率,舍弃一个鸟巢并建立一个新鸟巢 func_newBuildNest.m
      • 3.5 目标函数
      • 3.6 计算适应度函数
  • 三、输出结果
  • 四、CS案例MATLAB源码下载

一、布谷鸟算法理论

模拟退火算法(SA)、遗传算法(GA)、布谷鸟算法(CS)、人工蜂群算法(ABC)学习笔记—附MATLAB注释代码

二、CS算法应用于函数优化 1.流程图

在这里插入图片描述

3.代码解析 3.1 主函数 Csmain.m
% Script 布谷鸟算法,求解函数最小值
% @author zhaoyuqiang 
%#ok Remove hints of syntax
%#ok
%#ok
clear all ; 
close all ;
clc ;
N = 25; % 鸟巢的数量Number of nests(The scale of solution)
D = 10 ; % 问题的维度,一个鸟巢鸟蛋的个数 Dimensionality of solution
T =500 ; %迭代次数的上限 Number of iterations
Xmax = pi ;%%函数上限
Xmin = -pi ;%%函数下限
Pa = 0.25 ; % Probability of building a new nest(After host bird find exotic bird eggs)

nestPop = rand(N,D)*(Xmax-Xmin)+Xmin ;  % 初始化寄主的鸟巢Random initial solutions
for t=1:T
    levy_nestPop =  func_levy(nestPop,Xmax,Xmin) ; % 通过levy飞行产生一个解Generate new solutions by Levy flights
    nestPop = func_bestNestPop(nestPop,levy_nestPop);  % 与上一代比较,更新适应度较优的鸟巢Choose a best nest among  new and old nests     
    rand_nestPop = func_newBuildNest(nestPop,Pa,Xmax,Xmin); % 根据发现概率舍弃一个鸟巢并建立一个新鸟巢Abandon(Pa) worse nests and build new nests by (Preference random walk )
    nestPop = func_bestNestPop(nestPop,rand_nestPop) ; %列出当前最佳的鸟巢 Choose a best nest among  new and old nests
    [~,index] = max(func_fitness(nestPop)) ; % Best nests更新当代最优鸟巢的位置
    trace(t) = func_objValue(nestPop(index,:)) ;
    
    
end

[~,index] = max(func_fitness(nestPop)) ; % 查找当前最优鸟巢
%%%输出这个鸟巢里的每个鸟蛋,即是每个解
nestPop(index,:)
figure 
plot(trace);
xlabel('迭代次数') ;
ylabel('适应度值') ;
title('适应度进化曲线') ;
3.2 Levy飞行 func_levy.m

说白了就是实现一个随机搜索的公式来更新鸟巢的位置,

Xt+1 = Xt + α \alpha α S S就是服从Levy分布

Levy~u = t - β \beta β ,1

关注
打赏
1665674626
查看更多评论
立即登录/注册

微信扫码登录

0.0725s