About termination of genetic algorithm

I have set the options of the ga as shown:
options=gaoptimset(options,'Generations',100);
The algorithm terminates after 6 generations. I would like to ask how i will make the algorithm terminate at 100th generation. Thank you in advance.

 채택된 답변

Alan Weiss
Alan Weiss 2012년 9월 7일

0 개 추천

ga would normally not exit until at least 50 generations. Therefore, either you have nonlinear constraints, or your options are not what you say they are.
Can you please show us your real options settings (the line you gave assumes that some options have already been created), your real function call, and your real output?
Alan Weiss
MATLAB mathematical toolbox documentation

댓글 수: 5

dimitris
dimitris 2012년 9월 7일
편집: dimitris 2012년 9월 7일
The options are:
options=gaoptimset('PopulationSize',40,'SelectionFcn',@selectionroulette,'CrossoverFraction',0.75,'CrossoverFcn',@crossovertwopoint,'MutationFcn',@mutationadaptfeasible,'Generations',1000,'PlotFcns', {@gaplotbestf,@gaplotscores,@gaplotbestindiv},'Display','iter','UseParallel', 'always', 'Vectorized', 'off');
function [c ceq] = nlinconst(x)
c=[];
ceq=[];
end
matlabpool open 4
[x,y,exitflag,output]=ga(@(x) obj_opt(x),n,A,b,Aeq,beq,LB,UB,@nlinconst,options)
matlabpool close
And the output is
y=10
exitflag = 1
output=
problemtype: 'nonlinearconstr'
rngstate: [1x1 struct]
generations: 5
funccount: 10440
message: [1x140 char]
maxconstraint: 0
Sean de Wolski
Sean de Wolski 2012년 9월 7일
Whya re you giving it non-linear constraints if you don't use them?
Because the parameters are passed to the ga function in this particular way. The following line produces error
[x,y,exitflag,output]=ga(@(x) obj_opt(x),n,A,b,Aeq,beq,LB,UB,options)
Yes, you need to pass in the empty set:
[x,y,exitflag,output]=ga(@(x) obj_opt(x),n,A,b,Aeq,beq,LB,UB,[],options)
dimitris
dimitris 2012년 9월 7일
That was the problem. Now it works fine. Thank you very much sir.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 9월 6일
편집: Sean de Wolski 2012년 9월 6일

0 개 추천

What is the exitflag returnmed from ga()?
This will tell us a lot about what is causing it to exit...
More From doc:
Without nonlinear constraints — Average cumulative change in value of the fitness function over StallGenLimit generations is less than TolFun, and the constraint violation is less than TolCon.
With nonlinear constraints — Magnitude of the complementarity measure (see Definitions) is less than sqrt(TolCon), the subproblem is solved using a tolerance less than TolFun, and the constraint violation is less than TolCon.
So I would recommend starting with those settings.

댓글 수: 2

dimitris
dimitris 2012년 9월 6일
편집: dimitris 2012년 9월 6일
Of course, i should have posted it before, exitflag=1. I don't have any nonlinear constraints.
Sean de Wolski
Sean de Wolski 2012년 9월 6일
see more

댓글을 달려면 로그인하십시오.

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by