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

📄 ant3_10_gaaa.asv

📁 基于GAACA的协同多目标攻击空战决策算法
💻 ASV
字号:
% 多目标攻击空战决策的蚁群算法实现
% 假设一个武器不能同时迎击两个或两个以上目标
% 一个目标最多可以分配2个武器
% 我方有3架飞机(红机),每架飞机携带4枚导弹,攻击10个目标(蓝机)
function cost_min_2=ant3_10_GAAA(pop_choose)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                % 参数设置 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tic
M1 = 4;  
M2 = 4;
M3 = 4;
M4 = 0;                       % 我方各载机所携带的武器数

total_W = M1+M2+M3+M4;        % 总的武器数12
total_T = 10;                 % 总的目标数

 
PP = [0.10  0.05  0.36  0.73  0.21  0.70  0.02  0.85  0.90  0.10  0.08  0.50 ;
      0.56  0.56  0.75  0.31  0.38  0.06  0.33  0.32  0.95  0.37  0.50  0.87;
      0.80  0.25  0.21  0.67  0.40  0.20  0.12  0.50  0.45  0.60  0.30  0.60;
      0.40  0.17  0.10  0.52  0.23  0.80  0.75  0.73  0.50  0.80  0.08  0.10;
      0.32  0.20  0.43  0.26  0.45  0.15  0.62  0.85  0.95  0.01  0.90  0.70;
      0.20  0.10  0.82  0.32  0.30  0.40  0.03  0.34  0.26  0.69  0.70  0.87;
      0.96  0.58  0.75  0.80  0.01  0.63  0.27  0.10  0.72  0.23  0.01  0.07;
      0.40  0.67  0.50  0.91  0.34  0.54  0.90  0.22  0.65  0.23  0.90  0.92;
      0.03  0.42  0.15  0.32  0.40  0.30  0.74  0.58  0.85  0.90  0.30  0.55;
      0.15  0.75  0.62  0.45  0.56  0.80  0.61  0.76  0.10  0.06  0.35  0.50];     % 迎击武器单一命中概率,行为目标,列为武器
  
TH = [0.20  0.40  0.62  0.35  0.40  0.20  0.70  0.10  0.20  0.03 ;
      0.30  0.38  0.20  0.30  0.20  0.10  0.25  0.10  0.30  0.10 ;
      0.40  0.45  0.20  0.28  0.20  0.10  0.30  0.48  0.15  0.32 ];   % 目标对飞机的威胁评估因子,行为飞机,列为目标
      
TH_Z  = zeros(1,total_T);
for i = 1:total_T
    for j = 1:3
        TH_Z(i) = TH_Z(i)+TH(j,i);
    end
end                                    % 求每个目标对我机群的总威胁,即TH每列求和

mb_px = mbpx(TH_Z,total_T);          % 对目标进行排序,按照其对我机群的威胁从大到小,输出为敌机序号

  
alpha = 1;        % 反映蚂蚁在运动过程中所积累的信息
beta = 2;         % 反映启发信息在蚂蚁选择路径时的相对重要性
Q = 150;           % 比例系数
R = 1;           % 正整数,反映武器i选择目标j的权重大小
ru = 0.92;        % 信息浓度挥发系数
kx = 0.1;

nc_max = 100;    % 最大迭代次数
MM = 10;           % 蚂蚁数m                                     

delta_tao_min = 0.0001;
delta_tao_max = 1000;

%result = zeros(nc_max,(1+2*total_W));
%T = zeros(1,nc_max);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       % 初始化  t,nc,tao,delta_tao %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C0 = 0.96;           % 初始信息素, PP矩阵中的最大元素
t = 0;               
nc = 0;              % 迭代次数

