カメレオン アルゴリズムに基づいて線形計画問題を解くための Matlab プログラム

カメレオン アルゴリズムに基づいて線形計画問題を解く Matlab プログラム
1 カメレオン アルゴリズム

カメレオンは爬虫類であり、樹上生活に適した特徴と行動を備えた非常に特異な動物です。回避者の体長は約15〜25cmで、体の側面は平らで、背中に棘があり、後頭部には鈍い三角形の突起があります。四肢は非常に長く、指と足指は 2 つの対向するグループに分かれており、前肢の最初の 3 本の指が内側のグループを形成し、第 4 と第 5 の指が外側のグループを形成し、後肢の第 1 指と第 2 指が外側のグループを形成します。内側のグループを形成し、外側のグループは独特の 3 本の指で形成され、枝を保持するのに適しています。尾は長く、枝に巻きつくことができます。体長を超えて突き出た非常に長く敏感な舌を持ち、舌の先端には昆虫に付着する粘液を大量に分泌する腺があります。非常に特異な眼を持ち、厚いまぶたに輪状に突き出た眼球があり、左右180度自由に動き、左右の目は協調することなく独立して動きます。この現象は動物ではまれです。2 つの目は仕事を分担して前方と後方を監視します。これは捕食に役立つだけでなく、遅れている敵を発見することもできます。カメレオンは長い舌を使って獲物を素早く狩ります。所要時間はわずか 1/25 秒で、舌の長さは体の 2 倍です。木の上を歩いたり止まったりする動作は、天敵に風に吹かれて落ちてきた木の葉と間違えてしまいます。
カメレオン アルゴリズム (CSA) は、餌の検索、餌の追跡のための 360 度の目の回転、獲物の位置を特定して捕獲するための自分の舌の使用など、カメレオンの狩猟行動のステップを数学的にシミュレートおよび実現するバイオニック アルゴリズムです。カメレオン アルゴリズムは実際の問題にうまく使用でき、優れたパフォーマンスを達成できます。SAIDらはCSAを用いて経済的負荷配分問題を最適化し、他のアルゴリズムと比較したところ、シミュレーションの結果、CSAの方が優れた計算結果を示した。RIZKらは、SOFCモデルの信頼性が高く正確なパラメータを抽出するために改良されたカメレオングループアルゴリズムを設計した。CSA は強力なコンピューティング能力とさまざまな問題への適応力を備えています。
ここに画像の説明を挿入

2 算例
ここに画像の説明を挿入

3 プログラムソリューションの結果
ここに画像の説明を挿入

4 プログラム
1) メインプログラム

%% 基于变色龙算法的线性规划问题求解

   
clear 
close all
clc
%% % Prepare the problem
dim = 3;
ub = 15*ones(1, dim);
lb = 0*ones(1, dim);
fobj = @Objfun;

%% % CSA parameters 
noP = 500;
maxIter = 50;
[bestFitness, bestPosition, CSAConvCurve] =Chameleon(noP,maxIter,lb,ub,dim,fobj);
disp(['最优解为:', num2str(bestFitness)]);
disp(['最优变量为:', num2str(bestPosition)]);

2) サブルーチン


%% Chameleon Swarm Algorithm (CSA) source codes version 1.0
%
%  Developed in MATLAB R2018a
%
%  Author and programmer: Malik Braik
%
%         e-Mail: [email protected]
%                 [email protected]
%

%   Main paper:
%   Malik Sh. Braik,
%   Chameleon Swarm Algorithm: A Bio-inspired Optimizer for Solving Engineering Design Problems
%   Expert Systems with Applications
%   DOI: https://doi.org/10.1016/j.eswa.2021.114685
%____________________________________________________________________________________

function [fmin0,gPosition,cg_curve]=Chameleon(searchAgents,iteMax,lb,ub,dim,fobj)

%%%%* 1
if size(ub,2)==1
    ub=ones(1,dim)*ub;
    lb=ones(1,dim)*lb;
end
 
% if size(ub,1)==1
%     ub=ones(dim,1)*ub;
%     lb=ones(dim,1)*lb;
% end

%% Convergence curve
cg_curve=zeros(1,iteMax);
% 
% f1 =  figure (1);
% set(gcf,'color','w');
% hold on
% xlabel('Iteration','interpreter','latex','FontName','Times','fontsize',10)
% ylabel('fitness value','interpreter','latex','FontName','Times','fontsize',10); 
% grid;

%% Initial population

chameleonPositions=initialization(searchAgents,dim,ub,lb);% Generation of initial solutions 

%% Evaluate the fitness of the initial population

