Number of variables (NVARS) must be a positive integer.

30 次查看(过去 30 天)
I want to run a project using genetic algorithm but I get this error every time.
I know what is it but I don't know how to fix it.
this is my project that I attached and the main function is GAmodule.
you can start with these numbers :
235
2
1
4
0
0
0
10
0
0
5
0
10
0
0
1000
g
700
Thank you

采纳的回答

Star Strider
Star Strider 2014-8-23
编辑:Star Strider 2014-8-23
In this line (Line 163):
[x,fval]=ga(@(x) penalty2(x,available,bc,Dof,E,f,fixedcoord,na,nb,neft,nevt,nl,nn,numbitCoordX,numbitCoordY,numbitCoordZ,numbitEdof,numbitEp,sq,TOPGSM,xspan,yspan,zspan),(nn-nb-nl)*(numbitCoordX+numbitCoordY+numbitCoordZ)+(neft+nevt)*numbitEp+2*nevt*numbitEdof,options);
the ga function is taking this value:
(nn-nb-nl)*(numbitCoordX+numbitCoordY+numbitCoordZ)+(neft+nevt)*numbitEp+2*nevt*numbitEdof
to be ‘nvars’. It has to be an integer >0. I would use the ceil function to round it up to the next integer value, and include a check that it is >0.
For example, put this assignment and if block somewhere before your ga call:
Nvars = ceil((nn-nb-nl)*(numbitCoordX+numbitCoordY+numbitCoordZ)+(neft+nevt)*numbitEp+2*nevt*numbitEdof);
if Nvars <= 0
error('NVARS must be greater than zero.')
end
then when it meets the criteria, use ‘Nvars’ (or whatever you want to call it) in your ga call.
  2 个评论
Hessam
Hessam 2014-8-24
Thanks, It is a good idea.
The problem was all Y-coordinates = 0, therefore yspan=0 and numbitcoordY=-Inf

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by