How to access the generation of the population in fitness function while using gamultiobj in Matlab?

2 views (last 30 days)
I have been using gamultiobj in Matlab to run my optimization setup. When the GA calls the fitness function it only sends the population to the fitness function as its input. But, I need also the generation to which the population belong. How could that be done as I am not able to edit the Matlab inbuilt functions.

Answers (1)

Umang Pandey
Umang Pandey on 26 Sep 2023
Hi Rajan,
As per my understanding, you wish to get the number of generations until which the "gamultiobj" function executes before returning the Pareto front. It is indeed possible to get the number of generations as an output of the "gamultiobj" function. Refer the following example:
% Defining a sample fitness function
fitnessfcn = @(x)[norm(x)^2,0.5*norm(x(:)-[2;-1])^2+2];
% Using the gamultiobj function
[x,fval,exitFlag,output] = gamultiobj(fitnessfcn,2);
% Getting the number of Generations
gen = output.generations;
The output argument "output" returned by the "gamultiobj" function is a structure consisting of various fields like the type of problem("problemtype"), number of generations("generations"), total number of function evaluations("funccount"), etc.
Refer the documentation for more information:
Best,
Umang

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!