tao = C0*ones(total_W,total_T);          %导弹到目标初始信息素矩阵
delta_tao = zeros(total_W,total_T);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                %蚁群结束条件 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
minant=15;              %最小迭代次数
ant_min_tatio=0.05;     %子群体最小进化率
ant_die=5;              %子群体进化率小于最小进化率的可容忍进化代数
tt=0;                    %子群体进化率小于最小进化率的当前代数

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
             %  蚁群算法实现 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while (nc<nc_max)
    
    tabuw = zeros(MM,total_W);         % 武器禁忌表
    tabut = zeros(MM,total_W);         % 目标禁忌表
    
    cost = zeros(1,MM);                % 记录每只蚂蚁的目标函数值
    
    for mayi = 1:MM
        
        weapon = [1:total_W];          % 武器列表
        target = [1:total_T,mb_px(1:(total_W-total_T))];          % 目标列表;每机一个多余导弹加分给威胁最大的目标
        
        w_num = total_W;     % 总的迎击武器数
        t_num = total_W;     % 目标数
        
        %count = 2*ones(1,total_T);
        
        %*******************************%
            %%% 武器的选择 %%% 
        %*******************************%
        for i = 1:total_W
            m = rand_function(1,w_num);                    % 产生一个1-w_num之间的随机数,表示一个蚂蚁的起点武器节点
            tabuw(mayi,i) = weapon(m);                     % 将第m个武器放入武器禁忌表中
            weapon = [weapon(1:m-1),weapon(m+1:w_num)];    % 将武器列表中的第m个武器排除
            w_num = w_num-1;                               % 武器个数减去1
            
            %********************************%
                 %%% 武器到目标的选择 %%%
            %********************************%
                        
               fenmu = 0;        %分母
                for j = 1:t_num
                    eta = eta_function(M1,M2,M3,M4,PP,target(j),tabuw(mayi,i),TH_Z,R);          
                    fenmu = fenmu+((tao(tabuw(mayi,i),target(j)))^alpha)*((eta)^beta);
                end
   
                pro = 0;
                r = rand(1);
                for j = 1:t_num
                    eta = eta_function(M1,M2,M3,M4,PP,target(j),tabuw(mayi,i),TH_Z,R);           
                    fenzi = ((tao(tabuw(mayi,i),target(j)))^alpha)*((eta)^beta);
                    pro = pro+double(fenzi)/double(fenmu);  % 每条路径的转移概率
                    if r<=pro                            % 选取概率大于随机数r的路径                                  
                        tabut(mayi,i) = target(j);       % 将被选目标放入目标禁忌表中
                        n = j;
                        break;
                    end
                end
                    
                
                   target = [target(1:n-1),target(n+1:t_num)];
                   t_num = t_num-1; 
          end
        
          
        %%%%%%%%%%%% 计算每只蚂蚁的失败威胁概率和  %%%%%%%%%%%%%%
         for kk = 1:total_W              
            cost(mayi) = cost(mayi)+TH_Z(tabut(mayi,kk))*(1-PP(tabut(mayi,kk),tabuw(mayi,kk))); %每个目标分一个导弹
         end 
         
         for i = 1:total_W-1                 
             for j = i+1:total_W
                 if tabut(mayi,i)==tabut(mayi,j)       %当有一个目标分配两个导弹时
                     cost(mayi) = cost(mayi)-TH_Z(tabut(mayi,i))*(1-PP(tabut(mayi,i),tabuw(mayi,i)))-TH_Z(tabut(mayi,j))*(1-PP(tabut(mayi,j),tabuw(mayi,j)))...
                                  +TH_Z(tabut(mayi,i))*(1-PP(tabut(mayi,i),tabuw(mayi,i)))*(1-PP(tabut(mayi,j),tabuw(mayi,j)));
                 end
             end
          end
                  
                  for i = 1:total_W
                  %tao(tabuw(mayi,i),tabut(mayi,i)) = (1-kx)*tao(tabuw(mayi,i),tabut(mayi,i))+kx*(1/(MM*cost(mayi)));  % 局部更新规则
                  tao(tabuw(mayi,i),tabut(mayi,i)) = (1-kx)*tao(tabuw(mayi,i),tabut(mayi,i))+kx*C0;  % 局部更新规则
                  end
                  
        
    end  % 蚂蚁循环结束
    
    
    %%%%%%%% 比较MM只蚂蚁的失败概率和,并找出失败概率和最小的分配  %%%%%%%%%%%
    cost_min = cost(1);
    mayi_min = 1;
    for mm = 1:MM
        if cost(mm)<cost_min
            cost_min = cost(mm);
            mayi_min = mm;
        end
    end                                      
    
    result(nc+1,:) = [cost_min,tabuw(mayi_min,:),tabut(mayi_min,:)];    % 保存最好的结果
    T(nc+1) = t;
      
    %结束的条件判断 
   if nc>minant
       if (tt<=ant_die)&((result(nc,1)-result(nc+1,1))<ant_min_tatio*result(nc,1))
          tt=tt+1;
       end
   end
  
   if tt>ant_die
       break;
   end
    
    %***************************************%
      %%% 对t,nc,tao,delta_tao重新赋值 %%%
    %***************************************%
    %for i = 1:total_W
        %for j = 1:total_T
            %if delta_tao(i,j)<delta_tao_min
                %delta_tao(i,j) = delta_tao_min;
                % elseif delta_tao(i,j)>delta_tao_max
                %delta_tao(i,j) = delta_tao_max;
                %end
                %end
                %end
    %tao = ru*tao+(1-ru)*delta_tao;
    %tao = ru*tao+delta_tao;
    for i = 1:total_W
        tao(tabuw(mayi_min,i),tabut(mayi_min,i)) = ru*tao(tabuw(mayi_min,i),tabut(mayi_min,i))+Q/cost_min;
    end
    
    t = t+1;
    nc = nc+1;
    delta_tao = zeros(total_W,total_T);  
  
   
end    % 整个大循结束

%%%%%  输出最优分配  %%%%%
 time1=toc   %测CPU时间   
 nc
final_result = result(nc,:)
cost_min_2= result(:,1)';      

save parameter time2 nc 
% plot(T,result(:,1));

⌨️ 快捷键说明

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