Whats wrong with in my code attached
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Geoff Hayes
on 28 Sep 2014
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 Comments
Geoff Hayes
on 8 Oct 2014
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);
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!