0

I am using genetic algorithms to determine survival in my Netlogo model, and the ultimate output of the GA is a decimal number between 0 and 1, inclusive. For crossover / mutation purposes, I need to work with gray code rather than binary numbers. I have a function to convert binary to decimal, but not gray code to binary (which I've struggled with).

Any suggestions on how to code a gray code to binary function?

Morwenn
  • 21,684
  • 12
  • 93
  • 152
  • Yours is not eally a NetLogo question. But here's a tutorial: http://www.electrical4u.com/gray-code-binary-to-gray-code-and-that-to-binary-conversion/ – Alan Jun 07 '16 at 10:29
  • There's not really a formula - you need to set up a segmentation into 4 bit sections, convert each of those (with nested ifelse) and then concatenate the converted sections. – JenB Jun 07 '16 at 10:32

1 Answers1

0

Thanks for the above comments.

I did find another solution: the "bitstring: extension for Netlogo. I spoke with the author, and he added a "to-gray" function.

https://github.com/garypolhill/netlogo-bitstring