[HELP] fmincon to ga

Hi guys,
I have a o object function that i write for fmincon.
What should i change to minimize same object function by a ga(genetic algorithm) any tips,suggestions will be amazingly help me.
I explained the functions/problem/object (fitness) function better in comments below.

 Accepted Answer

You shouldn't have to change anything!
In fact you can use ga as the coarse minimization method and then use fmincon as a 'HybridFcn' for the finer tuned minimization after ga has gotten close.
doc gaoptimset

10 Comments

E K
E K on 31 Jul 2012
Thank you for your answer Sean,
but i call my optimization process by;
[x,fval,exitflag,output,lambda,grad,hessian] = ... fmincon(@(x) helper.objFcn(x,dimensions.R),x0,[],[],[],[],lb,ub,[],options);
as you know fmincon starts by initial points x0, so i am pretty lost in turning optimisation method to ga. should i use x0 as initial population? or do some weird stuff for ga.
I am really sorry if my question is silly. I am pretty new in both optimisation and ga.
Sean de Wolski
Sean de Wolski on 31 Jul 2012
Edited: Sean de Wolski on 31 Jul 2012
ga() will generate its own x0.
You could give it an 'InitialPopulation' which I believe is the equivalent of x0.
E K
E K on 31 Jul 2012
Edited: E K on 31 Jul 2012
Sorry to bother you guys (esspecially Sean) again but when i try to feed ga optimization tool like
[ x,fval,exitflag,output] = ...
ga(@(x) helper.objFcn(x,dimensions.R),70,[],[],[],[],lb,ub,[],options);
i cant get any solution, and get Optimization terminated: maximum number of generations exceeded.
even though i set maximum number of generations to 1000.
and fmincon manage to optimize the problem in just 38 iteration.
and when i try to feed initalpopulation with x0 (which are a vector of base station positions x1 y1 x2 y2 ....)
i get
Incorrect size of InitialPopulation
error
So your objective function is a function of 70 variables? How good are your intial guesses. How big is what you are feeding for 'InitialPopulation'?
E K
E K on 31 Jul 2012
Edited: E K on 31 Jul 2012
Hi again sean and thank for your patience and help. i am pretty lost in these optimisation processes.
i am pasting some codes to make a clear explanation
This is my setup/initial function (or where the problem begins) i got the parts of the code from an example.
%{
function [dim,lb,ub,x0] = celltowersetup(N,up,seed)
% CELLTOWERSETUP creates a randomly generated celltower problem.
% [dim,lb,ub,x0] = CELLTOWERSETUP(N, SIDE, SEED)
%
% Input:
% N : number of towers
% SIDE : length of the side of area
% SEED : random seed for initial cell location (integer)
% Output:
% dim.R : radius of cell tower coverage
% dim.xL : 0 % for plotting
% dim.xU : SIDE % for plotting
% dim.yL : 0 % for plotting
% dim.yU : SIDE % for plotting
% lb : lower bound values for x, y (based on the radius)
% ub : upper bound values for x, y (based on the radius)
% x0 : initial center points (x, y pairs)
low = 0;
st = RandStream('mcg16807', 'Seed', seed);
R = rand(st, N,1)+1; % allocate array
% Generate bound constraints
xL = low; xU = up;
yL = low; yU = up;
% 2*N variables in the order [x1,y1,x2,y2...,xn,yn]'
lb = zeros(2*N,1);
ub = lb;
lb(1:2:2*N) = xL + R;
lb(2:2:2*N) = yL + R;
ub(1:2:2*N) = xU - R;
ub(2:2:2*N) = yU - R;
% Random start point
x0 = up*rand(st, 2*N,1);
dim = struct('R', R, 'xL', xL, 'xU', xU, 'yL', yL, 'yU', yU);
}%
and my object function have the form of
f = objFcn(x, R)
which f is an integer , both x and R are vectors. where x are base station coordinates. R is their radius.
i am able to optimize the problem by using
[x,fval,exitflag,output,lambda,grad,hessian] = ...
fmincon(@(x) helper.objFcn(x,dimensions.R),x0,[],[],[],[],lb,ub,[],options);
and what i want to do is just optimize the problem by using ga.
Sean de Wolski
Sean de Wolski on 1 Aug 2012
Edited: Sean de Wolski on 1 Aug 2012
Well fmincon is using gradient information to help is converge quickly. ga does not have this luxury; it needs to breed and cull many generations in order to have a good solution evolve. However, it can handle things that fmincon can't for this reason.
You may wish to try using more generations, perhaps 10000. Genetic algorithms do require tuning in order to be effective. You may instead wish to change the 'EliteCount' so that more good candidates survive. This would especially be the case if you think you have a good starting point.
patternsearch might be another place to look as well.
E K
E K on 1 Aug 2012
Yes sean you are right it took a lot more time and generations for GA to find the optimal solution. In the end it found a little bit solution with trade of time and more function calculation.
Thank you very much.
This is why I suggest maybe using a 'HybridFcn'. Let ga find the valley that contains the global minimum and then use fmincon to hone in on the minimum of this valley really quickly.
Hello,
I want to do the same thing, have you managed to do it? Actually, when I use ga, the program doesn't find a feasible point, I couldn't solve the problem. Can you please tell me what options I can use to solve my problem? Any suggestion will be helpful.
Thank you in advance,

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!