mainclone.m

来自「遗传算法用于函数优化问题」· M 代码 · 共 34 行

M
34
字号
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      %
      %Q-C-A(Quantum Clone Algorithms)
      %
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      clear;
      q=(sqrt(1/2)).*ones(10,22); 
      v = 2*rand(50,22)-1;
      v=hardlim(v);
      v(1,:)=ones(1,22);
      disp(sprintf('** Please select the algorithm **'));
      disp(sprintf('1-SGA'));
      disp(sprintf('2-Clone-GA'));
      disp(sprintf('3-KClone-GA'));
      disp(sprintf('4-Self Adaptive Chaos Quantum Algorithm'));
      pp = input('Type the desired  number (or CTRL^C to Interrupt): ');
      
      numfunction = input('Type the desired function number (or CTRL^C to Interrupt): ');
      
      switch pp
      case 1
          [X,Y,x,y,fx,vx,vmfit,P] = genetic(numfunction,v);
      case 2
         [X,Y,x,y,fx,vx,vmfit,P] = clone(numfunction,q);
      case 3
         [X,Y,x,y,fx,vx,vmfit,P] = clone1(numfunction,q);
     case 4
         [X,x,fx,vx,vmfit,P] = selfc(numfunction);
      end
      disp(sprintf('Maximum found [f(x,y)]: [%.2f]',fx));
%       xx=vx;yy=vmfit;
      figure(2); plot(vx,'k'); 
      title('f(x,y) x Mean'); xlabel('Generations'); ylabel('f(x,y)');
      hold on; plot(vmfit,'k:'); legend('best','mean',0);hold off;

⌨️ 快捷键说明

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