⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fipso.m

📁 Matlab code for Fullyinformed PSO
💻 M
字号:
function out=fipso(functchc,D,Maxgen,epochtime,Rmax,Rmin,Stop_criteria)
%Fully Informed PSO 
global initial_flag EpochtimeArr tr FE_success_runs success_runs M O
global result_type
% Parameter Settings
NP=25;Xmax(1:D)=Rmax;Xmin(1:D)=Rmin;
Vmax = 0.25*(Xmax - Xmin);
%------------------------------
 C1=2.05;C2=2.05; phi=C1+C2;
 K=2./(abs(2-phi-sqrt(phi.^2-4*phi)));
%---------- Initialization of swarm -------------
for count_p = 1:NP
    for count_d= 1:D
        X(count_p,count_d) = rand;
        V(count_p,count_d) = rand;
        p_best(count_p,count_d) = X(count_p,count_d);
    end
end
%------------------------------
%-------------Evaluate fitness value  gbest of all particles
for count_p = 1:NP
            for count_d= 1:D
               xy(count_d)=X(count_p,count_d);
            end
        current_fitness(count_p)=BENCH_FUNCS(xy,functchc);
end 
                      
    [g_best_val,g_best_index] = min(current_fitness);
    for count_d = 1:D
      g_best(count_d) = X(g_best_index,count_d);
    end
    
    for count_p = 1:NP
        W(count_p)=norm(g_best-p_best(count_p));
        phi(count_p)=Rmin+rand*(Rmax-Rmin);
    end
    
    % Calucalation of Pm
    num=0;
    den=0; 
  for count_p = 1:NP
      num=num+W(count_p)*phi(count_p)*p_best(count_p);
      den=den+W(count_p)*phi(count_p);
  end
  Pm=num./den;
  %-----------------------  

    
%-----------------------------------------------
if epochtime ==1
    tic;
end
%-------- Main routine starts ---------------
for count_g = 1:Maxgen
% ----------  Velocity and Possition Updation ---------------------------
           for count_p = 1:NP
                   for count_d= 1:D 
  V(count_p,count_d)=K*(V(count_p,count_d)+phi(count_p)*(Pm-X(count_p,count_d)));
 V(count_p,count_d)=min(Vmax(count_d),max(-Vmax(count_d),V(count_p,count_d)));
                    X(count_p,count_d)=X(count_p,count_d)+V(count_p,count_d);
                  end
           end  
             
%------------------------------------------------------------------------
             
 % -------- Computing f(xi) ---------
    for count_p = 1:NP   
          if( X(count_p,:) > Xmin & X(count_p,:) < Xmax)
                for count_d= 1:D
                     xy(count_d)=X(count_p,count_d);
                end
              current_fitness(count_p)=BENCH_FUNCS(xy,functchc);
          else
              for count_d= 1:D
                  X(count_p,count_d)=rand;
              end
          end
    end   
% -------- updating pbest---------    
    for count_p = 1:NP
        for count_d= 1:D
          xy(count_d)=p_best(count_p,count_d);
        end
       p_best_fitness(count_p)=BENCH_FUNCS(xy,functchc);        
        
            if current_fitness(count_p)< p_best_fitness(count_p)
                     p_best_fitness(count_p) = current_fitness(count_p);
                        for count_d = 1:D
                            p_best(count_p,count_d) = X(count_p,count_d);
                        end
           end
    end
%-----------------------------
%--------- Updating gbest------------
      for count_d= 1:D
          xy(count_d)=g_best(count_d);
      end
       g_best_fitness(count_g)=BENCH_FUNCS(xy,functchc);        
 
       [g_best_val,g_best_index] = min(p_best_fitness);
       if g_best_val < g_best_fitness(count_g)
           g_best_fitness(count_g)=g_best_val;
           for count_d = 1:D
                   g_best(count_d) = p_best(g_best_index,count_d);
           end        
       end
%---------------------------------------        

 % Calucalation of Pm
    for count_p = 1:NP
        W(count_p)=norm(g_best-p_best(count_p));
    end
    
    num=0;
    den=0;
  for count_p = 1:NP
      num=num+W(count_p)*rand*p_best(count_p);
      den=den+W(count_p)*rand;
  end
  Pm=num./den;
  %-----------------------    
% -------- Stop criteria ---------
             if g_best_fitness(count_g) <Stop_criteria   
             disp('Stop criteria');
             success_runs= success_runs+1;
             FE_success_runs(success_runs)=g_best_fitness(count_g);
                break
             end
           %---------------------------------               
end
if epochtime ==1
    EpochtimeArr(tr)=toc;
end

for n=count_g:Maxgen
    g_best_fitness(n)=g_best_fitness(count_g);
end


Value=g_best;
        if result_type==1
            out=g_best_fitness;
            FitnessFIPSO=g_best_fitness(Maxgen)
        else
            out=g_best_fitness(Maxgen);  
        end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -