www.pudn.com > SGAProToolboxVer.zip > SGA_pro.m


function [maxfitness,minfitness,meanfitness,best_decimal_space,now_generation,now_probability_crossover,best_binary_space]=SGA_pro(min_confines,max_confines,probability_crossover,probability_mutation,population,decimal_step,max_generation,convergence_method,max_no_change_probability_crossover_generation,deta_fitness_max,deta_fitness_max_min,max_probability_crossover,max_no_change_fitness_generation,probability_crossover_step) 
 
 
%SGA Function Of Simple Genetic Algorithm Program (Version 1.0.0.1) 
%support multi-parameters 
%By chen yi ,CQU .QQ:2376635  Email:cdey@10mail.net  (Aug,9th,2002) 
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
%SGA function is the main function of  Simple Genetic Algorithm Program 
%usage: 
%[maxfitness,minfitness,meanfitness,best_decimal_space,now_generation]=SGA_pro(min_confines,max_confines,probability_crossover,probability_mutation,population,decimal_step,max_generation) 
% 
%min_confines is the minimum of input value in decimal-space 
%max_confines is the maximum of input value in decimal-space 
%i.e. X belong to [min_confines,max_confines] 
% min_confines < max_confines 
%~~ 
%decimal_step is the search step in decimal-space 
%it must be smaller than (max_confines-min_confines)/2 
%~~~ 
%population is the random decimal value in  [min_confines,max_confines] 
% it is given by yourself and it must be Even integer number and larger than 0 
%~~~~ 
%probability_crossover is the crossover probability in crossover step, 
%your can give it's value to reach your need (About:0.4~0.99) 
% 
%probability_mutation is given by yourself (about:0.001~0.01) 
 
%  See Also DECODING ,CODING ,CROSSOVER,MUTATION,FITNESS, 
%           FITNESS_FUNCTION, 	SELECTION	  
 
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
% 
[binary_space,bits_sum,bits]=coding(min_confines,max_confines,population,decimal_step); 
 
[decimal_space]=decoding(min_confines,max_confines,binary_space,bits); 
 
%[population,parameter_numbers]=size(decimal_space); 
 
%ini 
Generation_numbers=1; 
no_change_fitness_generation=1; 
no_change_probability_crossover_generation =1; 
now_generation=max_generation; 
fitness_plot_max=zeros(1,now_generation); 
fitness_plot_min=zeros(1,now_generation); 
fitness_plot_mean=zeros(1,now_generation); 
 
%best_decimal_space=zeros(population,parameter_numbers); 
%ini over 
 
if convergence_method==1 
   disp('convergence_method 1 is Max generation !'); 
   while Generation_numbers<=max_generation 
%%%%%%%%%%%%% Co-evolutionary Genetic Algorithms  
[subjected_decimal_value]=Subject_fitness(decimal_space); 
[fitness_value]=fitness(subjected_decimal_value); 
%%%%%%%%%%%%%%% end Co-GAs 
 
fitness_plot_max(1,Generation_numbers)=max(fitness_value); 
fitness_plot_min(1,Generation_numbers)=min(fitness_value); 
fitness_plot_mean(1,Generation_numbers)=mean(fitness_value); 
[max_fitness_temp_position,decimal_space,binary_space,maxfitness]=selection(decimal_space,binary_space,fitness_value,bits); 
[decimal_space,binary_space]=crossover(min_confines,max_confines,decimal_space,binary_space,bits,probability_crossover); 
% pay attention to the decimal_space and binary_space from mutation.m  
% it can't be  [decimal_space_mutation,binary_space_mutation] 
[decimal_space,binary_space]=mutation(min_confines,max_confines,decimal_space,binary_space,bits,probability_mutation); 
Generation_numbers=(Generation_numbers+1); 
best_binary_space=binary_space; 
end % end of while  
 
best_decimal_space=decimal_space(max_fitness_temp_position(population),:); 
maxfitness1=fitness(best_decimal_space); 
maxfitness2=max(fitness_plot_max); 
 
if maxfitness1==maxfitness2 
    maxfitness=maxfitness1; 
