## problem with curve tracking obtained by the genetic algorithm

### Maisa Melo (view profile)

on 11 Feb 2019
Latest activity Commented on by Maisa Melo

on 11 Feb 2019

### John D'Errico (view profile)

Hello,
I'm running a genetic algorithm with linear inequality constraints:
gaoptions = gaoptimset('TolCon', 1e-12, 'TolFun', 1e-8, 'CrossoverFcn', @crossoverheuristic, 'MutationFcn',@mutationadaptfeasible, 'PopulationSize', 100, 'Generations', 200, 'InitialPopulation',U0');
U =ga(@(U0) funcaoObjetivo(QP,U0',n,auxPrevisoes,R,Riqueza,auxR1,tbBarra,C,D,r1,ci,Uant,peso1,peso2),m*(n+1),B,b,[],[],[],[],[],gaoptions);
I'm also running the same algorithm with fmincon optimization.
options = optimoptions(@fmincon,'Algorithm','sqp','TolFun',1e-12);
U = fmincon(@(U0) funcaoObjetivo(QP,U0,n,auxPrevisoes,R,Riqueza,auxR1,tbBarra,C,D,r1,ci,Uant,peso1,peso2),U0,B,b,[],[],[],[],[],options);
Both results must be equivalents however, the genetic algorithm is not able to achieve good solutions as fmincon does. The main objective is tracking a curve, the solutions obtained by fmincon get tracking the curve exactly (with small error), the solutions obtained by ga also get tracking the curve but with a big error. Do you know what can be my mistake?

R2015a

### John D'Errico (view profile)

on 11 Feb 2019
Edited by John D'Errico

### John D'Errico (view profile)

on 11 Feb 2019

It is not really a mistake, except perhaps a mistake of choice. Or you might say a mistake of understanding the tools involved.
GA is a stochastic algorithm. It is good at trying to not get stuck in a local minimum, while still trying to find the global solution. But it is not really that good at zeroing in on the exact solution. Or if you try to force it to do so, a stochastic optimizer will take a longer time to do so, because it will require many function evaluations.
Fmincon is designed to move down a smoothly structured surface, with rapid convergence when the solution is near. If you want, think of the quadratic convergence behavior of algorithms in the class of Newton's method.
Different algoithms have differing performance, and different things they do really well.
So you can have it either way, but you cannot so easily have the best of all worlds. Yes, I suppose you could use GA to do as well as it can in areasonable amount of time, then when it terminates, switch to fmincon to hone in on the solution.

Alan Weiss

### Alan Weiss (view profile)

on 11 Feb 2019
Excellent description, John. Let me just add that the HybridFcn option exists for exactly this reason: to allow ga to get to the neighborhood of a solution, and then let fmincon find a more precise solution.
Alan Weiss
MATLAB mathematical toolbox documentation
John D'Errico

### John D'Errico (view profile)

on 11 Feb 2019
AH. Thank you Alan. One thing I really need to do is learn the GO TB toolset. Harder since I do not have that TB.
Maisa Melo

### Maisa Melo (view profile)

on 11 Feb 2019
Thank you, everyone, to the help. I used the HybridFcn option as suggested. The result for ga optimization was a lot better than the result before.