• 刘一凡1
    了解作者
  • matlab
    开发工具
  • 386KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 6
    下载次数
  • 2020-04-08 11:21
    上传日期
可运行的蝙蝠算法代码,希望能给学习的小伙伴一些帮助
蝙蝠算法.zip
  • 蝙蝠算法
  • replay_pid28824.log
    645.3KB
  • replay_pid7760.log
    810.4KB
  • replay_pid20060.log
    723.4KB
  • Abat_algorithm.m
    2.8KB
  • replay_pid19832.log
    757.7KB
内容介绍
% Usage: bat_algorithm([20 0.25 0.5]); % function [best,fmin,N_iter]=Abat_algorithm(para) % Display help 显示帮助 help bat_algorithm.m % Default parameters 默认参数 if nargin<1, para=[10 0.25 0.5 0.8 0.6]; end n=para(1); % Population size, typically 10 to 25 人口规模通常为10-25人 A=para(2); % Loudness (constant or decreasing) 响度(恒定或减少) r=para(3); %脉冲发射频率 wmax=para(4); %权重系数最大值 wmin=para(5); % Pulse rate (constant or decreasing) 脉冲率(恒定或递减) % This frequency range determines the scalings 这个频率范围决定了刻度 Qmin=0; % Frequency minimum 频率的最小值 Qmax=2; % Frequency maximum 频率的最大值 % Iteration parameters 迭代参数 tol=10^(-5); % Stop tolerance 停止公差 N_iter=0; % Total number of function evaluations 功能评估总数 % Dimension of the search variables 搜索变量的维度 d=5; % Initial arrays 初始数组 Q=zeros(n,1); % Frequency 频率 v=zeros(n,d); % Velocities速度 % Initialize the population/solutions 初始化填充/解决方案 for i=1:n, Sol(i,:)=randn(1,d); Fitness(i)=Fun(Sol(i,:));%适应度 end % Find the current best [fmin,I]=min(Fitness); best=Sol(I,:); % ====================================================== % % Note: As this is a demo, here we did not implement the % % reduction of loudness and increase of emission rates. % % Interested readers can do some parametric studies % % and also implementation various changes of A and r etc % % ====================================================== % % Start the iterations -- Bat Algorithm 开始迭代 while (fmin>tol) for i=1:n fv(i)= Fitness(i); end favg=sum(fv)/n; for i=1;n if fv(i)<=favg w=wmin+(fv(i)-fmin)*(wmax-wmin)/(favg-fmin); else w=wmax; end Q(i)=Qmin+(Qmin-Qmax)*rand;% Frequency 频率 v(i,:)=w*v(i,:)+(Sol(i,:)-best)*Q(i); % Velocities速度 S(i,:)=Sol(i,:)+v(i,:); % Pulse rate if rand>r S(i,:)=best+0.01*randn(1,d); end % Evaluate new solutions Fnew=Fun(S(i,:)); % If the solution improves or not too loudness if (Fnew<=Fitness(i)) & (rand<A) , Sol(i,:)=S(i,:); Fitness(i)=Fnew; end % Update the current best if Fnew<=fmin, best=S(i,:); fmin=Fnew; end end N_iter=N_iter+n; end plot(Fitness) % Output/display disp(['Number of evaluations: ',num2str(N_iter)]); disp([' fmin=',num2str(fmin)]); disp(['Best =',num2str(best)]); function z=Fun(u) z=(1-u(1))^2+100*(u(2)-u(1)^2)^2+(1-u(3))^2+(u(4)-2)^2+(u(5)-0.4)^2;
评论
    相关推荐