【飞蛾扑火优化算法】基于交叉算子和非均匀变异算子的飞蛾扑火优化算法求解单目标优化问题附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

相关文章

Python实现MQTT通信的示例代码

《Python实现MQTT通信的示例代码》本文主要介绍了Python实现MQTT通信的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 安装paho-mqtt库‌2. 搭建MQTT代理服务器(Broker)‌‌3. pytho

Spring的RedisTemplate的json反序列泛型丢失问题解决

《Spring的RedisTemplate的json反序列泛型丢失问题解决》本文主要介绍了SpringRedisTemplate中使用JSON序列化时泛型信息丢失的问题及其提出三种解决方案,可以根据性... 目录背景解决方案方案一方案二方案三总结背景在使用RedisTemplate操作redis时我们针对

MySQL进行数据库审计的详细步骤和示例代码

《MySQL进行数据库审计的详细步骤和示例代码》数据库审计通过触发器、内置功能及第三方工具记录和监控数据库活动,确保安全、完整与合规,Java代码实现自动化日志记录,整合分析系统提升监控效率,本文给大... 目录一、数据库审计的基本概念二、使用触发器进行数据库审计1. 创建审计表2. 创建触发器三、Java

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

nginx中端口无权限的问题解决

《nginx中端口无权限的问题解决》当Nginx日志报错bind()to80failed(13:Permissiondenied)时,这通常是由于权限不足导致Nginx无法绑定到80端口,下面就来... 目录一、问题原因分析二、解决方案1. 以 root 权限运行 Nginx(不推荐)2. 为 Nginx

解决1093 - You can‘t specify target table报错问题及原因分析

《解决1093-Youcan‘tspecifytargettable报错问题及原因分析》MySQL1093错误因UPDATE/DELETE语句的FROM子句直接引用目标表或嵌套子查询导致,... 目录报js错原因分析具体原因解决办法方法一:使用临时表方法二:使用JOIN方法三:使用EXISTS示例总结报错原

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

MySQL深分页进行性能优化的常见方法

《MySQL深分页进行性能优化的常见方法》在Web应用中,分页查询是数据库操作中的常见需求,然而,在面对大型数据集时,深分页(deeppagination)却成为了性能优化的一个挑战,在本文中,我们将... 目录引言:深分页,真的只是“翻页慢”那么简单吗?一、背景介绍二、深分页的性能问题三、业务场景分析四、

Linux进程CPU绑定优化与实践过程

《Linux进程CPU绑定优化与实践过程》Linux支持进程绑定至特定CPU核心,通过sched_setaffinity系统调用和taskset工具实现,优化缓存效率与上下文切换,提升多核计算性能,适... 目录1. 多核处理器及并行计算概念1.1 多核处理器架构概述1.2 并行计算的含义及重要性1.3 并

SpringSecurity整合redission序列化问题小结(最新整理)

《SpringSecurity整合redission序列化问题小结(最新整理)》文章详解SpringSecurity整合Redisson时的序列化问题,指出需排除官方Jackson依赖,通过自定义反序... 目录1. 前言2. Redission配置2.1 RedissonProperties2.2 Red