【飞蛾扑火优化算法】基于交叉算子和非均匀变异算子的飞蛾扑火优化算法求解单目标优化问题附matlab代码

本文主要是介绍【飞蛾扑火优化算法】基于交叉算子和非均匀变异算子的飞蛾扑火优化算法求解单目标优化问题附matlab代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1 简介

针对飞蛾扑火优化算法收敛速度慢以及计算后期易收敛到局部最优解的问题,提出了一种基于遗传算法交叉算子和非均匀变异算子的改进方法.该方法在飞蛾围绕火焰飞行的计算过程中,采用交叉算子和变异算子对火焰位置进行扰动以生成新的火焰,当新火焰的适应度值优于原火焰时则替换原火焰,以提高算法的随机性,防止算法过快陷入局部最优解.测试结果表明,改进后的算法在8个常用最优化算法基准测试函数的求解问题中全局收敛能力和收敛速度均优于原算法.

2 部分代码

%______________________________________________________________________________________________%  Moth-Flame Optimization Algorithm (MFO)                                                            %  Source codes demo version 1.0                                                                      %                                                                                                     %  Developed in MATLAB R2011b(7.13)                                                                   %                                                                                                     %  Author and programmer: Seyedali Mirjalili                                                                                                              %                                                                                                     .07.006%_______________________________________________________________________________________________% You can simply define your cost in a seperate file and load its handle to fobj % The initial parameters that you need are:%__________________________________________% fobj = @YourCostFunction% dim = number of your variables% Max_iteration = maximum number of generations% SearchAgents_no = number of search agents% lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n% ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n% If all the variables have equal lower bound you can just% define lb and ub as two single number numbers% To run MFO: [Best_score,Best_pos,cg_curve]=MFO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj)%______________________________________________________________________________________________function [Best_flame_score,Best_flame_pos,Convergence_curve]=MFO(N,Max_iteration,lb,ub,dim,fobj)display('MFO is optimizing your problem');%Initialize the positions of mothsMoth_pos=initialization(N,dim,ub,lb);Convergence_curve=zeros(1,Max_iteration);Iteration=1;% Main loopwhile Iteration<Max_iteration+1        % Number of flames Eq. (3.14) in the paper    Flame_no=round(N-Iteration*((N-1)/Max_iteration));        for i=1:size(Moth_pos,1)                % Check if moths go out of the search spaceand bring it back        Flag4ub=Moth_pos(i,:)>ub;        Flag4lb=Moth_pos(i,:)<lb;        Moth_pos(i,:)=(Moth_pos(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;                  % Calculate the fitness of moths        Moth_fitness(1,i)=fobj(Moth_pos(i,:));              end           if Iteration==1        % Sort the first population of moths        [fitness_sorted I]=sort(Moth_fitness);        sorted_population=Moth_pos(I,:);                % Update the flames        best_flames=sorted_population;        best_flame_fitness=fitness_sorted;    else                % Sort the moths        double_population=[previous_population;best_flames];        double_fitness=[previous_fitness best_flame_fitness];                [double_fitness_sorted I]=sort(double_fitness);        double_sorted_population=double_population(I,:);                fitness_sorted=double_fitness_sorted(1:N);        sorted_population=double_sorted_population(1:N,:);                % Update the flames        best_flames=sorted_population;        best_flame_fitness=fitness_sorted;    end        % Update the position best flame obtained so far    Best_flame_score=fitness_sorted(1);    Best_flame_pos=sorted_population(1,:);          previous_population=Moth_pos;    previous_fitness=Moth_fitness;        % a linearly dicreases from -1 to -2 to calculate t in Eq. (3.12)    a=-1+Iteration*((-1)/Max_iteration);        for i=1:size(Moth_pos,1)                for j=1:size(Moth_pos,2)            if i<=Flame_no % Update the position of the moth with respect to its corresponsing flame                                % D in Eq. (3.13)                distance_to_flame=abs(sorted_population(i,j)-Moth_pos(i,j));                b=1;                t=(a-1)*rand+1;                                % Eq. (3.12)                Moth_pos(i,j)=distance_to_flame*exp(b.*t).*cos(t.*2*pi)+sorted_population(i,j);            end                        if i>Flame_no % Upaate the position of the moth with respct to one flame                                % Eq. (3.13)                distance_to_flame=abs(sorted_population(i,j)-Moth_pos(i,j));                b=1;                t=(a-1)*rand+1;                                % Eq. (3.12)                Moth_pos(i,j)=distance_to_flame*exp(b.*t).*cos(t.*2*pi)+sorted_population(Flame_no,j);            end                    end            end        Convergence_curve(Iteration)=Best_flame_score;        % Display the iteration and best optimum obtained so far    if mod(Iteration,50)==0        display(['At iteration ', num2str(Iteration), ' the best fitness is ', num2str(Best_flame_score)]);    end    Iteration=Iteration+1; end

3 仿真结果

4 参考文献

[1]张保东、张亚楠、郭黎明、江进礼、赵严振. 基于交叉算子和非均匀变异算子的飞蛾扑火优化算法[J]. 计算机与数字工程, 2020, 48(11):6.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

这篇关于【飞蛾扑火优化算法】基于交叉算子和非均匀变异算子的飞蛾扑火优化算法求解单目标优化问题附matlab代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/397176

相关文章

解读为什么@Autowired在属性上被警告,在setter方法上不被警告问题

《解读为什么@Autowired在属性上被警告,在setter方法上不被警告问题》在Spring开发中,@Autowired注解常用于实现依赖注入,它可以应用于类的属性、构造器或setter方法上,然... 目录1. 为什么 @Autowired 在属性上被警告?1.1 隐式依赖注入1.2 IDE 的警告:

解决java.lang.NullPointerException问题(空指针异常)

《解决java.lang.NullPointerException问题(空指针异常)》本文详细介绍了Java中的NullPointerException异常及其常见原因,包括对象引用为null、数组元... 目录Java.lang.NullPointerException(空指针异常)NullPointer

javaScript在表单提交时获取表单数据的示例代码

《javaScript在表单提交时获取表单数据的示例代码》本文介绍了五种在JavaScript中获取表单数据的方法:使用FormData对象、手动提取表单数据、使用querySelector获取单个字... 方法 1:使用 FormData 对象FormData 是一个方便的内置对象,用于获取表单中的键值

Vue ElementUI中Upload组件批量上传的实现代码

《VueElementUI中Upload组件批量上传的实现代码》ElementUI中Upload组件批量上传通过获取upload组件的DOM、文件、上传地址和数据,封装uploadFiles方法,使... ElementUI中Upload组件如何批量上传首先就是upload组件 <el-upl

Android开发中gradle下载缓慢的问题级解决方法

《Android开发中gradle下载缓慢的问题级解决方法》本文介绍了解决Android开发中Gradle下载缓慢问题的几种方法,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、网络环境优化二、Gradle版本与配置优化三、其他优化措施针对android开发中Gradle下载缓慢的问

关于Nginx跨域问题及解决方案(CORS)

《关于Nginx跨域问题及解决方案(CORS)》文章主要介绍了跨域资源共享(CORS)机制及其在现代Web开发中的重要性,通过Nginx,可以简单地解决跨域问题,适合新手学习和应用,文章详细讲解了CO... 目录一、概述二、什么是 CORS?三、常见的跨域场景四、Nginx 如何解决 CORS 问题?五、基

MySQL安装时initializing database失败的问题解决

《MySQL安装时initializingdatabase失败的问题解决》本文主要介绍了MySQL安装时initializingdatabase失败的问题解决,文中通过图文介绍的非常详细,对大家的学... 目录问题页面:解决方法:问题页面:解决方法:1.勾选红框中的选项:2.将下图红框中全部改为英

golang字符串匹配算法解读

《golang字符串匹配算法解读》文章介绍了字符串匹配算法的原理,特别是Knuth-Morris-Pratt(KMP)算法,该算法通过构建模式串的前缀表来减少匹配时的不必要的字符比较,从而提高效率,在... 目录简介KMP实现代码总结简介字符串匹配算法主要用于在一个较长的文本串中查找一个较短的字符串(称为

Nginx启动失败:端口80被占用问题的解决方案

《Nginx启动失败:端口80被占用问题的解决方案》在Linux服务器上部署Nginx时,可能会遇到Nginx启动失败的情况,尤其是错误提示bind()to0.0.0.0:80failed,这种问题通... 目录引言问题描述问题分析解决方案1. 检查占用端口 80 的进程使用 netstat 命令使用 ss

通俗易懂的Java常见限流算法具体实现

《通俗易懂的Java常见限流算法具体实现》:本文主要介绍Java常见限流算法具体实现的相关资料,包括漏桶算法、令牌桶算法、Nginx限流和Redis+Lua限流的实现原理和具体步骤,并比较了它们的... 目录一、漏桶算法1.漏桶算法的思想和原理2.具体实现二、令牌桶算法1.令牌桶算法流程:2.具体实现2.1