【智能优化算法】基于鲸鱼算法结合蚁群算法求解函数极值问题含Matlab代码

本文介绍了蚁群算法在解决复杂离散优化问题上的优势,特别是针对多峰函数优化的问题。通过展示代码示例,演示了如何使用蚁群算法和改进的WABC算法进行优化,并对比了两种算法在寻找函数极值时的表现。最后,通过绘制图表展示了算法的性能,并给出了多次运行的平均值和标准差。
摘要由CSDN通过智能技术生成

1 内容介绍

蚁群算法是继模拟退火、遗传算法、禁忌搜索等之后的又一启发式智能优化算法,它是由意大利学者M.Dorigo等人首次提出,并广泛应用于求解一系列组合优化问题,如:旅行商问题,二次分配问题,车辆路径问题和图着色问题等,这些应用充分显示了它在解决复杂离散优化问题方面的优越性。连续空间函数优化问题也是蚁群算法的研究课题之一,多峰函数优化又是函数优化的一个重要方面,但目前蚁群算法对该问题的研究主要是集中在求解函数的最大(小)值,对求解函数所有极值方面的研究却很少。

2 部分代码

clear

close all

clc

% Set ABC Control Parameters

ABCOpts = struct( 'ColonySize',  100, ...   % Number of Employed Bees+ Number of Onlooker Bees 种群规模

    'MaxCycles', 500,...   % Maximum cycle number in order to terminate the algorithm 循环次数,即全部蚂蚁走几遍

    'ErrGoal',   1e-20, ...  % Error goal in order to terminate the algorithm (not used in the code in current version)

    'Dim',       20 , ... % Number of parameters of the objective function 维数

    'Limit',   100, ... % Control paramter in order to abandone the food source 放弃食物源的阈值

    'lb',  -5.12, ... % Lower bound of the parameters to be optimized 函数值下限

    'ub',  5.12, ... %Upper bound of the parameters to be optimized 函数值上限

    'ObjFun' , 'rastrigin', ... %Write the name of the objective function you want to minimize 选择函数

    'RunTime',3); % Number of the runs 迭代次数

GlobalMins=zeros(ABCOpts.RunTime,ABCOpts.MaxCycles);

GlobalMins_WABC=zeros(ABCOpts.RunTime,ABCOpts.MaxCycles);

for r=1:ABCOpts.RunTime

    

    % Initialise population

    Range = repmat((ABCOpts.ub-ABCOpts.lb),[ABCOpts.ColonySize ABCOpts.Dim]);

    Lower = repmat(ABCOpts.lb, [ABCOpts.ColonySize ABCOpts.Dim]);

    Colony = rand(ABCOpts.ColonySize,ABCOpts.Dim) .* Range + Lower;

    

    Employed=Colony(1:(ABCOpts.ColonySize/2),:);

    GlobalMins(r,:) = ABCbee(ABCOpts,Employed);  % ABC算法

   GlobalMins_WABC(r,:) = WABCbee(ABCOpts,Employed);  % WABC-ABC算法

end; %end of runs

%----------------------------- 画图、记录最优均值和方差 --------------------------

dd=ABCOpts.MaxCycles;

if ABCOpts.RunTime==1

    semilogy((1:10:dd),GlobalMins(1:10:end));

    hold on

    semilogy((1:10:dd),GlobalMins_WABC(1:10:end),'-*g');

else

    semilogy((1:10:dd),mean(GlobalMins(:,1:10:end)));%若多次执行,求均值

    hold on

    semilogy((1:10:dd),mean(GlobalMins_WABC(:,1:10:end)),'-*g');%若多次执行,求均值

end

grid on

title('Mean of Best function values');

xlabel('cycles');

ylabel('fitness');

legend('ABC','WABC');

fprintf('Mean =%g Std=%g\n',mean(GlobalMins(:,end)),std(GlobalMins(:,end)));

fprintf('Mean =%g Std=%g\n',mean(GlobalMins_WABC(:,end)),std(GlobalMins_WABC(:,end)));

3 运行结果

4 参考文献

[1]刘卉. 应用蚁群算法求解函数所有极值[D]. 四川师范大学, 2011.

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

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值