fit=zeros(searchAgents,1);


for i=1:searchAgents
     fit(i,1)=fobj(chameleonPositions(i,:));
end

%% Initalize the parameters of CSA
fitness=fit; % Initial fitness of the random positions
 
[fmin0,index]=min(fit);

chameleonBestPosition = chameleonPositions; % Best position initialization
gPosition = chameleonPositions(index,:); % initial global position

v=0.1*chameleonBestPosition;% initial velocity
 
v0=0.0*v;

%% Start CSA 
% Main parameters of CSA
rho=1.0;
p1=2.0;  
p2=2.0;  
c1=2.0; 
c2=1.80;  
gamma=2.0; 
alpha = 4.0;  
beta=3.0; 
 

 %% Start CSA
for t=1:iteMax
a = 2590*(1-exp(-log(t))); 
omega=(1-(t/iteMax))^(rho*sqrt(t/iteMax)) ; 
p1 = 2* exp(-2*(t/iteMax)^2);  % 
p2 = 2/(1+exp((-t+iteMax/2)/100)) ;
        
mu= gamma*exp(-(alpha*t/iteMax)^beta) ;

ch=ceil(searchAgents*rand(1,searchAgents));
%% Update the position of CSA (Exploration)
for i=1:searchAgents  
             if rand>=0.1
                  chameleonPositions(i,:)= chameleonPositions(i,:)+ p1*(chameleonBestPosition(ch(i),:)-chameleonPositions(i,:))*rand()+... 
                     + p2*(gPosition -chameleonPositions(i,:))*rand();
             else 
                 for j=1:dim
                   chameleonPositions(i,j)=   gPosition(j)+mu*((ub(j)-lb(j))*rand+lb(j))*sign(rand-0.50) ;
                 end 
              end   
end       
 %% Rotation of the chameleons - Update the position of CSA (Exploitation)

%%% Rotation 180 degrees in both direction or 180 in each direction
%  

% [chameleonPositions] = rotation(chameleonPositions, searchAgents, dim);
 
 %%  % Chameleon velocity updates and find a food source
     for i=1:searchAgents
               
        v(i,:)= omega*v(i,:)+ p1*(chameleonBestPosition(i,:)-chameleonPositions(i,:))*rand +.... 
               + p2*(gPosition-chameleonPositions(i,:))*rand;        

         chameleonPositions(i,:)=chameleonPositions(i,:)+(v(i,:).^2 - v0(i,:).^2)/(2*a);
     end
    
  v0=v;
  
 %% handling boundary violations
 for i=1:searchAgents
     if chameleonPositions(i,:)<lb
        chameleonPositions(i,:)=lb;
     elseif chameleonPositions(i,:)>ub
            chameleonPositions(i,:)=ub;
     end
 end
 
 %% Relocation of chameleon positions (Randomization) 
for i=1:searchAgents
    
    ub_=sign(chameleonPositions(i,:)-ub)>0;   
    lb_=sign(chameleonPositions(i,:)-lb)<0;
       
    chameleonPositions(i,:)=(chameleonPositions(i,:).*(~xor(lb_,ub_)))+ub.*ub_+lb.*lb_;  %%%%%*2
 
  fit(i,1)=fobj (chameleonPositions(i,:)) ;
      
      if fit(i)<fitness(i)
                 chameleonBestPosition(i,:) = chameleonPositions(i,:); % Update the best positions  
                 fitness(i)=fit(i); % Update the fitness
      end
 end


%% Evaluate the new positions

[fmin,index]=min(fitness); % finding out the best positions  


% Updating gPosition and best fitness
if fmin < fmin0
    gPosition = chameleonBestPosition(index,:); % Update the global best positions
    fmin0 = fmin;
end

%% Print the results
%   outmsg = ['Iteration# ', num2str(t) , '  Fitness= ' , num2str(fmin0)];
%   disp(outmsg);

%% Visualize the results

   cg_curve(t)=fmin0; % Best found value until iteration t

%     if t>2
%      set(0, 'CurrentFigure', f1)
% 
%         line([t-1 t], [cg_curve(t-1) cg_curve(t)],'Color','b'); 
%         title({'Convergence characteristic curve'},'interpreter','latex','FontName','Times','fontsize',12);
%         xlabel('Iteration');
%         ylabel('Best score obtained so far');
%         drawnow 
%     end 
end
 
ngPosition=find(fitness== min(fitness)); 
g_best=chameleonBestPosition(ngPosition(1),:);  % Solutin of the problem
fmin0 =fobj(g_best);

end

少し

おすすめ

転載: blog.csdn.net/weixin_47365903/article/details/128483669