【优化算法】基于变异策略的改进型花朵授粉算法【Matlab 485期】

一、简介

介绍了一种新的元启发式群智能算法——花朵授粉算法(flower pollinate algorithm,FPA)和一种新型的差分进化变异策略——定向变异(targeted mutation,TM)策略。针对FPA存在的收敛速度慢、寻优精度低、易陷入局部最优等问题,提出了一种基于变异策略的改进型花朵授粉算法——MFPA。该算法通过改进TM策略,并应用到FPA的局部搜索过程中,以增强算法的局部开发能力。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、源代码

function [pdd,fmin ] =pso( c1,c2,Vmax,Vmin,popmax,popmin,sizepop,maxgen)
%UNTITLED2 此处显示有关此函数的摘要
%   此处显示详细说明
PLb=-5.12*ones(1,30);
PUb=5.12*ones(1,30);
pop=zeros(sizepop,30);
V=zeros(1,30);
fitnessP=zeros(1,sizepop);
for i=1:sizepop
    pop(i,:)=PLb+(PUb-PLb)*rand;
    V(i,:)=rands(1,30);
    fitnessP(i)=Fun(pop(i,:));
end
[bestfitness bestindex]=min(fitnessP);
zbest=pop(bestindex,:);   %全局最佳
gbest=pop;    %个体最佳
fitnessgbest=fitnessP;   %个体最佳适应度值
fitnesszbest=bestfitness;   %全局最佳适应度值
% Ntime11=1	;
% Ntime=Ntime11-1;
% maxgen=0;
% ptol=0.01;
% while(fitnesszbest>ptol),
for i11=1:maxgen
  
    for j=1:sizepop
        
        %速度更新
        V(j,:) = V(j,:) + c1*rand*(gbest(j,:)-pop(j,:)) + c2*rand*(zbest-pop(j,:));
        V(j,find(V(j,:)>Vmax))=Vmax;
        V(j,find(V(j,:)<Vmin))=Vmin;
        
        %种群更新
        pop(j,:)=pop(j,:)+0.2*V(j,:);
        pop(j,find(pop(j,:)>popmax))=popmax;
        pop(j,find(pop(j,:)<popmin))=popmin;
        
        %自适应变异
        pos=unidrnd(30);
        if rand>0.95
            pop(j,pos)=5.12*rands(1,1);
        end
      
        %适应度值
%          pop(j,:)=simpleboundsP(pop(j,:),PLb,PUb);
        fitnessP(j)=Fun(pop(j,:));
      
    end
    
    for j=1:sizepop
    %个体最优更新
    if fitnessP(j) < fitnessgbest(j)
        gbest(j,:) = pop(j,:);
        fitnessgbest(j) = fitnessP(j);
    end
    
    %群体最优更新 
    if fitnessP(j) < fitnesszbest
        zbest = pop(j,:);
        fitnesszbest = fitnessP(j);
    end
%         Ntime11=Ntime11+1;
       
  
     
    
    end
%     maxgen=maxgen+1;
%     if maxgen>10000,
%         fitnesszbest=ptol-1;
%     end
%    if round(i11/30)==i11/30,
     pdd(i11)=fitnesszbest; 
%    end
       
end
fmin =fitnesszbest;
end
% function sfP=simpleboundsP(sfP,PLb,PUb)
%   % Apply the lower bound
%   ns_tmpfP=sfP;
%   IfP=ns_tmpfP<PLb;
%   ns_tmpfP(IfP)=PLb(IfP);
%   
%   % Apply the upper bounds 
%   JfP=ns_tmpfP>PUb;
%   ns_tmpfP(JfP)=PUb(JfP);
%   % Update this new move 
%   sfP=ns_tmpfP;
% end
% ======================================================== % 
% Files of the Matlab programs included in the book:       %
% Xin-She Yang, Nature-Inspired Metaheuristic Algorithms,  %
% Second Edition, Luniver Press, (2010).   www.luniver.com %
% ======================================================== %    

% -------------------------------------------------------- %
% Bat-inspired algorithm for continuous optimization (demo)%
% Programmed by Xin-She Yang @Cambridge University 2010    %
% -------------------------------------------------------- %
% Usage: bat_algorithm([20 0.25 0.5]);                     %

