鲸鱼蚁群算法结合Matlab,如何优化求解函数极值问题?

2026-05-16 11:521阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计813个文字,预计阅读时间需要4分钟。

鲸鱼蚁群算法结合Matlab,如何优化求解函数极值问题?

1+内容介绍+蚁群算法是模仿蚂蚁觅食、遗传算法、禁忌搜索等之后的一种新型智能优化算法,由意大利意利学者M.Dorigo等人首次提出,并广泛用于求解一系列组合优化问题,如旅行商问题。

1 内容介绍

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

2 部分代码

clear

close all

鲸鱼蚁群算法结合Matlab,如何优化求解函数极值问题?

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.

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


本文共计813个文字,预计阅读时间需要4分钟。

鲸鱼蚁群算法结合Matlab,如何优化求解函数极值问题?

1+内容介绍+蚁群算法是模仿蚂蚁觅食、遗传算法、禁忌搜索等之后的一种新型智能优化算法,由意大利意利学者M.Dorigo等人首次提出,并广泛用于求解一系列组合优化问题,如旅行商问题。

1 内容介绍

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

2 部分代码

clear

close all

鲸鱼蚁群算法结合Matlab,如何优化求解函数极值问题?

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.

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