欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

简易版:使用PSOGWO(粒子群与灰狼优化算法结合)在Matlab中寻找最佳解决方案的实例代码

最编程 2024-07-22 10:14:23
...

1 简介

针对粒子群算法有陷入局部最优的缺点,提出一种基于灰狼算法的粒子群优化算法。首先,根据自然界中优胜劣汰的生存法则,对每次迭代种群中的最差粒子进行进化,其次,由于粒子群算法中整个种群中的最优粒子有很强的引导能力,对 最 优粒子进行扰动,增大寻找全局最优的可能性;最后,结合灰狼优化算法,引导粒子群包围式进行搜索,增强全 局 搜 索 能 力;将 改进的粒子群算法与标准粒子群算法在 9个测试函数上进行了寻优精度和收敛速度的对比,结果证明改进粒子群算法 (PSO _GWO)在收敛速度和寻优精度上均优于粒子群算法 (PSO)。

2 部分代码

% this script implements the hybrid of PSO and GWO optimization algorithm. 
%This code is developed at https://free-thesis.com
% GWO code from https://in.mathworks.com/matlabcentral/fileexchange/44974-grey-wolf-optimizer-gwo
%is extended to make it hybrid with PSO and better than GWO.

%%

clear all 
clc
close all

SearchAgents_no=30; % Number of search agents

Function_name='F3'; % Name of the test function that can be from F1 to F23 (Table 1,2,3 in the paper)

Max_iteration=500; % Maximum numbef of iterations

% Load details of the selected benchmark function
[lb,ub,dim,fobj]=Get_Functions_details(Function_name);

[Best_score,Best_pos,PSOGWO_cg_curve]=PSOGWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
[Alpha_score,Alpha_pos,GWO_cg_curve]=GWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);

figure('Position',[500 500 660 290])
%Draw search space
subplot(1,2,1);
func_plot(Function_name);
title('Parameter space')
xlabel('x_1');
ylabel('x_2');
zlabel([Function_name,'( x_1 , x_2 )'])

%Draw objective space
subplot(1,2,2);
semilogy(PSOGWO_cg_curve,'Color','r')
hold on
semilogy(GWO_cg_curve,'Color','b')
title('Objective space')
xlabel('Iteration');
ylabel('Best score obtained so far');

axis tight
grid on
box on
legend('PSOGWO','GWO')

display(['The best solution obtained by PSOGWO is : ', num2str(Best_pos)]);
display(['The best optimal value of the objective funciton found by PSOGWO is : ', num2str(Best_score)]);
display(['The best solution obtained by GWO is : ', num2str(Alpha_pos)]);
display(['The best optimal value of the objective funciton found by GWO is : ', num2str(Alpha_score)]);
     

3 仿真结果

4 参考文献

[1]邱少明等. "一种基于粒子群位置更新思想灰狼优化算法的K-Means文本分类方法.", CN111368077A. 2020.

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

5 MATLAB代码与数据下载地址

见博客主页