Genetic agorithms are used in optimization and search problems. The idea is that the organisms change in the process of evolution (genetic operations - crossover / mutation) but organisms with better fitness survive.
The description and Simple Generational Genetic Algorithm Pseudocode
can be found at http://en.wikipedia.org/wiki/Genetic_algorithm
In this section genetic algorithm will be implemented in perl for simple optimization problem:
Find the max of eq: y=2000-(x-3)(x-3) We will use bit operation and our x will be coded as N bits number. This number also
called chromosome and number of bits is called chromosome size.
The very first step is random inialization of population of chromosomes.
The following function is used for generating fiffrent events with given probability.
The input is the array of probabilities for each event value. For example we can have the event as the initializaton of bit.
The result of this event can be 0 or 1 in the binary system. If we assume the same probabilities for
bit value equal 0 and 1 then input array will be 0.5,05. In general case in can have more than 2 values and the sum of all values should be = 1.
In this function the random number between 0 and 1 is generated and according to input probabilities the index of the event value that occured
will be returned.
Crossover and mutation
Crossover and mutation are genetic operations in genetic algorithms. In crossover parts of 2 chromosoms are replaced with each other
at random split. In mutation one bit is changed at random. The genetic operations make sure
that algorithm will not stuck at local optimum and will explore for new possible solutions.
Choosing the parents
For each generation we are choosing parents that have the best fitness. There are many different ways
to do this.