Data structure for very large binary data
I'm building a Genetic Algorithm and I was wondering what's a good data structure to use for encoding the chromosomes (essentially a long sequence o开发者_Go百科f 0s and 1s).
I'm aiming for efficiency in changing bits at random within the chromosomes and performing crossovers between chromosomes. Essentially a lot of copying and changing of bits or sub sequences of bits.
So far I'm just stuck with a plain Boolean array but I feel like there should be a better data structure for efficiently handling very large amounts of binary data.
Any suggestions?
Switching to using int primitives to represent groups of binary values and using bitwise operations and masks to change the groups of binary values could gain you large speed increases depending on how you are manipulating data. You could randomly mutate blocks of genes at a time using randomly generated masks.
An array is hard to beat if you are scanning the whole thing or know the index ahead of time. However, copying sections of the array over other sections can be challenging, but its still reasonably efficient.
If you are more concerned with swapping fixed sized groups of genes, building a 2 level tree with n branches with the groups of genes on each leaf would allow you to swap groups of genes very fast. The groups might not need to be the same size either. If you the genes need to be broken up further into chromosomes, you can add an intermediate level to the tree.
精彩评论