Question

I have a genetic algorithm program, everything is allocated dynamically using vectors. Nowhere is the number of generations or individuals per generation set at compile time.

I tried it using 500, 1000, 2000 generations, it runs perfect. Then I tried 10,000 generations. It gave me debug assertion failed, vector subscript out of range at generation 4966.

I tried again twice with the same parameters, 10,000 generations, it ran fine.

I tried it once more, I got the error at generation 7565.

It's strange that sometimes it works perfectly, sometimes I get the error. Especially considering that everything is done using vectors.

Any ideas on where could the problem come from? Maybe the debug mode is buggy for some reason?

Was it helpful?

Solution

The problem comes from stack corruption or most probably from index out of bounds access. The fact that there are cases when your code crashes indicates there is something wrong. If your code is multi-threaded the problem may be because if actions are executed in a given order your code will try to access something out of bounds for a vector.

My advice is to run your code using valgrind and see what it will say. Usually it helps in resolving similar issues.

Also note the fact that there are cases when your code does not crash this does not mean that it works perfectly. You may still have stack corruption or similar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top