Encoding schemes for genes.
Constructs a Gray code for the specified values, using the minimum number of bits required to encode all of the values.
If the number of values provided is not a perfect square, some codes will
not be used; calling
decode with those values will return
You can find out if this will be the case by calling
mkGrayCode ['a','b','c'] would assign the code
To avoid having unassigned codes, you can repeat a value in the input
list so the example above could be modified to
mkGrayCode ['a','a','b','c'], which would assign the codes
A Gray code maps values to codes in a way that guarantees that the codes for two consecutive values will differ by only one bit. This feature can be useful in evolutionary programming because the genes resulting from a crossover operation will be similar to the inputs. This helps to ensure that offspring are similar to their parents, as any radical changes from one generation to the next are the result of mutation alone.
Encoding and decoding
Returns the value corresponding to a sequence of bits.