Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement selection and crossover in using genetic algorithm to find square root of a number in C

I'm trying to find out square root of a float number using genetic algorithm.
I have initialized population of random numbers and a fitness function. How do I implement selection of parents from population and uniform crossover?

like image 928
Lost Avatar asked Oct 11 '12 07:10

Lost


1 Answers

SELECTION
The function given by gilad (the one you are using) seems fine. Why not just follow a standard procedure ? You can find some ideas on wikipedia

CROSSOVER
If you are considering a candidate as a 32 bit vector (31 actually), then doing a uniform crossover consist in choosing bits of either parent with half probability.

The idea will be :

  • Toss a coin
  • If head take on parent one,
  • If tails take on parent two

Programmatically an efficient way of creating a child from 2 parents will be to generate a random 32 bit number r, and given parents a and b do :

 child = (r & a) | (~r & b);
like image 102
UmNyobe Avatar answered Oct 24 '22 18:10

UmNyobe