A gray-coded genetic algorithm represents candidate solutions with Gray-coded chromosomes, where adjacent numerical values differ by one bit. This reduces Hamming cliffs: a single crossover or mutation is less likely to cause a large decoded-value jump or premature convergence. section 8.1
A small encoding example
For decimal values 2 and 3, binary codes are 0010 and 0011, while Gray codes are 0011 and 0010. The neighboring values still differ by one bit, illustrating the smoother genotype-to-phenotype mapping. XOR gates can convert 4-bit binary numbers to Gray codes. section 8.1
Table 8.1 Decimal, binary, and Gray coding (view table figure)
| Decimal number |
Binary code |
Gray code |
|---|---|---|
| 0 |
0000 |
0000 |
| 1 |
0001 |
0001 |
| 2 |
0010 |
0011 |
| 3 |
0011 |
0010 |
| 4 |
0100 |
0110 |
| 5 |
0101 |
0111 |
| 6 |
0110 |
0101 |
| 7 |
0111 |
0100 |
| 8 |
1000 |
1100 |
| 9 |
1001 |
1101 |
| 10 |
1010 |
1111 |
| 11 |
1011 |
1110 |
| 12 |
1100 |
1010 |
| 13 |
1101 |
1011 |
| 14 |
1110 |
1001 |
| 15 |
1111 |
1000 |
Compare decimal values with their binary and Gray representations from 0 through 15. section 8.1
The encoding is useful when binary crossover and mutation can disrupt important high-order bits. It supports smoother search in continuous or discrete optimization settings and appears in applications such as ticket pricing, rotary encoders, and digital-to-analog conversion. section 8.1 section 8.0
