function [xopt,stats]=messaoud3(NombGen,pop,cod);
pause on;
clc;
tic,
binf1=1; % Definition des bornes sup et inf des prametres
binf2=0.1;
binf3=200;
binf4=1;
bsup1=1;
bsup2=0.25;
bsup3=1250;
bsup4=1;
bsup=[bsup1 bsup2 bsup3 bsup4];
binf=[binf1 binf2 binf3 binf4];
bits(1,1:4)=cod; % Definition du nombre de bits avec lequel sera code le chromosome
a=rand(pop,cod*length(bits)); % Creation d'une matrice aleatoire
new_gen=round(a);
%xopt=[1 0.01 0.03 0.03];
%xopt=ones(pop,1)*xopt;
%new_gen=encode(xopt,binf,bsup,bits);
%new_gen=ones(pop,1)*xopt;
%new_gen=encode(x_fin,binf,bsup,bits);
fit_opt=-inf; % Intialisation du meilleur individu a -infini
stats=[];
au=1;
disp('Soyez Patients pendant l''impl�mantation du programme S.V.P.');
disp(' Statistiques Fitness')
disp('Generation Maximum Minimum Moyenne')
for generation=1:NombGen, % Debut de la boucle principale
old_gen=new_gen;
x_pop=decode(old_gen,binf,bsup,bits); % Decodage de la matrice aleatoirement cree
for i=1:pop, % Calcul des fonctions cout
x=x_pop(i,:);
ki=x(1);
kv=x(2);
kr=x(3);
kref=x(4);
%epr=1.05;
%w=0.0178;
%l=0.0267;
%h=0.0099;
Vr=(1/kr)*(ki*1.8+kv*28+kref*2.8);
%fitness(i)=10-abs(min((fr-5)/(fr+5)).^4);
fitness(i)=1-abs(min(Vr)-0.017);
%fitness(i)=10-abs(min((fr-5)/(fr+5)).^2);
end;
[fitness_c,ind_fit]=sortmx(fitness); % Classement du max au min
if fitness_c(1)>fit_opt,
fit_opt=fitness_c(1);
xopt=x_pop(ind_fit(1),:);
end
tr=10-max(fitness);
pu(au)=tr;
bu(au)=generation;
au=au+1;
stats(generation,:)=[(10-fitness)];
%stats(generation,:)=[20*log10((fitness)) 20*log10(min(Fs(1:30)))...
% 20*log10(max(Fs(40:91)))];
s=stats(generation,:);
disp([sprintf('%5.0f %12.6g ',generation-1,stats(generation,1))]);
%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
new_gen=ones(pop,1)*old_gen(ind_fit(1),:);
new_gen(pop/2+1:pop,:)=xover(old_gen(1:pop/2,:),0.8); % Croisement du chromosome,on ne
% croise que 50% de la population
new_gen=mate(new_gen); % Reorganisation aleatoire du chromosome
new_gen=mutate(new_gen,0.01); % Mutation avec Pm=1%
%new_gen = tselect(old_gen,fitness,2,2);% s�lection par tournoi
% Reproduce par roulette russe
%new_gen = reproduc(old_gen,fitness);
% Mate
%new_gen = mate(new_gen);
% Crossover
%new_gen = xover(new_gen,0.7);
% Mutate
%new_gen = mutate(new_gen,0.01);
end
ki=xopt(1);
kv=xopt(2);
kr=xopt(3);
kref=xopt(4);
disp('Les param�tres sont:');
disp([sprintf(' ki=%d ',ki)]);
disp([sprintf(' kv=%d ',kv)]);
disp([sprintf(' kr=%d ',kr)]);
disp([sprintf(' kref=%d ',kref)]);
Vr=(1/kr)*(ki*1.8+kv*28+kref*2.8)
toc;
%plot(bu,pu,'linewidth',2);grid;
AG-code.rar_AG genetic_algorithms
版权申诉
16 浏览量
2022-09-19
21:38:57
上传
评论
收藏 5KB RAR 举报
小贝德罗
- 粉丝: 70
- 资源: 1万+