Writing fitness function in multi objective GA

If I need to go for a multi objective optimisation in GA, how can I bring in the two objectives in a custom made fitness function. Can someone explain in the context of the travelling salesman problem described here : https://in.mathworks.com/help/gads/custom-data-type-optimization-using-ga.html

 Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Mayo de 2022
mobj = @(x) [fun1(x); fun2(x) ]

7 comentarios

Hari
Hari el 26 de Mayo de 2022
Would the syntax be the same if user function evaluation is chosen as vectorized? I wrote 2 custom fitness functions and called them according to this syntax. But I am getting an error "When 'Vectorized' is 'on', your fitness function must return a vector of length equal to the size of the population"
You know that ga() cannot handle multi objective? gamultiobj() is needed for multi objective.
Hari
Hari el 27 de Mayo de 2022
Yes, I have used gamultiobj() and got the error. The fitness functions worked well independently when used with ga().
You could try
mobj = @(x) [fun1(x), fun2(x) ]
where each of those returns a column vector
Hari
Hari el 27 de Mayo de 2022
This too gives the same error
I am not getting a problem in my tests ?
fun1 = @(x) sin(pi*x(:,1)) + sinh(x(:,2));
fun2 = @(x) cos(pi*x(:,1)) + cosh(x(:,2));
mobj = @(x) [ fun1(x), fun2(x) ];
nvars = 2;
lb = [-pi -pi];
ub = [pi pi];
options1 = optimoptions(@gamultiobj, 'UseVectorized', false);
[Y1, fval1] = gamultiobj(mobj, nvars, [], [], [], [], lb, ub, [], options1);
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
options2 = optimoptions(@gamultiobj, 'UseVectorized', true);
[Y2, fval2] = gamultiobj(mobj, nvars, [], [], [], [], lb, ub, [], options1);
Optimization terminated: average change in the spread of Pareto solutions less than options.FunctionTolerance.
Hari
Hari el 4 de Jun. de 2022
Yes, I tried again. The second approach worked this time. Thanks!!

Iniciar sesión para comentar.

Preguntada:

el 25 de Mayo de 2022

Respondida:

el 5 de Jun. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by