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

📄 simturb1.m

📁 本程序利用遗传算法实现PID参数的优化问题.
💻 M
字号:
%clear all;
%close all;
global Td Tn bt;
%genatic program
G=100;%
size=30;
CodeL=10;
BSVi=zeros(size,1);
BestSatV=zeros(G,1);
%range of Tn
Minx(1)=zeros(1);
Maxx(1)=5.0*ones(1);
%range of bt
Minx(2)=zeros(1);
Maxx(2)=5.0*ones(1);
%range of Td
Minx(3)=zeros(1);
Maxx(3)=5.0*ones(1);
%************
E=round(rand(size,3*CodeL));
totals=0;
for kg=1:1:G
    time(kg)=kg;%time 
    for s=1:1:size%size begin
        m=E(s,:);%
        y1=0;
        y2=0;
        y3=0;
 m1=m(1:1:CodeL);
 for i=1:1:CodeL
     y1=y1+m1(i)*2^(i-1);
 end
 pidpara(s,1)=(Maxx(1)-Minx(1))*y1/1023+Minx(1);%Tn,30 values
 m2=m(CodeL+1:1:2*CodeL);
 for i=1:1:CodeL
     y2=y2+m2(i)*2^(i-1);
 end
 pidpara(s,2)=(Maxx(2)-Minx(2))*y2/1023+Minx(2);%bt,30 values
 m3=m(2*CodeL+1:1:3*CodeL);
 for i=1:1:CodeL
     y3=y3+m3(i)*2^(i-1);
 end
 pidpara(s,3)=(Maxx(3)-Minx(3))*y3/1023+Minx(3);%Td,30 values
 
 %*************************step1:Evaluate besats**************************
 pidparai=pidpara(s,:);
 [pidparai,totals]=sub_simturb1(pidparai,totals);%call sub_programe
 BSVi(s)=totals;
    end %size-end
  [OderJi,IndexJi]=sort(BSVi,'descend');%arranegd total satisfaction degree value in descendent way.
  BestSatV(kg)=OderJi(1);%get the largest value of total satisfaction degree
  BS=BestSatV(kg);
  Si=BSVi;  
  fi=Si;
  [Oderfi,Indexfi]=sort(fi,'descend');
  Bestfi=Oderfi(1);%????????
  BestS=E(Indexfi(1),:);%?????????
  
 % BS1.329423264907136

 % BestS
  %****************step2:Select and Reproduct Operation*******************
  fi_sum=sum(fi);
  fi_size=(Oderfi/fi_sum)*size;
  fi_S=floor(fi_size);
  
  kk=1;
  for i=1:1:size
      for j=1:1:fi_S(i)
          TempE(kk,:)=E(Indexfi(i),:);
          kk=kk+1;
      end
  end
  %****************step3:Crossover Operation****************************
  pc=0.80;
  n=ceil(20*rand);
  for i=1:2:(size-1)
      temp=rand;
      if pc>temp
          for j=n:1:20
              TempE(i,j)=E(i+1,j);
              TempE(i+1,j)=E(i,j);
          end
      end
  end
  TempE(size,:)=BestS;
  E=TempE;
  %************************step4:Mutation Operation********************
  pm=0.002-1:1:size*(0.002)/size;
  for i=1:1:size
      for j=1:1:3*CodeL
          temp=rand;
          if pm>temp
              if TempE(i,j)==0
                  TempE(i,j)=1;
              else
                  TempE(i,j)=0;
              end
          end
      end
  end
  Temp(size,:)=BestS;
  E=TempE;
  %******************************************************************
  kg
  totals
  
  
 %if (kg-10)==0
     
     %break;
 %end
  
end
Bestfi
BestS
totals
%Best_sat=BestSatV(G);
%figure;
%plot(time,BestSatV);
%xlable('times');
%ylable('Best_sat');
%figure(2);
%plot
%


  
%

⌨️ 快捷键说明

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