Browse Source

Update main.m

master
TianZhendong 5 years ago
committed by GitHub
parent
commit
7627d5d6b1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      GA_PID/main.m

20
GA_PID/main.m

@ -5,8 +5,8 @@ close all;
%% 参数设置 %% 参数设置
ChromosomeSize = 1; %染色体个数 ChromosomeSize = 1; %染色体个数
ChromosomeLen=17; %染色体长度 由最大值决定 ChromosomeLen=17; %染色体长度 由最大值决定
PopulationSize = 200; %种群规模 PopulationSize = 100; %种群规模
MaxIter = 200; %最大迭代次数 MaxIter = 50; %最大迭代次数
% MinFitness=0.01; %最小适应值 % MinFitness=0.01; %最小适应值
CrossRate=0.6; %交叉概率 CrossRate=0.6; %交叉概率
MutateRate=0.1; %变异概率 MutateRate=0.1; %变异概率
@ -98,19 +98,19 @@ for Iter=1:MaxIter
PopulationNew2(i,:)=mutation(ChromosomeLen,MutateRate,PopulationNew2(i,:)); PopulationNew2(i,:)=mutation(ChromosomeLen,MutateRate,PopulationNew2(i,:));
PopulationNew3(i,:)=mutation(ChromosomeLen,MutateRate,PopulationNew3(i,:)); PopulationNew3(i,:)=mutation(ChromosomeLen,MutateRate,PopulationNew3(i,:));
end end
parfor i=1:PopulationSize for i=1:PopulationSize
Population1(i,:)=PopulationNew1(i,:); Population1(i,:)=PopulationNew1(i,:);
Population2(i,:)=PopulationNew2(i,:); Population2(i,:)=PopulationNew2(i,:);
Population3(i,:)=PopulationNew3(i,:); Population3(i,:)=PopulationNew3(i,:);
end end
K_p(1,Iter)=Elite1(Iter,1); K_p(Iter,1)=Elite1(Iter,1);
K_i(1,Iter)=Elite2(Iter,1); K_i(Iter,1)=Elite2(Iter,1);
K_d(1,Iter)=Elite3(Iter,1); K_d(Iter,1)=Elite3(Iter,1);
end end
figure(1) figure(1)
plot(BestFitness,'LineWidth',2); plot(BestFitness,'LineWidth',2);
title('个体适应值','fontsize',18); title('个体适应值','fontsize',18);
xlabel('迭代次数');ylabel('适应值'); xlabel('迭代次数');ylabel('适应值');
figure(2) figure(2)
plot(K_p) plot(K_p)
@ -118,3 +118,9 @@ hold on
plot(K_i,'k','LineWidth',3) plot(K_i,'k','LineWidth',3)
plot(K_d,'--r') plot(K_d,'--r')
title('pid参数优化曲线','fontsize',18); title('pid参数优化曲线','fontsize',18);

Loading…
Cancel
Save