end 
 
minfitness=min(fitness_plot_min); 
meanfitness=mean(fitness_plot_mean); 
now_generation=Generation_numbers-1; 
now_probability_crossover=probability_crossover; 
 
%plot 
hold on; 
ii=1:1:max_generation; 
fitness_plot=plot(ii,fitness_plot_max,'k',ii,fitness_plot_min,'r',ii,fitness_plot_mean,'b'); 
grid on 
title('Every Fitness--population') 
xlabel('population'); 
ylabel('every-fitness'); 
legend('max','min','mean',4); 
 
% end of convergence 1 
 
% begin convergence 2 
 
elseif convergence_method==2 
disp('convergence_method 2 is no change fitness !') 
 while (no_change_probability_crossover_generation <=max_no_change_probability_crossover_generation) 
%%%%%%%%%%%%% Co-evolutionary Genetic Algorithms  
[subjected_decimal_value]=Subject_fitness(decimal_space);    
[fitness_value]=fitness(subjected_decimal_value); 
%%%%%%%%%%%%%%% end Co-GAs 
fitness_plot_max(1,Generation_numbers)=max(fitness_value); 
fitness_plot_min(1,Generation_numbers)=min(fitness_value); 
fitness_plot_mean(1,Generation_numbers)=mean(fitness_value); 
 
[max_fitness_temp_position,decimal_space,binary_space,maxfitness]=selection(decimal_space,binary_space,fitness_value,bits); 
[decimal_space,binary_space]=crossover(min_confines,max_confines,decimal_space,binary_space,bits,probability_crossover); 
% pay attention to the decimal_space and binary_space from mutation.m  
% it can't be  [decimal_space_mutation,binary_space_mutation] 
[decimal_space,binary_space]=mutation(min_confines,max_confines,decimal_space,binary_space,bits,probability_mutation); 
 
if Generation_numbers~=1 
  if (abs(fitness_plot_max(1,Generation_numbers)-fitness_plot_max(1,Generation_numbers-1))~=deta_fitness_max)&... 
      (abs(fitness_plot_max(1,Generation_numbers)-fitness_plot_min(1,Generation_numbers))~=deta_fitness_max_min)&... 
      (abs(fitness_plot_min(1,Generation_numbers)-fitness_plot_min(1,Generation_numbers-1))~=deta_fitness_max)&... 
      (abs(fitness_plot_mean(1,Generation_numbers)-fitness_plot_mean(1,Generation_numbers-1))~=deta_fitness_max) 
        if no_change_fitness_generation>=max_no_change_fitness_generation 
        if probability_crossover<=max_probability_crossover 
       probability_crossover=probability_crossover+probability_crossover_step; 
       no_change_probability_crossover_generation=no_change_probability_crossover_generation+1; 
       end       
   end 
no_change_fitness_generation=no_change_fitness_generation+1; 
end 
end 
Generation_numbers=(Generation_numbers+1); 
best_binary_space=binary_space; 
end % end of while 
 
best_decimal_space=decimal_space(max_fitness_temp_position(population),:); 
maxfitness1=fitness(best_decimal_space); 
maxfitness2=max(fitness_plot_max); 
 
if maxfitness1==maxfitness2 
    maxfitness=maxfitness1; 
end 
minfitness=min(fitness_plot_min); 
meanfitness=mean(fitness_plot_mean); 
now_generation=Generation_numbers-1; 
now_probability_crossover=probability_crossover;  
 
else % other convergence method  update choice 
    disp('The convergence method has two way now, chose:1 or 2'); 
    break; 
end 
 
%plot 
hold on; 
if now_generation>max_generation 
   i=1:1:now_generation; 
else 
    i=1:1:(max_generation); 
end 
fitness_plot=plot(i,fitness_plot_max,'k',i,fitness_plot_min,'r',i,fitness_plot_mean,'b'); 
grid on 
title('Every Fitness--population') 
xlabel('population'); 
ylabel('every-fitness'); 
legend('max','min','mean',4); 
 
% end of sga_pro.m