2
votes

I have a Matlab script (actually a function, funModel), which I'm trying to solve with 7 integer variables via a genetic algorithm:


nvars = 7; %number of variables
Aineq = [1 1 1 1 1 1 1]; Aeq = [];
bineq = [VesMaxCrew]; beq = [];
LowBound = [1 1 1 1 1 4 0];
UpBound = [1 1 VesMaxCrew 1 VesMaxCrew VesMaxCrew VesMaxCrew];
Nonlcon = [];
IntCon = [1:7]; % all 7 variables to be treated as integers
Options = gaoptimset('Display','iter',... %display every iteration
'Generations',70,... %maximum number of generations is 70
'TolFun',1,... %tolerance for optimisation is 1
'TolCon',1,...
'PlotFcns',@gaplotbestf);
OptimisedValue = ga(@funModel,nvars,Aineq,bineq,Aeq,beq,,LowBound,UpBound,NonlCon,IntCon,Options);

The genetic algorithm works fine and finds a good solution, easily within 70 generations (as can be seen with the plot function @gaplotbestf). With the current input, the optimal solution is chosen for every individual after 25 to 30 generations. The algorithm, however, continues to run until 51 generations have been made. This would seem like at least 20 generations too many.

Even if I change the input parameters of funModel, the genetic algorithm still runs at least 51 generations, like there is some constraint or setting saying the algorithm has to run 51 generations minimum. (As can be seen, a maximum number of generations has been entered)

Why doesn't the algorithm stop between 25 or 30 generations? (or just after 30 generations) And more importantly, does anyone know how to alter this?

(I haven't been able to find anything about a setting (gaoptimset) of minimum generations in the Matlab documentation. Neither have I been able to find somebody with the same problem/question.)

1
Can you show us the graph of "optimal solution over generation" and "average fitness of society over generation"? It could be that, even though the optimal is found, it still tries to improve (since of course it doesn't know that what it found was optimal). - Shahbaz
@Shahbaz: thanks for your quick response! However, even if it tries to find a more optimal solution, why always this minimum of 51 generations? - Willem
Could be lucky and have something to do with the nature of your problem. Or could be that whoever implemented that algorithm thought a minimum of 50 generations helps preventing early (and wrong) termination, so he just put it there in the implementation without documenting it. - Shahbaz
"Stall generations" option has default value of 50. This is actually the point where it stops in your case. [MatlabDoc] (mathworks.com/help/gads/genetic-algorithm-examples.html#f15811) - durasm
@aircooled: that's indeed what I was looking for. I'm sorry to say I didn't check the manual good enough :s. Thanks a lot for answering! - Willem

1 Answers

1
votes

"Stall generations" option has default value of 50. This is actually the point where it stops in your case. This can be considered as a minimum number of generations. For more details please check here.