0

I'm programming a genetic algorithm. Right now, I'm using arrays for everything: my individuals are composed of arrays of ints, my populations are arrays of individuals, I store information inside an array to keep track of it.

A huge limitation I'm encountering is running out of memory. I know GAs are memory intensive, but i wonder if my first step should be to make an easy change, by using something better than an array.

user3448821
  • 249
  • 1
  • 3
  • 13

2 Answers2

0

The answer to this question depends a lot on the nature of your data.

If you have sparse data (mostly 0's and very few 1's or vice versa), then creating an array of indices of 1's might do the trick for you. As David Wallace mentioned, a HashSet of indices would allow you to quickly check whether a particular index is 1 or 0.

If you do not have sparse data, then you might want a BitSet.

This discussion might also be useful to give you input.

Community
  • 1
  • 1
merlin2011
  • 71,677
  • 44
  • 195
  • 329
0

You can put a triplet into one integer.

G = 0001

A = 0010

T = 0011

C = 0100

U = 0101 (RNA)

N = 0111 (G or C)

Q = 1000 (A or T/U)

...

3 x 4 bits fits in one 32 bit int. A triplet fits good into the genetic context. Write a Helper class to encode/decode the base and add it to an list array. Consider initial size and load factor.

Hannes
  • 2,018
  • 25
  • 32