【优化求解】基于Levy飞行的飞蛾扑火优化算法(LMFO)求解单目标优化问题附matlab代码

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

1 简介

由于飞蛾扑火优化 (MFO)算法收敛速度和计算精度还有待提高,提出一种改进的基于 Lévy飞行轨迹的飞蛾扑火优化 (LMFO)算法。增强局部搜索能力,大幅度提升收敛速度和求解精度。对12个无约束基准函数进行实验测试,测试结果表明,改进后的 LMFO 是有效可行的。群智能算法一般来源于对自然界中一些生物群体行为的模仿,因其具有传统优化方法所不具有的优点,已 发展成为优化问题中的研究热点。飞蛾扑火优化 (moth-flameoptimization,MFO算法是由 Mirjalili提出的一种启发式优化算法,此算法的灵感来源于飞蛾在夜间一种奇特的导航方式。夜间飞蛾以月亮为参考物来辨别方向,当 飞 蛾 迷失方向的时候,只需根据月光来自己调整身体的方位,便能找到之前的 方 向。因其与月亮相距甚远,所 以 此 机 制 能确保沿直线运 动。在 现 实 世 界 里,飞蛾常常把人造光误 认为是月亮所发出 的 光,于是飞蛾便会绕着人造光作螺旋状盘旋,这就是时常会看到飞蛾绕着人造光作螺旋形移动的原因,同时也说明了横向定位的低效性。

在基本 MFO 算 法 中,假设飞蛾是候选解,矩 阵 M 表示飞蛾的集合,数组OM 用于存储相应的适应度值。该 算法的另外一个核心组件是火焰,火 焰 矩 阵 用 F 表 示,且 数组 M 和F 的 维 数 相 等,数 组 OF 用来存储相应的适应度值。在这里,飞蛾和火焰都是解。它 们 之 间 不 同 之 处 就 是在每一次迭代过程中对待和更新它们的方式不同。飞 蛾 是在搜索空间里移动的实际搜索主体,而火焰是飞蛾到目前为止获取的 最 佳 位 置。因 此,倘 若 找 到 一 个 更 好 的 解,每只飞蛾便在标记附近搜索并更新它。通 过 此 机 制,飞 蛾 永远不会错过它的最优解。

2 部分代码

%______________________________________________________________________________________________

%  Moth-Flame Optimization Algorithm (MFO) toolbox                                                            

%  Source codes demo version 1.0                                                                      

%                                                                                                     

%  Developed in MATLAB R2011b(7.13)                                                                   

%                                                                                                     

%  Author and programmer: Seyedali Mirjalili                                                          

%                                                                                                     

%         e-Mail: ali.mirjalili@gmail.com                                                             

%                 seyedali.mirjalili@griffithuni.edu.au                                               

%                                                                                                     

%       Homepage: http://www.alimirjalili.com                                                         

%                                                                                                     

%  Main paper:                                                                                        

%  S. Mirjalili, Moth-Flame Optimization Algorithm: A Novel Nature-inspired Heuristic Paradigm, 

%  Knowledge-Based Systems, DOI: http://dx.doi.org/10.1016/j.knosys.2015.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,handles,value)

display('MFO is optimizing your problem');

%Initialize the positions of moths

Moth_pos=initialization(N,dim,ub,lb);

Convergence_curve=zeros(1,Max_iteration);

Iteration=1;

% Main loop

while 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,:));

        All_fitness(1,i)=Moth_fitness(1,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;

    

     if Iteration>2

        line([Iteration-1 Iteration], [Convergence_curve(Iteration-1) Convergence_curve(Iteration)],'Color','b')

        xlabel('Iteration');

        ylabel('Best score obtained so far');        

        drawnow

    end

    

    set(handles.itertext,'String', ['The current iteration is ', num2str(Iteration)])

    set(handles.optimumtext,'String', ['The current optimal value is ', num2str(Best_flame_score)])

    if value==1

        hold on

        scatter(Iteration*ones(1,N),All_fitness,'.','k')

    end

    

    Iteration=Iteration+1; 

end

3 仿真结果

4 参考文献

[1]李志明,莫愿斌.基于Lévy飞行的飞蛾扑火优化算法[J].计算机工程与设计,2017,38(03):807-813.

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

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

这篇关于【优化求解】基于Levy飞行的飞蛾扑火优化算法(LMFO)求解单目标优化问题附matlab代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

JAVA项目swing转javafx语法规则以及示例代码

《JAVA项目swing转javafx语法规则以及示例代码》:本文主要介绍JAVA项目swing转javafx语法规则以及示例代码的相关资料,文中详细讲解了主类继承、窗口创建、布局管理、控件替换、... 目录最常用的“一行换一行”速查表(直接全局替换)实际转换示例(JFramejs → JavaFX)迁移建

Python实现快速扫描目标主机的开放端口和服务

《Python实现快速扫描目标主机的开放端口和服务》这篇文章主要为大家详细介绍了如何使用Python编写一个功能强大的端口扫描器脚本,实现快速扫描目标主机的开放端口和服务,感兴趣的小伙伴可以了解下... 目录功能介绍场景应用1. 网络安全审计2. 系统管理维护3. 网络故障排查4. 合规性检查报错处理1.

Go异常处理、泛型和文件操作实例代码

《Go异常处理、泛型和文件操作实例代码》Go语言的异常处理机制与传统的面向对象语言(如Java、C#)所使用的try-catch结构有所不同,它采用了自己独特的设计理念和方法,:本文主要介绍Go异... 目录一:异常处理常见的异常处理向上抛中断程序恢复程序二:泛型泛型函数泛型结构体泛型切片泛型 map三:文

Springboot3统一返回类设计全过程(从问题到实现)

《Springboot3统一返回类设计全过程(从问题到实现)》文章介绍了如何在SpringBoot3中设计一个统一返回类,以实现前后端接口返回格式的一致性,该类包含状态码、描述信息、业务数据和时间戳,... 目录Spring Boot 3 统一返回类设计:从问题到实现一、核心需求:统一返回类要解决什么问题?

maven异常Invalid bound statement(not found)的问题解决

《maven异常Invalidboundstatement(notfound)的问题解决》本文详细介绍了Maven项目中常见的Invalidboundstatement异常及其解决方案,文中通过... 目录Maven异常:Invalid bound statement (not found) 详解问题描述可

MyBatis中的两种参数传递类型详解(示例代码)

《MyBatis中的两种参数传递类型详解(示例代码)》文章介绍了MyBatis中传递多个参数的两种方式,使用Map和使用@Param注解或封装POJO,Map方式适用于动态、不固定的参数,但可读性和安... 目录✅ android方式一:使用Map<String, Object>✅ 方式二:使用@Param

idea粘贴空格时显示NBSP的问题及解决方案

《idea粘贴空格时显示NBSP的问题及解决方案》在IDEA中粘贴代码时出现大量空格占位符NBSP,可以通过取消勾选AdvancedSettings中的相应选项来解决... 目录1、背景介绍2、解决办法3、处理完成总结1、背景介绍python在idehttp://www.chinasem.cna粘贴代码,出

SpringBoot实现图形验证码的示例代码

《SpringBoot实现图形验证码的示例代码》验证码的实现方式有很多,可以由前端实现,也可以由后端进行实现,也有很多的插件和工具包可以使用,在这里,我们使用Hutool提供的小工具实现,本文介绍Sp... 目录项目创建前端代码实现约定前后端交互接口需求分析接口定义Hutool工具实现服务器端代码引入依赖获

利用Python在万圣节实现比心弹窗告白代码

《利用Python在万圣节实现比心弹窗告白代码》:本文主要介绍关于利用Python在万圣节实现比心弹窗告白代码的相关资料,每个弹窗会显示一条温馨提示,程序通过参数方程绘制爱心形状,并使用多线程技术... 目录前言效果预览要点1. 爱心曲线方程2. 显示温馨弹窗函数(详细拆解)2.1 函数定义和延迟机制2.2

Spring Boot基于 JWT 优化 Spring Security 无状态登录实战指南

《SpringBoot基于JWT优化SpringSecurity无状态登录实战指南》本文介绍如何使用JWT优化SpringSecurity实现无状态登录,提高接口安全性,并通过实际操作步骤... 目录Spring Boot 实战:基于 JWT 优化 Spring Security 无状态登录一、先搞懂:为什