# Effect of GA population size and Number of generation with many variables

7 views (last 30 days)
Rawit Janrat on 27 Feb 2022
Answered: Prateekshya on 9 Nov 2023
first of all i'm not good at computer programming and i'm not a native English speaker if moderator or others find this frustating,I'm apologising for my mistake
my objective function has 240 variables with the given options
options = optimoptions('ga','Generations',1000,'PopulationSize',500,'MaxStallGenerations',1000,...
'CrossoverFcn',{@crossoverintermediate},'FunctionTolerance',0.01,...
'SelectionFcn',{@selectionroulette},'Display','iter',...
'EliteCount',48,'PlotFcn',{@gaplotbestf,@gaplotdistance});
from my objective function when having a smaller population size it doesn't give an optimal result also doesn't satisfy the constraints.
with given population size (500) it takes too long to run but sometimes the result satisfy constraints and sometimes don't.
which mean i have to increase population size? but how much without guessing and spent a whole lot of time testing
e.g I create my own constraints using if else and lagrange multiplier formula which cost the objective function m file has between 7000 lines
e.g 2 -> have to use GA.I got assigned to do GA with the problem.

Prateekshya on 9 Nov 2023
Hi Rawit,
As per my understanding, you want to know how to tune the Genetic Algorithm operations in order to improve your solution.
Increasing the population size or number of generations leads to increase in execution time as well. Taking the population size as 500 is also not suggested. The closest workaround will be to change the "crossover" function and check which one is working the best. You can check my answer here to know more about it: https://in.mathworks.com/matlabcentral/answers/1732700-how-does-crossover-occur-in-a-genetic-learning-algorithm-do-genes-ever-mix-change-locations#answer_1304186?s_tid=prof_contriblnk
You may need to implement Genetic Algorithm from scratch to twist things according to you.
I hope it helps!