Randomly Error - index must be a positive integer or logical

3 views (last 30 days)
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

Answers (5)

Bugar Waristara
Bugar Waristara on 23 Jun 2011
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 Comments
Walter Roberson
Walter Roberson on 23 Jun 2011
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 on 24 Jun 2011
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

Sign in to comment.


Krishna Kumar
Krishna Kumar on 23 Jun 2011
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 on 23 Jun 2011
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 on 23 Jun 2011
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 on 29 Jun 2012
Send me your code, its been removed by media fire, so I can help you as soon as possible. Mjid.yazdani@gmail.com

Products

Community Treasure Hunt

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

Start Hunting!