问题
My previous question belied my inexperience and was based on an assumption. Now I am much wiser. (Put 1s and 0s in a string? Pah! I laugh at the suggestion!)
My question is then, how should I encode my genomes?
On paper, they look like this:
01010011010110010
17 bits that encode (in some cases singly and in some cases as groups) the parameters to be tested.
The requirements are:
- Needs to be scalable. There might be 17 at the moment, but this could grow/shrink as options are added, removed or have their range modified.
- Each bit needs to be individually flippable, to represent spot mutations.
- Ideally, it should be easy to take the last X% of two genomes and switch them over (representing crossover).
- There must be a straightforward way of representing the genome in plaintext. Here the emphasis is on convenience rather than human translatability. (Think URL shorteners.)
Anyone got any great ideas? (If it's useful, I'm using C#.)
回答1:
Like Andrey said, BitArray is probably your best answer, it meets all your requirements.
1) you can set the number of bits with the constructor
2) it allows you Set (on or off),Or,And,Xor, Not on bits
3) you can loop over your last x% to do crossover
4) there is a ToString that should allow you to output it.
回答2:
BitArray
来源:https://stackoverflow.com/questions/3943858/whats-a-sensible-way-to-represent-a-binary-genome-for-a-genetic-algorithm