function [pblt,fminbl]=bat_algorithm(nb,A,r,BQmin,BQmax,db,NB)
% Display help
%  help bat_algorithm.m

% Default parameters
% if nargin<1,  para=[10 0.25 0.5];  end
% nb=para(1);      % Population size, typically 10 to 25
% A=para(2);      % Loudness  (constant or decreasing)
% r=para(3);      % Pulse rate (constant or decreasing)
% % This frequency range determines the scalings
% BQmin=0;         % Frequency minimum
% BQmax=2;         % Frequency maximum
% % Iteration parameters
%  % Stop tolerance
% N_iter=0;       % Total number of function evaluations
% Dimension of the search variables
% db=5;
% Initial arrays
BLb=-5.12*ones(1,db);
BUb=5.12*ones(1,db);
Q=zeros(nb,1);   % Frequency
v=zeros(nb,db);   % Velocities
Solb=zeros(nb,db);
Fitnessb=zeros(1,nb);
Sb=zeros(nb,db);
% Initialize the population/solutions
for i=1:nb,
  Solb(i,:)=BLb+(BUb-BLb)*rand;
  Fitnessb(i)=Fun(Solb(i,:));
end
% Find the current best
[fminb,Ib]=min(Fitnessb);
bestb=Solb(Ib,:);

% ======================================================  %
% Note: As this is a demo, here we did not implement the  %
% reduction of loudness and increase of emission rates.   %
% Interested readers can do some parametric studies       %
% and also implementation various changes of A and r etc  %
% ======================================================  %
% btol=0.01;
% NB=0;
% Start the iterations -- Bat Algorithm
% while(fminb>btol),
for tb =1: NB,
        % Loop over all bats/solutions
        for i=1:nb,
          Q(i)=BQmin+(BQmin-BQmax)*rand;
          v(i,:)=v(i,:)+(Solb(i,:)-bestb)*Q(i);
          Sb(i,:)=Solb(i,:)+v(i,:);
          % Pulse rate
          if rand>r
              Sb(i,:)=bestb+0.01*randn(1,db);
          end

     % Evaluate new solutions
       Sb(i,:)=BsimpleboundsP(Sb(i,:),BLb,BUb);
           Fnewb=Fun(Sb(i,:));
     % If the solution improves or not too loudness
           if (Fnewb<=Fitnessb(i)) & (rand<A) ,
                Solb(i,:)=Sb(i,:);
                Fitnessb(i)=Fnewb;
           end

          % Update the current best
          if Fnewb<=fminb,
                bestb=Sb(i,:);
                fminb=Fnewb;
          end
        end
        function [aa,fminf,Ntime ] = fpa(n,p,N_iter,d )
%UNTITLED3 此处显示有关此函数的摘要
%   此处显示详细说明
Lb=-600*ones(1,d);
Ub=600*ones(1,d);
 Sol=zeros(n,d);
  Fitness=zeros(1,n);
for i=1:n,
  Sol(i,:)=Lb+(Ub-Lb)*rand;
  Fitness(i)=Fun(Sol(i,:));
end

% Find the current best
[fmin,I]=min(Fitness);
best=Sol(I,:);
S=Sol;
 Ntime=1;
  Ntime= Ntime-1;
for t=1:N_iter,
        % Loop over all bats/solutions
        for i=1:n,
          % Pollens are carried by insects and thus can move in
          % large scale, large distance.
          % This L should replace by Levy flights  
          % Formula: x_i^{
    
    t+1}=x_i^t+ L (x_i^t-gbest)
          if rand<p,
          %% L=rand;
          L=Levy(d);
          
          dS=L.*(Sol(i,:)-best);
          S(i,:)=Sol(i,:)+dS;
          
          % Check if the simple limits/bounds are OK
          S(i,:)=simplebounds(S(i,:),Lb,Ub);
          
          % If not, then local pollenation of neighbor flowers 
          else
              epsilon=rand;
              % Find random flowers in the neighbourhood
              JK=randperm(n);
             

%               end
              % As they are random, the first two entries also random
              % If the flower are the same or similar species, then
              % they can be pollenated, otherwise, no action.
              % Formula: x_i^{
    
    t+1}+epsilon*(x_j^t-x_k^t)
