I'm currently trying to realize a very simple example of genetic algorithms.
At one point, you have to do a "Cross-Over" (biology) with two numbers (parents) to get a "child".
You can find an explanation of Cross-Over here:
How to "crossover" two strings (1234 & abcd -> 12cd & ab34)
(The second illustration, the easier "one-point" Cross-Over is the one I'm trying to do.)
The chromosomes (parents and child) are numbers but the "Cross-Over" will be a bit operation.
I found a solution for one of the "chromosomes", which is the following :
>>>
operator )<<
operator)So this would keep the end of one of the chromosomes and fill the beginning with 0s.
But I don't really know how to solve the problem of the other chromosome and then also do the Cross-Over.
(Probably a XOR once I kept the beginning / end of the chromosomes and filled the rest with 0s.)
Or should I even approach this problem from another angle?
If the fraction of the Cross-Over is p (e.g., p = .25), then this should work:
mask1 = ((0xffff >> 16*p) << 16*p)
mask2 = 0xffff ^ mask1
output1 = (input1 & mask1) ^ (input2 & mask2)
output2 = (input1 & mask2) ^ (input2 & mask1)
A couple of notes:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With