main.m

来自「Real Genetic Algorithm RGA」· M 代码 · 共 46 行

M
46
字号

% By Youhanna Parvizinejad (83405169) and Mahdi Farahmadfar (81414271)
% ------------------- Valid Range Of Algorithm -------------------

Start_points=[-4 -1.5];
End_points=[2 1];

%----------- Base Parameters Of Binary Gen Algorithm -------------
N=50;           %Number Of Population
Gen_num=2;            
till=100;

%----------- Defination Temp Vars -------------
Best=[];
AvaerageFit=[];
Population=[];

%----------- Base Parameters Of Gen Algorithm -------------

Mutation_rate=0.01;         
Crossover_rate=0.705;       

%-------------------- Initializing First Generation --------------
Norm_Population=rand(N,Gen_num);     
for i=1:Gen_num
    x=Norm_Population(:,i);
    x=Start_points(i)+x*(End_points(i)-Start_points(i));
    Population(:,i)=x;
end

% --------------------- Loop Back Till Last Generation -----------

for it=1:till
    [Selection_rate,Fit,AveFit,MaxFit,Best_answ]=Get_Value(Population,N);  
    Best(it)=MaxFit;
    Best=sort(Best);
    AverageFit(it)=AveFit;
    [Selected_gen]=Roulette(N,Selection_rate,Population);         
    [Next_Gen]=Crossover(Selected_gen,Crossover_rate,N);                                    
    [Population]=Mutation(End_points,Start_points,Next_Gen,N,Gen_num,Mutation_rate);                             
end


% ------------------------  Calling Output + Plot Funtion  ------------
[out1]=Displayit(Best_answ,Best,AverageFit,till);

⌨️ 快捷键说明

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