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

 채택된 답변

Geoff Hayes
Geoff Hayes 2014년 9월 28일

1 개 추천

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);
So we just pass the options structure as the last input to the ga function.
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

Bhavz
Bhavz 2014년 9월 28일
편집: Bhavz 2014년 9월 28일
Hi Geoff
Many thanks for solving one of my queries abt the indefinite loop issue and as for the ub being commented out so can it be removed from my funtion call to ?
As for the result i just see B = 50 100 50 150...in repeat indefinitely how can i get the function to show f values while specifying the population size ?
All help much appreciated
Hi Bhavz - to specify the population size, again use the options object as follows
options = gaoptimset('Generations',50,'PopulationSize',42);
or whatever you wish for the population size.
As for ub, you will either have to set it to something or remove it from the function call to ga else you will get some sort of undefined function or variable error.
I'm not sure where the B is coming from as there is only a reference to this variable in the constraint.m file. But as all lines are terminated with a semi-colon then this can't be the source of the output B=50 100 50 ....
Are you sure that this version of constraint.m is the one that you are using? When I tried it, I observed two errors with line 36
C(ii)=C(ii))*(1-Ye(ii));
There is an additional bracket to right of second C(ii) yielded the Unbalanced or unexpected parenthesis or bracket. Once I removed that bracket, the error Undefined function or variable "C" was raised since C hadn't yet been defined and yet you are using it in the equation
C(ii) = C(ii)*(1-Ye(ii));
What should C be initialized to?
Bhavz
Bhavz 2014년 9월 30일
Many thanks for that Geoff now when I seem to run it gives me this error
Error using ga (line 324) GA requires the following inputs to be of data type double: 'ub'.
Error in main (line 111) [x,fval,exitflag] = ga(@objectiveFun,...
What should I do in this case and how do I get to the pt that the program displays f= [some number] scenario.
I cant thankyou enough for yr help and guidance
Bhavz
Bhavz 2014년 9월 30일
편집: Bhavz 2014년 9월 30일
I looked into it and its because of the UB not being defined and if I keep ub as [] in [x,fval,exitflag] = ga(@objectiveFun,... then it gives me f=0 repeatedly as value what shud be my upperbound UB in this case to make it work ?
If f is always being set to zero, then you should first step through objectiveFun.m code to see what the inputs are and what is happening. Put a breakpoint at the line
l_dp=reshape(l_dp1,4,8);
then run your main.m script and look at what the input, l_dp1, to your objective function is. Are they all zeros, or...? What should typical values be for these 32 variables - integers or real numbers, positive or negative?
Bhavz
Bhavz 2014년 10월 5일
^ Many Thanks for that I did manage to crack that but now my f values do come out but its same two decimal values repeatedly and alternately I am attaching my current files ...ideally f shud be a varied set of decimal values
Try putting a breakpoint in the file objectiveFun.m, at the line
l_dp=reshape(l_dp1,4,8);
then re-run the optimization. When the debugger pauses at this line, look at the input l_dp1, and the global variables hd, ce, and delta_edp. Step through the code and observe what happens to the local variable array ro as it is updated.
As the only difference between successive calls to this function is the input parameter l_dp1, consider how it is constructed by the genetic algorithm. Does it have the values that you expect to appear for each of the 32 variables? As each new parent (or child) is evaluated with this fitness function, do the parent (or child) "genes" change much from one parent to another?
Bhavz
Bhavz 2014년 10월 7일
^ Thankyou so much I cant thankyou enough for all your help ,just one last pointer if I wanted to plot these fval vector values how would i do that ?
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);
See GA plot options for more details.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

질문:

2014년 9월 28일

댓글:

2014년 10월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by