123代码测试

function [fMin , bestX, Convergence_curve ] = DBO(pop, M,c,d,dim,fobj  )
        
    P_percent = 0.2;   
    pNum = round( pop *  P_percent );    

    lb= c.*ones(1,dim);      
    ub= d.*ones(1,dim);        

    fMin=inf;
    while fMin==inf
        for i = 1 : pop
            x( i, : ) = lb + (ub - lb) .* rand( 1, dim );
            fit( i ) = fobj( x( i, : ) ) ;
            if fit( i )<fMin
                fMin=fit( i );
            end
        end
    end

    pFit = fit;
    pX = x;
    XX=pX;
    [fMin, bestI] = min(fit);        
    bestX = x(bestI,:);              

for t = 1 : M    
    [fmax,B]=max(fit);  
    worse= x(B,:);
    r2=rand(1);

    for i = 1 : pNum
      if(r2<0.9)
          r1=rand(1);
          a=rand(1,1);
          if (a>0.1)
              a=1;
          else
              a=-1;
          end
          x(i,:) = pX(i,:)+0.3*abs(pX(i,:)-worse)+a*0.1*(XX(i,:));   
      else
          angle= randperm(180,1);
          if (angle==0 ||angle==90 ||angle==180)
              x(i,:) = pX(i,:);
          end
          theta= angle*pi/180;
          x(i,:) = pX(i,:)+tan(theta).*abs(pX(i,:)-XX(i ,:));   
      end
      x(i,:) = Bounds(x(i,:),lb,ub);
      fit(i) = fobj(x(i,:));
    end
    
    
    [fMMin, bestII] = min(fit);        
    bestXX = x( bestII,:);           
  
    R=1-t/M;
    
    Xnew1 = bestXX.*(1-R);
    Xnew2 = bestXX.*(1+R);                       
    Xnew1 = Bounds(Xnew1,lb,ub);
    Xnew2 = Bounds(Xnew2,lb,ub);

    Xnew11 = bestX.*(1-R);
    Xnew22 = bestX.*(1+R);                      
    Xnew11 = Bounds(Xnew11,lb,ub);
    Xnew22 = Bounds(Xnew22,lb,ub);


    for i = ( pNum + 1 ) :12              % Equation (4) 繁殖
      x( i, : )=bestXX+((rand(1,dim)).*(pX( i , : )-Xnew1)+(rand(1,dim)).*(pX( i , : )-Xnew2));
      x(i, : ) = Bounds( x(i, : ), Xnew1, Xnew2 );
      fit(i ) = fobj(  x(i,:) ) ;
    end


    for i = 13: 19                
      x( i, : )=pX( i , : )+((randn(1)).*(pX( i , : )-Xnew11)+((rand(1,dim)).*(pX( i , : )-Xnew22)));
      x(i, : ) = Bounds( x(i, : ),lb, ub);
      fit(i ) = fobj(  x(i,:) ) ;
    end

    for j = 20 : pop                 
      x( j,: )=bestX+randn(1,dim).*((abs(( pX(j,:  )-bestXX)))+(abs(( pX(j,:  )-bestX))))./2;
      x(j, : ) = Bounds( x(j, : ), lb, ub );
      fit(j ) = fobj(  x(j,:) ) ;
    end

     XX=pX;
    for i = 1 : pop 
        if ( fit( i ) < pFit( i ) )
            pFit( i ) = fit( i );
            pX( i, : ) = x( i, : );
        end
        
        if( pFit( i ) < fMin )

           fMin= pFit( i );
            bestX = pX( i, : ); 
        end
    end
      Convergence_curve(t)=fMin;
      disp(['DBO Iter:',num2str(t),' Fit:',num2str(fMin)]);
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jawy丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值