Randomly Error - index must be a positive integer or logical

1 次查看(过去 30 天)
Hello All,
Now, I develop a program based on m-file. My program was based on Genetic Algorithm to solve Vehicle Routing Problem with Time Window (VRPTW) case.
But when I run it, it come to this -index must be a positive integer or logical- kind of error.
Because my program consist of more than one m-file, I afraid it will make you confuse if I just copy a part of that. So, I upload all in http://www.mediafire.com/?0u4a32bx0mz6gys
Please help me to solve this, it started to make me frustated. Thank you

回答(5 个)

Bugar Waristara
Bugar Waristara 2011-6-23
I was not sure that there are any zeros value in my population because the member of the population generated from random number from 1-JumGen(integer positive number).
Is there are any method to check whether there are any zero in my population?
Thank you
  2 个评论
Walter Roberson
Walter Roberson 2011-6-23
if any(YourArray(:)==0)
then there is a 0.
More robust would be to check
if any(YourMatrix(:) < 1 | YourMatrix(:) ~= fix(YourMatrix(:))
Krishna Kumar
Krishna Kumar 2011-6-24
Bugar,
Your population may be ok while initialization. But during course
of mutation, recombination etc( hope you use simple GA), the values in population may go beyond limits or become zero, negative etc. So Check that . If that is true, make sure the rogue values are re initialized in the limit.
HTh

请先登录,再进行评论。


Krishna Kumar
Krishna Kumar 2011-6-23
Bugar, its difficult for us to solve it straightaway, since you didnt mention in which code the error occurs. The error is a common one. when use call sth like this c=A(:,r), where A is a matrix, r needs to be positive integer. if r is -ve or 0 or decimal, the error would be shown. Obviously MATLAB will tell you which code has the error. Put breakpoint at the point of error and see what the index is- negative, zero etc. This would suffice

Bugar Waristara
Bugar Waristara 2011-6-23
Krishna, but when I run it, the m-file where the error occurs is random. Sometimes, it came from my mainHMOEA.m file, but in another time, it came from my HMOEAmutasi.m, the file which the output is used in mainHMOEA.m.
Basically, i always check the line that noted by the program as the error source and I sure that normally it will not get error. Can you please kindly check my file.
Thanks

Krishna Kumar
Krishna Kumar 2011-6-23
Bugar From a brief review of code, I suppose that Tempopulasi is your population which is passed as input argument to other functions. This population matrix has zeros in it . So it causes problem in RuteA which in used as index somewhere. So make sure your population does not have zeros or negatives. Thats the way out for you. hth

majid yazdani
majid yazdani 2012-6-29
Send me your code, its been removed by media fire, so I can help you as soon as possible. Mjid.yazdani@gmail.com

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by