A Programming of Genetic Algorithm in Matlab7.0

The genetic algorithm is briefly introduced and its complete programming is provided in detail by MATLAB7.0. In addition, the application in optimization of functions and solution of equation is shown through three examples and the method of avoiding local optimization by increasing the value of pm is also discussed


Introduction of genetic algorithm
Genetic Algorithm (GA) is a global optimization algorithm derived from evolution and natural selection.Although genetic algorithm cannot always provide optimal solution, it has its own advantages (Liu yong, Kang lishan & Chen yuping.1997) and is a powerful tool for solving complex problems (Xi yugeng, Chai tianyou & Yun weimin.1996).
The basic thought of Genetic algorithm: 1) Randomly producing a original population whose number of individuals is a constant N.
2) Producing next generation by crossing over and mutation among individuals.
3) Forming the new population of N individuals from the generation of 2) 4) Producing the next population by repeating the step2) and 3) until obtaining the individual which satisfies conditions.

MATLAB programming for genetic algorithm
In order to understand the sense of the MATLAB programming for genetic algorithm, giving the following instances.
Instance one: seeking the maximum of the function

individual and population
For instance one, ) , , ( is a population of four individuals.In genetic algorithm, the individuals of next population are chosen by the fitting values of individuals, by maintaining the individuals whose fitting values are greater than others.In addition, the fitting values are also as the extermination end condition of genetic algorithm (Liang jiye.1999).And when the fitting values don't continue to increase, exterminating the programming and the individual with the greatest value is seen as the optimal solution.The number of the generation of populations is another termination condition for genetic algorithm.For example, when after 100 generation of population, terminate the programming and the individual with the greatest fitting value in the last generation is as the optimal solution.

encoding
In genetic algorithm, coding is expressing the individual by the binary strings of 0s and 1s.In the instance one, every individual has there dimensions, and every dimension is expressed by a 8-bit string of 0s and 1s, so every individual is expressed as a 24-bit string of 0s and 1s, showing as Programming 1 function pop=encoding(popsize,stringlength,dimension) pop=round(rand(popsize,dimension*stringlength+1)); Programming 1 is an encoding function by MATLAB and it randomly produces an encoded original population.Pop in the function encoding is a matrix whose every row indicates an encoded individual and the total number of rows is denoted as popsize.And dimension is the number of dimension of an individual, stringlength is the number of the bits of binary string of encode individual.In the instance one, dimension=3,stringlength=8.In the programming1 ,the last bit of every row record the fitting value of an individual encoded by this row.

cross-over
Randomly choosing two individuals from pop, and changing the bits of the same section of the two individuals.

mutation
Mutation also simulates biologic evolution mechanism.For the individual to mutate, randomly choose the point to mutate which means the bit of the individual encoded binary string, then change 0 to 1 and change 1 to 0. Pm is the probability of mutation and it is not great in nature and in programming 2, pm=0.05.For every individual, a number of probabilities of mutation are randomly given by the computer.If the giver number is not greater than pm, the individual mutates, otherwise don't mutate.

decoding
Decoding change the encoding binary strings into decimal number, and then computes fitting values for individuals.Decoding is shown as following through instance one above.