100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 【智能优化算法】基于蝙蝠优化算法求解多目标优化问题附matlab代码

【智能优化算法】基于蝙蝠优化算法求解多目标优化问题附matlab代码

时间:2024-01-24 03:33:18

相关推荐

【智能优化算法】基于蝙蝠优化算法求解多目标优化问题附matlab代码

1 内容介绍

蝙蝠算法( BA) 是 Yang 教授于 年基于群体智能提出的启发式搜索算法,是一种搜索全局最优解的有效方法。该算法是一种基于迭代的优化技术,初始化为一组随机解,然后 通过迭代搜寻最优解,且在最优解周围通过随机飞行产生局部新解,加强了局部搜索。与其他算法相比,BA 在准确性和有效性方面远优于其他算法,且没有许多参数要进行调整。

2 仿真代码

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function moba_ns_new(inp),%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if nargin<1,% Check inputs (otherwise, default values)inp=[100 1000]; % [Pop size, #Iteration] e.g., inp=[100 1000]endnpop = inp(1); %% Population sizeGen = inp(2);%% Number of Iterationsm=2; %% Number of objectivesndim=30;%% ndim=dimensions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Parameter settings (initial values)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%AL= 0.9;r = 0.9;alpha = 0.9;Gamma = 0.9;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Initialize the increment components for bats/locationsdel_bats = zeros(npop,ndim);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%new_bats = zeros(npop,ndim);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Lb=zeros(1,ndim);% Lower boundsUb=ones(1,ndim);% Upper boundsminf=0; maxf=1; % Frequnecy range%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Initialize the populationfor i=1:npop,x(i,:)=Lb+(Ub-Lb).*rand(1,ndim);f(i,1:m) = obj_funs(x(i,:), m);end%% Combining x and f into a large matrix for easy storage%% x is an npop x ndim matrix, while f is an (npop x m) matrix.%% So the combined matrix has a size of npop x (ndim+m),%% with the last m columns being the m objective valuesbats=[x f];end%% Displaying the final Pareto Front as a graphfigure(2)plot(bats(:,ndim+1), bats(:,ndim+2),'rd');title(strcat(num2str(npop),' Points on the Pareto Front'));xlabel('Objective (f_1)'); ylabel('Objective (f_2)');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Make sure all the bats are within the limitsfunction [ns]=findlimits(ns,Lb,Ub)% Apply the lower boundns_tmp=ns;I=ns_tmp < Lb;ns_tmp(I)=Lb(I);% Apply the upper boundsJ=ns_tmp>Ub;ns_tmp(J)=Ub(J);% Update this new movens=ns_tmp;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Objective functionsfunction f = obj_funs(x, m)% Zitzler-Deb-Thiele's funciton No 3 (ZDT function 3)% m = number of objectives% ndim = number of variables/dimensionsndim=length(x); % ndim=30 for ZDT 3% First objective f1f(1) = x(1);g=1+9/29*sum(x(2:ndim));h=1-sqrt(f(1)/g)-f(1)/g*sin(10*pi*f(1));% Second objective f2f(2) = g*h;%%%%%%%%%%%%%%%%%% end of the definitions of obojectives %%%%%%%%%%%%%%%%%%%% Clean up the populations (both old and new) to give a new population% This cleanup here is similar to the Non-dominated Sorting Genetic% Algorithm (NSGA-II) by K. Deb et al. (2002), which can be applied to% any cleanup of 2*npop solutions to form a set of npop solutions.function new_bats = cleanup_batspop(bats, m, ndim, npop)% The input population to this part has twice (ntwice) of the needed% population size (npop). Thus, selection is done based on ranking and% crowding distances, calculated from the non-dominated sortingntwice= size(bats,1);% Ranking is stored in column KrankKrank=m+ndim+1;% Sort the population of size 2*npop according to their ranks[~,Index] = sort(bats(:,Krank)); sorted_bats=bats(Index,:);% Get the maximum rank among the populationRankMax=max(bats(:,Krank));%% Main loop for selecting solutions based on ranks and crowding distancesK = 0; % Initialization for the rank counter% Loop over all ranks in the populationfor i =1:RankMax,% Obtain the current rank i from sorted solutionsRankSol = max(find(sorted_bats(:, Krank) == i));% In the new bats/solutions, there can be npop solutions to fillif RankSol<npop,new_bats(K+1:RankSol,:)=sorted_bats(K+1:RankSol,:);end% If the population after addition is large than npop, re-arrangement% or selection is carried outif RankSol>=npop% Sort/Select the solutions with the current rankcandidate_bats = sorted_bats(K + 1 : RankSol, :);[~,tmp_Rank]=sort(candidate_bats(:,Krank+1),'descend');% Fill the rest (npop-K) bats/solutions up to npop solutionsfor j = 1:(npop-K),new_bats(K+j,:)=candidate_bats(tmp_Rank(j),:);endend% Record and update the current rank after adding new batsK = RankSol;end

3 运行结果

4 参考文献

[1]康志龙, 张雪萍, 陈雷,等. 基于多目标蝙蝠优化的高光谱图像解混算法[J]. 光电子.激光, , 29(3):8.

[2]裴文杰, 汪沨, 谭阳红,等. 基于蝙蝠算法的电力恢复机组选择多目标优化[J]. 计算机工程与应用, .

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

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。