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!