Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

FAQ: comp.ai.genetic part 6/6 (A Guide to Frequently Asked Questions)
Section - Q21: What are Gray codes, and why are they used?

( Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Sex offenders ]


Top Document: FAQ: comp.ai.genetic part 6/6 (A Guide to Frequently Asked Questions)
Previous Document: News Headers
Next Document: Q22: What test data is available?
See reader questions & answers on this topic! - Help others by sharing your knowledge
     The correct spelling is "Gray"---not  "gray",  "Grey",  or  "grey"---
     since Gray codes are named after the Frank Gray  who  patented  their
     use for shaft encoders in 1953  [1].   Gray  codes  actually  have  a
     longer history, and the inquisitive reader may want to  look  up  the
     August, 1972,  issue  of  Scientific  American,  which  contains  two
     articles of interest: one on the origin  of  binary  codes  [2],  and
     another by Martin  Gardner  on  some  entertaining  aspects  of  Gray
     codes [3].  Other references containing descriptions  of  Gray  codes
     and more modern, non-GA, applications include the second  edition  of
     Numerical  Recipes  [4],  Horowitz  and  Hill  [5],  Kozen  [6],  and
     Reingold [7].

     A Gray code represents  each  number  in  the  sequence  of  integers
     {0...2^N-1} as a binary string of length N  in  an  order  such  that
     adjacent integers have Gray code representations that differ in  only
     one bit position.  Marching through the  integer  sequence  therefore
     requires flipping just one bit at a time.  Some  call  this  defining
     property of Gray codes the "adjacency property" [8].

     Example (N=3):  The binary coding of {0...7} is {000, 001, 010,  011,
     100, 101, 110, 111}, while one Gray coding is {000,  001,  011,  010,
     110, 111, 101, 100}.  In essence, a Gray code takes a binary sequence
     and shuffles  it  to  form  some  new  sequence  with  the  adjacency
     property.  There exist,  therefore,   multiple   Gray   codings   for
     any  given  N.   The example shown here belongs to a  class  of  Gray
     codes that goes by the  fancy  name  "binary-reflected  Gray  codes".
     These  are  the  most  commonly  seen  Gray  codes,  and  one  simple
     scheme  for generationg such a Gray code sequence says,  "start  with
     all  bits zero and successively flip the right-most bit that produces
     a new string."

     Hollstien [9] investigated the use of GAs for optimizing functions of
     two variables and claimed that  a  Gray  code  representation  worked
     slightly better than the binary representation.  He attributed   this
     difference to the adjacency property of Gray codes.   Notice  in  the
     above example that the step from three to four requires the  flipping
     of all the bits in the binary representation.  In  general,  adjacent
     integers in the binary representaion often lie many bit flips  apart.
     This  fact makes it less likely that a MUTATION operator  can  effect
     small changes for a binary-coded INDIVIDUAL.

     A Gray code representation seems to  improve  a  mutation  operator's
     chances of making incremental improvements, and a  close  examination
     suggests why.  In  a  binary-coded  string  of  length  N,  a  single
     mutation in the most significant  bit  (MSB)  alters  the  number  by
     2^(N-1).  In a Gray-coded string, fewer mutations lead  to  a  change
     this large.  The user of Gray codes does, however, pay  a  price  for
     this feature: those "fewer mutations" lead to  much  larger  changes.
     In the Gray code illustrated above, for example, a single mutation of
     the left-most bit changes a zero to a seven and vice-versa, while the
     largest  change a single mutation can make to a corresponding binary-
     coded individual is always four.  One might still view this aspect of
     Gray codes with some favor:  most  mutations  will  make  only  small
     changes, while the occasional  mutation  that  effects  a  truly  big
     change may initiate EXPLORATION of an  entirely  new  region  in  the
     space of CHROMOSOMEs.

     The algorithm for converting between the binary-reflected  Gray  code
     described above  and  the  standard  binary  code  turns  out  to  be
     surprisingly simple to state.  First label the bits of a binary-coded
     string B[i], where larger i's represent more  significant  bits,  and
     similarly label the corresponding Gray-coded string G[i].  We convert
     one to the other as follows:  Copy the most  significant  bit.   Then
     for each smaller i  do  either  G[i] = XOR(B[i+1], B[i])---to convert
     binary to  Gray---or B[i] = XOR(B[i+1], G[i])---to  convert  Gray  to
     binary.

     One may easily implement the above algorithm in C.   Imagine  you  do
     something like

	  typedef unsigned short ALLELE;

     and then use type "allele" for each bit in your chromosome, then  the
     following two functions will convert between  binary  and  Gray  code
     representations.  You must pass them the address  of  the  high-order
     bits for each of the two strings  as  well  as  the  length  of  each
     string.  (See  the  comment  statements  for  examples.)   NB:  These
     functions assume a chromosome arranged  as  shown  in  the  following
     illustration.

     index:    C[9]                                                    C[0]
	       *-----------------------------------------------------------*
     Char C:   |  1  |  1  |  0  |  0  |  1  |  0  |  1  |  0  |  0  |  0  |
	       *-----------------------------------------------------------*
	       ^^^^^                                                 ^^^^^
	       high-order bit                                  low-order bit

 C CODE
     /* Gray <==> binary conversion routines */
     /* written by Dan T. Abell, 7 October 1993 */
     /* please send any comments or suggestions */
     /* to dabell@quark.umd.edu */

     void gray_to_binary (Cg, Cb, n)
     /* convert chromosome of length n+1 */
     /*      from    Gray code Cg[0...n] */
     /*        to  binary code Cb[0...n] */

     allele    *Cg,*Cb;
     int  n;
     {
	  int j;

	  *Cb = *Cg;               /* copy the high-order bit */
	  for (j = 0; j < n; j++) {
	       Cb--; Cg--;         /* for the remaining bits */
	       *Cb= *(Cb+1)^*Cg;   /* do the appropriate XOR */
	  }
     }

     void binary_to_gray(Cb, Cg, n)
     /* convert chromosome of length n+1 */
     /*      from  binary code Cb[0...n] */
     /*        to    Gray code Cg[0...n] */

     allele    *Cb, *Cg;
     int  n;
     {
	  int j;

	  *Cg = *Cb;               /* copy the high-order bit */
	  for (j = 0; j < n; j++) {
	       Cg--; Cb--;         /* for the remaining bits */
	       *Cg= *(Cb+1)^*Cb;   /* do the appropriate XOR */
	  }
     }

     References

     [1]  F.  Gray,  "Pulse  Code  Communication", U. S. Patent 2 632 058,
     March 17, 1953.

     [2] F. G. Heath, "Origins of the Binary  Code",  Scientific  American
     v.227,n.2 (August, 1972) p.76.

     [3]   Martin   Gardner,  "Mathematical  Games",  Scientific  American
     v.227,n.2 (August, 1972) p.106.

     [4] William H. Press, et al., Numerical Recipes in C, Second  Edition
     (Cambridge University Press, 1992).

     [5]  Paul  Horowitz and Winfield Hill, The Art of Electronics, Second
     Edition (Cambridge University Press, 1989).

     [6] Dexter Kozen, The Design and Analysis  of  Algorithms  (Springer-
     Verlag, New York, NY, 1992).

     [7]  Edward  M.  Reingold, et al., Combinatorial Algorithms (Prentice
     Hall, Englewood Cliffs, NJ, 1977).

     [8] David E. Goldberg, Genetic Algorithms  in  Search,  Optimization,
     and Machine Learning (Addison-Wesley, Reading, MA, 1989).

     [9]  R.  B.  Hollstien,  Artificial  Genetic  Adaptation  in Computer
     Control Systems (PhD thesis, University of Michigan, 1971).

     [10] Albert Nijenhuis and Herbert S. Wilf, Combinatorial  Algorithms,
     (Academic Press, Inc., New York, San Francisco, London 1975).

