Whats wrong with in my code attached
조회 수: 1 (최근 30일)
이전 댓글 표시
Please see my attached files the issue I am facing is that the value of f that I am calculating via the objective function is not getting displayed instead another value is being displayed and the program is running indefinitely which i dont want
댓글 수: 0
채택된 답변
Geoff Hayes
2014년 9월 28일
Bhavz - as you have not specified any options (see ga options) then the default number of generations for your optimization problem is 100 multiplied by the number of variables. Since you have 32 variables, then there will be 3200 generations/iterations for this problem, which explains why it appears to be running indefinitely.
To limit the number of generations to (for example) 50, you should be able to do the following in your main.m file
options = gaoptimset('Generations',50);
nonlcon=@constraint;
[x,fval,exitflag] = ga(@objectiveFun,...
32,[],[],[],[],lb,ub,nonlcon, options);
NOTE how the above code makes use of the ub variable which you have commented out in main.m. You will need to review this to see what this variable should be set to.
As for the value f from your objective function not being displayed, what do you see instead? Something other than f or just something that you don't expect to be f? The last line in your objectiveFun.m file is
f=ro_max
without a semi-colon, so whenever this function is called, you should be seeing something like the following in the Command Window
f =
<some number>
And you will see something similar to this up to 100 times per generation/iteration since you have not specified a population size and so the default of 100 is used (again, based on an equation that makes use of the number of variables).
댓글 수: 9
Geoff Hayes
2014년 10월 8일
In your options object, try adding the following so that the best fitness (your fval) for each generation is plotted
options = gaoptimset('Generations',50,'PopulationSize',42, ...
'PlotFcns',@gaplotbestf);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!