请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册
查看: 4200|回复: 0

遗传算法GA优化的PID参数整定

[复制链接]

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
发表于 2017-3-5 16:43:39 | 显示全部楼层 |阅读模式
参考链接:
人群搜索算法SOA优化的PID参数整定:
http://halcom.cn/forum.php?mod=v ... age=1&extra=#pid664
程序如下:

  1. %GA Program tooptimize PID Parameters
  2. clear all;
  3. close all;
  4. size=30;
  5. codel=3;
  6. minx(1)=zeros(1);
  7. maxx(1)=100*ones(1);
  8. minx(2)=zeros(1);
  9. maxx(2)=100*ones(1);
  10. minx(3)=zeros(1);
  11. maxx(3)=0*ones(1);
  12. kpid(:,1)=minx(1)+(maxx(1)-minx(1))*rand(size,1);
  13. kpid(:,2)=minx(2)+(maxx(2)-minx(2))*rand(size,1);
  14. kpid(:,3)=minx(3)+(maxx(3)-minx(3))*rand(size,1);
  15. G=100;
  16. BsJ=0;
  17. for kg=1:1:G
  18.     time(kg)=kg;
  19. for i=1:1:size
  20.     kpidi=kpid(i,:);
  21.     BsJ=pid_GA(kpidi);
  22. BsJi(i)=BsJ;
  23. end
  24. [OderJi,IndexJi]=sort(BsJi);
  25. BestJ(kg)=OderJi(1);
  26. BJ=BestJ(kg);
  27. Ji=BsJi+1e-10;
  28. fi=1./Ji;
  29. [Oderfi,Indexfi]=sort(fi);
  30. Bestfi=Oderfi(size);
  31. BestS=kpid(Indexfi(size),:);
  32. % select and reproduct operation
  33. fi_sum=sum(fi);
  34. fi_size=(Oderfi/fi_sum)*size;
  35. fi_s=floor(fi_size);
  36. r=size-sum(fi_s);
  37. Rest=fi_size-fi_s;
  38. [Restvalue,Index]=sort(Rest);
  39. for i=size:-1:size-r+1
  40.     fi_s(Index(i))=fi_s(Index(i))+1;
  41. end
  42. k=1;
  43. for i=size:-1:1
  44.     for j=1:1:fi_s(i)
  45.     TempE(k,:)=kpid(Indexfi(i),:);
  46.     k=k+1;
  47.     end
  48. end
  49. % crossover operation
  50. Pc=0.90;
  51. for i=1:2:(size-1)
  52.     temp=rand;
  53.     if Pc>temp
  54.         alfa=rand;
  55.         TempE(i,:)=alfa*kpid(i+1,:)+(1-alfa)*kpid(i,:);
  56.         TempE(i+1,:)=alfa*kpid(i,:)+(1-alfa)*kpid(i+1,:);
  57.     end
  58. end
  59. TempE(size,:)=BestS;
  60. kpid=TempE;
  61. %Mution operation
  62. Pm=0.1-[1:1:size]*(0.01)/size;
  63. Pm_rand=rand(size,codel);
  64. Mean=(maxx+minx)/2;
  65. Dif=(maxx-minx);
  66. for i=1:1:size
  67.     for j=1:1:codel
  68.         if Pm(i)>Pm_rand(i,j)
  69.             TempE(i,j)=Mean(j)+Dif(j)*(rand-0.5);
  70.         end
  71.     end
  72. end
  73. %guarantee TempE(size,:)belong tu the best individual
  74. TempE(size,:)=BestS;
  75. kpid=TempE;
  76. end
  77. Bestfi;
  78. BestS;
  79. Best_J=BestJ(G);
  80. figure(1);
  81. plot(time,BestJ,'LineWidth',3);
  82. title('最优个体适应值','fontsize',10);
  83. xlabel('迭代次数');ylabel('适应值');
  84. grid on
复制代码



算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-3-29 03:31 , Processed in 0.211287 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表