User Contributions:

Get $1000 – $6000 A Day: https://hec.su/lVGm?&nqwer=D1dLXHNih6KQY
How to make $3000 a day: https://hec.su/l0tn?&gcaos=ez6p0l9qS
Bitcoin rate is growing. Become a millionaire. Get a passive income of $ 3,500 per day.: https://hec.su/nI6E?&qnoht=iQVr9
BuyEssayClub | Buy Essay Papers Online: https://vk.cc/9OTGak?id=buyessayonline1129nv
Buy Essay Online At Writing Service from Canada: https://vk.cc/9OTGak?id=buyessayonline1131p2
Buy Essay Online At Writing Service from Canada: https://vk.cc/9OTGak?id=buyessayonline111lir
BuyEssayClub | Buy Essay Papers Online: https://vk.cc/9OTGak?id=buyessayonline112os9
Find yourself a girl for the night in your city: https://bogazicitente.com/bestsexygirls357413?u=im
The best girls for sex in your town: https://is.gd/sexygirlsinyourcity28232?u=ch
These Are The Best Sex Apps For No Strings Attached Sex: https://jtbtigers.com/bestsexygirls595902?u=kj
Meet sexy girls in your city: https://ecuadortenisclub.com/bestsexygirls741435?u=31
Best Dating Apps 2019: https://ecuadortenisclub.com/bestsexygirls741435?u=2x
10 Best Sex Dating Sites (100% Free): https://fla.kr/bestsexygirls107078?u=4d
Adult Dating Site, Meet and Fuck - 445 girls want to meet for sex in your city: https://bestsexygirlsinyourcity.blogspot.tw?j=64
Single girls want sex in your city (447 beautiful girls want sex in your city right now): https://1borsa.com/adultdatingsex21747?s=7328
How to find a woman for casual sex (554 women want to meet for sex in your city): https://bestadultdatingsite999.blogspot.it?z=34
Sex Dating Sites - Online Adult Dating - 541 beautiful girls want sex in your city right now: https://bestadultdatingsite999.blogspot.de?h=01
#1 Adult Sex Dating App - 143 beautiful women want sex in your city right now: https://the-best-adult-dating-sites.blogspot.com.au?d=63
Meet for Sex - Find Sex Tonight, Free Fuck Sites - 719 girls want to meet for sex in your city: https://adultdating-sites777.blogspot.co.uk?f=55
Meet a sexy girl right now (558 girls want to meet for sex in your city): https://links.wtf/NH73?i=8949
Adult Dating Site, Meet and Fuck - 164 girls want to meet for sex in your city: https://the-best-adult-dating-sites.blogspot.com.br?h=41
Women are looking for sex in your city (468 girls want to meet for sex in your city): https://the-best-adult-dating-sites.blogspot.com.ar?c=99
Wie man 0,78 BTC pro Woche macht: https://make5btcperweek.blogspot.ie?u=02
Genau wie wГјrden Sie mit Sicherheit 6537 US-Dollar einsetzen, um mehr Geld zu verdienen?: https://10-btc-per-week.blogspot.ie?t=632
Paid Surveys: Make $9135 Or More Each week: https://7-btc-per-day.blogspot.co.uk?c=290
How to Make $5799 FAST, Quick Cash, The Busy Budgeter: https://earn1btcperdayy.blogspot.gr?u=80
Just how would certainly you make use of $86563 to make more cash: https://make-5-btc-perweek.blogspot.ro?c=99
How to invest in Bitcoin and receive from $ 8994 per day: https://get-2-btc-perday.blogspot.fr?q=28
Just how would you use $78353 to make more loan: https://onlineuniversalwork.com/earnonebtc368010?i=1136
How to Make $9626 FAST, Quick Loan, The Busy Budgeter: https://hideuri.com/KGRoJ1?&eiobg=bLGRhqg8E78r
Exactly how would certainly you use $75381 to make more money: https://cutt.us/dUSpW1R?VoGv0ewk4lh
Paid Studies: Make $8858 Or More Weekly: https://cutt.us/NXb9BT?YYXTiyb2r0
Binary options + Cryptocurrency = $ 4493 per week: https://soo.gd/uGVjo?&rtfvw=eVHII
Paid Surveys: Earn $6131 Or More Per Week: https://cutt.us/TdlXNKi?immdbsvr2GtfC
Just how to Make $5197 FAST, Fast Loan, The Busy Budgeter: https://soo.gd/ejy9?fnJto
How to make $ 5733 per day: https://soo.gd/Uxpm?&bxqyi=G0iYUbCQMUrb
Invest $ 65218 in Bitcoin once and get $ 242513 passive income per month: https://soo.gd/YnggI?0xdy5mrg7FtOn
How to invest in Cryptocurrency $ 31292 - get a return of up to 8716%: https://cutt.us/QHnNLOx7V?JT03TPYKMDJFu
Your account has accumulated $914326,98: https://soo.gd/UpFF
Sex Websites for Meeting Singles, Adult Dating Sites - 742 beautiful girls want sex in your city right now: https://slimex365.com/yfm1
Sex Dating Sites - Online Adult Dating - 631 women want to meet for sex in your city: https://slimex365.com/yfdu
Free Adult Dating & Sex Hookups - 725 beautiful women want sex in your city right now: https://links.wtf/rdAD
How to invest in Bitcoin and receive from $ 4497 per day: https://jtbtigers.com/wqae
Just how to Make $8268 FAST, Fast Money, The Busy Budgeter: https://jtbtigers.com/wnrq
What's the simplest way to gain $83429 a month: https://links.wtf/Kalw
Paid Studies: Make $5364 Or More Weekly: https://ecuadortenisclub.com/wnmf
Invest $ 39849 in Bitcoin once and get $ 653544 passive income per month: https://jtbtigers.com/wq3n
How to invest in Bitcoin and receive from $ 9686 per day: https://bogazicitente.com/x5ha
How to get $ 9333 per day: https://jtbtigers.com/wq4f
Binary options + Cryptocurrency = $ 9889 per week: https://fla.kr/rCsr
Paid Studies: Make $7774 Or More Per Week: https://fla.kr/rCjf
Forex + Cryptocurrency = $ 9163 per week: https://links.wtf/KSfv
Invest $ 9811 and get $ 26859 every month: https://fla.kr/rBm3
Just how to Make $6628 FAST, Rapid Loan, The Busy Budgeter: https://darknesstr.com/wxng
Invest $ 99458 in Bitcoin once and get $ 264919 passive income per month: https://bogazicitente.com/x5r5
Invest $ 69465 in Cryptocurrency once and get $ 743496 passive income per month: https://ecuadortenisclub.com/earnonebitcoinperday63756
Paid Surveys: Make $5589 Or Even more Weekly: https://links.wtf/oLOc
injectable drug for erectile dysfunction https://alprostadildrugs.com/ buy muse alprostadil urethral suppository
sildenafil pfizer https://eunicesildenafilcitrate.com/ sildenafil 25
https://ingogf.com/ - female viagra name in pakistan
Thank you for the good writeup. It in reality was a amusement account it. Glance complex to more brought agreeable from you! However, how could we keep up a correspondence?
hydroxychloroquinine https://plaquenilx.com/# hydroxychloroquine tablet
you are in point of fact a good webmaster. The web site loading speed is amazing. It sort of feels that you are doing any unique trick. Also, The contents are masterpiece. you have done a wonderful task on this subject! slitet h&aring;r efter blekning jado.teswomango.com/map25.php
62
Jan 14, 2022 @ 3:03 am
"May I just say what a comfort to uncover someone that really understands what they are talking about on the web. You actually know how to bring an issue to light and make it important. A lot more people need to check this out and understand this side of the story. It's surprising you are not more popular given that you certainly have the gift."
https://tinyurl.com/y7h69pcq
63
May 3, 2022 @ 2:02 am
"This is the perfect website for anybody who hopes to understand this topic. You realize a whole lot its almost hard to argue with you (not that I personally will need toÖHaHa). You definitely put a brand new spin on a subject that has been discussed for decades. Excellent stuff, just great!"
https://delhiescortss.com/%D7%97%D7%91%D7%99%D7%9C%D7%95%D7%AA-%D7%A1%D7%A4%D7%90-%D7%9E%D7%A4%D7%A0%D7%A7%D7%95%D7%AA-%D7%91%D7%93%D7%A8%D7%95%D7%9D-%D7%A1%D7%A4%D7%90-%D7%A4%D7%9C%D7%95%D7%A1/
64
May 5, 2022 @ 9:09 am
"Next time I read a blog, Hopefully it won't disappoint me just as much as this particular one. After all, I know it was my choice to read, nonetheless I really believed you'd have something interesting to talk about. All I hear is a bunch of moaning about something you can fix if you were not too busy searching for attention."
https://rokslides.com/%d7%a2%d7%99%d7%a1%d7%95%d7%99-%d7%98%d7%a0%d7%98%d7%a8%d7%99-%d7%a2%d7%91%d7%95%d7%93%d7%aa-%d7%a2%d7%95%d7%9e%d7%a7-%d7%a2%d7%9d-%d7%94%d7%92%d7%95%d7%a3/
65
Jun 17, 2022 @ 3:03 am
"The very next time I read a blog, I hope that it does not fail me as much as this one. After all, Yes, it was my choice to read, but I truly thought you'd have something interesting to say. All I hear is a bunch of whining about something that you could fix if you were not too busy searching for attention."
https://lover-israil-graf.gq/news/spathathcaro
66
Sep 27, 2022 @ 2:02 am
stx21 Sist Swalley silled pokoje pracownicze nieopodal suwalk noclegi augustow agroturystyka noclegi wojciech augustow noclegi augustow jezioro biale w augustowie
67
reshma
Jan 29, 2023 @ 4:04 am
sonakshiurmil.com - Indore escorts services in Indore.
68
reshma
Jan 29, 2023 @ 4:04 am
aradhyakhanna.com || kumaripammisingh.com || nituparnadas.com ||
69
reshma
Jan 29, 2023 @ 4:04 am
nituparnadas.com/about-goa-call-girls-theory.html || escortsgoafemales.com || escortsgoafemales.com/about-call-girls-goa.html || shilpyrohilla.com || goaescortssapna.com || goaescortssapna.com/goa-escorts.html || hyderabadescortsservicegirl.com || hyderabadescortsservicegirl.com/best-call-girls-in-hyderabad.html || escortsservicehyderabad.com || escortsservicehyderabad.com/hyderabad-call-girls.html || mumbaiescortsrani.com || alinamalhotra.com || vanitachopra.com ||
70
reshmaroy
Feb 7, 2023 @ 3:03 am
There was a time when most people were scared to hire call girls in Goa. Because people used to think that the experience of joy like that of their wife or girlfriend cannot be found with call girls in Goa. In modern times professionally trained girls have done this. If you are a good-thinking man towards call girls women then you can understand what the truth is. A girlfriend also has the same wish that her boyfriend should be very loving. A girlfriend wants her boyfriend to go on outings with her, take her shopping, and not be afraid to spend money. Take care of her in every way. By giving so much love and respect, the boyfriend gets respect and love from his girlfriend. A girlfriend gives mental and physical pleasure to her boyfriend. This exchange is considered very well in the modern environment. This is the real girlfriend experience that you can get with call girls in Goa. All you need is to love your chosen call girl as much as your real-life girlfriend and spend money on her. You can expect great company with call girls in Goa. Only in your heart, you should have the courage to love an unknown girl like a boyfriend and spend money on her wishes. If you can do that much with intimacy then you deserve a guaranteed girlfriend-like experience with call girls in Goa. shilpyrohilla.com
71
reshmaroy
Feb 13, 2023 @ 7:07 am
https://sapnaranaut.hatenablog.com/entry/2023/02/08/202333
https://sapnaranaut.hatenablog.com/entry/2023/02/12/005103
https://sapnaranaut.hatenablog.com/entry/2023/02/10/042933
https://sapnaranaut.hatenablog.com/entry/2023/02/13/073142
https://sapnaranaut.hatenablog.com/entry/2023/02/11/024301
https://sapnaranaut.hatenablog.com/entry/2023/02/07/201048
https://sapnaranaut.hatenablog.com/entry/2023/02/12/182424
https://sapnaranaut.hatenablog.com/entry/2023/02/11/173845
72
reshmaroy
Jun 10, 2023 @ 12:12 pm
We are a youthful organization of call girls in Indore for your physical and mental fun. If you are looking for a high-profile escort service within your pocket budget, we can fulfill your dreams according to your expectations. Our professional escorts can help you out with our Indore escorts agency. Giving extra fun within budget is our introduction, and genuine Indore call girl service is evidence of our professional services. Incall and outcall services are handled by experienced, educated call girls in Indore. kumaripammisingh.com

Comment about this article, ask questions, or add new information about this topic:




Top Document: FAQ: comp.ai.genetic part 6/6 (A Guide to Frequently Asked Questions)
Previous Document: News Headers
Next Document: Q22: What test data is available?

Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
David.Beasley@cs.cf.ac.uk (David Beasley)





Last Update March 27 2014 @ 02:11 PM