%            
               S(i,:)=S(i,:)+epsilon*(Sol(JK(1))-Sol(JK(2)));
%               
              % Check if the simple limits/bounds are OK
              S(i,:)=simplebounds(S(i,:),Lb,Ub);
          end

三、运行结果

在这里插入图片描述

四、备注

完整代码或者代写添加QQ912100926
往期回顾>>>>>>
【优化求解】粒子群算法之充电站最优布局【Matlab 061期】
【优化求解】遗传算法之多旅行商问题【Matlab 062期】
【优化求解】遗传和模拟退火之三维装箱问题【Matlab 063期】
【优化求解】遗传算法之求最短路径【Matlab 064期】
【优化求解】粒子群之优化灰狼算法【Matlab 065期】
【优化求解】多目标之灰狼优化算法MOGWO 【Matlab 066期】
【优化求解】遗传算法之求解优化车辆发车间隔【Matlab 067期】
【优化求解】磷虾群算法简介【Matlab 068期】
【优化求解】差分进化算法简介【Matlab 069期】
【优化求解】约束优化之惩罚函数法简介【Matlab 070期】
【优化求解】改进灰狼算法之求解重油热解模型【Matlab 072期】
【优化求解】蚁群算法之配电网故障定位【Matlab 073期】
【优化求解】遗传算法之求解岛屿物资补给优化问题【Matlab 137期】
【优化求解】基于matlab冠状病毒群体免疫优化算法(CHIO)【Matlab 138期】
【优化求解】基于matlab之金鹰优化求解算法(GEO)【Matlab 139期】
【优化求解】基于GUI界面之BP神经网络优化求解【Matlab 179期】
【优化求解】基于GUI界面之遗传算法优化求解【Matlab 180期】
【优化求解】基于GUI界面之蚁群算法优化求解【Matlab 181期】
【优化求解】 免疫算法之数值逼近优化分析【Matlab 182期】
【优化求解】 启发式算法之函数优化分析【Matlab 183期】
【优化求解】改进的遗传算法(GA+IGA)之城市交通信号优化【Matlab 184期】
【优化求解】改进的遗传算法GA之城市交通信号优化【Matlab 185期】
【优化求解】改进的遗传算法IGA之城市交通信号优化【Matlab 186期】
【优化求解】罚函数的粒子群算法之函数寻优【Matlab 187期】
【优化求解】细菌觅食算法之函数优化分析【Matlab 188期】
【优化求解】引力搜索算法之函数优化分析【Matlab 189期】
【优化求解】蚁群算法之函数优化分析【Matlab 190期】
【优化求解】多元宇宙优化算法【Matlab 191期】
【优化求解】飞蛾扑火算法(MFO)【Matlab 192期】
【优化求解】实现电动汽车有序充电【Matlab 294期】
【优化求解】粒子群的智能微电网多目标优化算法【Matlab 295期】
【优化求解】PSO货物配装问题最优化【Matlab 296期】
【优化求解】人工鱼群算法求解梯级水库优化调度【Matlab 297期】
【优化求解】改进的人工鱼群算法求解高维问题【Matlab 298期】
【优化求解】粒子群算法解决经济调度【Matlab 299期】
【优化求解】遗传算法的资源配置【Matlab 300期】
【优化求解】遗传算法求解电力系统最优潮流问题【Matlab 353期】
【优化求解】电动汽车有序充电【Matlab 475期】
【优化求解】遗传算法的资源配置【Matlab 476期】
【优化求解】基于PSO的多目标优化问题【Matlab 477期】
【优化求解】小区基站最优化选址问题【Matlab 478期】
【优化求解】粒子群算法的多目标优化【Matlab 479期】
【优化求解】基于人工鱼群求解多目标优化问题【Matlab 480期】
【优化求解】粒子群的微电网多目标优化【Matlab 481期】
【优化求解】蜻蜓算法求解多目标优化问题【Matlab 482期】
【优化算法】海洋捕食者算法(MPA)【Matlab 483期】
【优化算法】黑洞模拟算法(MVO)【Matlab 484期】

猜你喜欢

转载自blog.csdn.net/m0_54742769/article/details/115007895