What's a sensible way to represent a binary genome for a genetic algorithm?

浪子不回头ぞ 提交于 2019-12-10 15:28:10

问题


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:

  1. 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.
  2. Each bit needs to be individually flippable, to represent spot mutations.
  3. Ideally, it should be easy to take the last X% of two genomes and switch them over (representing crossover).
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!