• 大小: 6KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-06-11
  • 语言: Matlab
  • 标签: matalb  

资源简介

matlab蛙跳算法程序!这里面是matlab蛙跳算法的程序,实现简单易懂!

资源截图

代码片段和文件信息

function SFLA_Func01
 
tic; t1=clock; 
num=1;
ge=100;
le=10
  fit2=zeros(numge*le);
  sbest=zeros(1num);
  for tdy=1:num
 
 
  M=40;
  
m=4;
n=5;
q=m*n;
ge=100;
le=10;
 
Dmin= -100;
Dmax =100;
c=2;
 
fit=[];

%%%%%%%%%%%%%%%%
NN=0.2;



frog=struct(‘fitness‘{}‘center‘{});
% lfrog= struct(‘fitness2‘{}‘center2‘{});


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%1) Sphere function [-100100]  data=a+(b-a)*rand(mn)
     
%     
%       data=-5.12+5.12*2*rand(1M);
%     
%      f1=0.0;
%     for  t=1:size(data2)
%         
%      f1=f1+data(t)*data(t);
%     end
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
for i=1:q 
  
            data=-100+100*2*rand(1M);
%             data=-5.12+5.12*2*rand(1M);
%          
        
      f1=0.0;
      for  t=1:size(data2)
         
          f1=f1+data(t)*data(t);
      end
       f1;
       fitness=f1;

       frog(i).fitness=fitness;
      frog(i).center=data;
end
 

 

w=1;
%%%%%%%%%%%%%%%%%
 
 
for v=1:ge %混合排序

    
    
         for I=1:q-1
             for J=1:q-I
                if frog(J).fitness < frog(J+1).fitness
                     temp=frog(J+1).fitness;
                     temp2=frog(J+1).center;
            
                      frog(J+1).fitness=frog(J).fitness;
                      frog(J+1).center=frog(J).center;
             
                      frog(J).center=temp2;
                      frog(J).fitness=temp;
                end 
             end
         end
  


 
      Xg=frog(q)  ;%全局最好的青蛙
%  fit=[fit Xg.fitness] 
        
 
       testG=Xg;
 

       for k=1:le
          for ff=1: q
                if   testG.fitness>frog(ff).fitness
                        testG=frog(ff);
                end
          end
        
              fit=[fit testG.fitness] 
           fit2(tdy le*(v-1)+k)=Xg.fitness; 
      for i=1:m
%             for k=1:le
                    Xw= frog(i);
                    w=i;
                     Xb= frog(i);
                     b=i;
           
                    for tt=2:n
                         if  frog(i+m*(tt-1)).fitness                             Xb=frog(i+m*(tt-1));
                             b=i+m*(tt-1);
                         end
                         if  frog(i+m*(tt-1)).fitness>Xw.fitness
                            Xw=frog(i+m*(tt-1));
                            w=i+m*(tt-1);%结构体数组的索引号
                         end

                    end
                    Xw;
                    Xb;
        
                         Xnew=Xw;
             
                          for x=1:size(Xb.center2)
                             Xnew.center(x )=Xw.center(x )+c*rand.*(Xb.center(x)-Xw.center(x));
                             if Xnew.center(x)                               Xnew.center(x)=Dmin;
                             end
                     

评论

共有 条评论