1

I am using rbga in R, and the following error occurs during what seems to be the part of the function that applies elitism. Here is the session leading up to the error:

Testing the sanity of parameters...
The start conditions:
GA Settings
  Type                  = 
  Population size       = 10
  Number of Generations = 10
  Elitism               = 2
  Mutation Chance       = 0.00237529691211401

Search Domain
  Var 1 = [-0.1,0.1]
  Var 2 = [-0.1,0.1]
  Var 3 = [-0.1,0.1]

Starting with random values in the given domains...
Starting iteration 1 
Calucating evaluation values... .......... done.
Creating next generation...
  sorting results...
  applying elitism...
Error: subscript out of bounds

Unfortunately, I can't provide a reproducible example as my code consists of around 300 lines, and I can't seem to create simplified version. Has anyone experienced a similar issue when using rbga, and can anyone give me any pointers on why this could be happening ?

Update

I have found the line of code in the rbga function that is causing the error:

newPopulation[1:elitism, ] = sortedPopulation[1:elitism, ]

The length of sortedPopulation at this point is 0, while elitism is 2 ... anyone have any ideas ?

Sherlock
  • 5,557
  • 6
  • 50
  • 78
  • Can you run `rbga` successfully with example code from help page? Have you tried going into `debug` mode? – Carl Witthoft Nov 01 '12 at 11:41
  • Hi Carl, thanks for adding the tag. I am able to run the code from the help page. I'm not sure how to go into debug mode, can you give me some pointers ? many thanks – Sherlock Nov 01 '12 at 11:49

1 Answers1

3

This issue occurred because the evaluation function returned NA, which messed things up in the rbga function. Ensure the evaluation function returns a real value to avoid this error.

Sherlock
  • 5,557
  • 6
  • 50
  • 78