Genetic Algorithm for Solving Simple Mathematical Equality Problem

This paper explains genetic algorithm for novice in this field. Basic philosophy of genetic algorithm and its flowchart are described. Step by step numerical computation of genetic algorithm for solving simple mathematical equality problem will be briefly explained

that the survival of an organism can be maintained through the process of reproduction, crossover and mutation. Darwin's concept of evolution is then adapted to computational algorithm to find solution to a problem called objective function in natural fashion. A solution generated by genetic algorithm is called a chromosome, while collection of chromosome is referred as a population. A chromosome is composed from genes and its value can be either numerical, binary, symbols or characters depending on the problem want to be solved. These chromosomes will undergo a process called fitness function to measure the suitability of solution generated by GA with problem. Some chromosomes in population will mate through process called crossover thus producing new chromosomes named offspring which its genes composition are the combination of their parent. In a generation, a few chromosomes will also mutation in their gene. The number of chromosomes which will undergo crossover and mutation is controlled by crossover rate and mutation rate value. Chromosome in the population that will maintain for the next generation will be selected based on Darwinian evolution rule, the chromosome which has higher fitness value will have greater probability of being selected again in the next generation. After several generations, the chromosome value will converges to a certain value which is the best solution for the problem.

The Algorithm
In the genetic algorithm process is as follows [1]: Step 1. Determine the number of chromosomes, generation, and mutation rate and crossover rate value Step 2. Generate chromosome-chromosome number of the population, and the initialization value of the genes chromosome-chromosome with a random value Step 3. Process steps 4-7 until the number of generations is met Step 4. Evaluation of fitness value of chromosomes by calculating objective function Step 5. Chromosomes selection Step 5. Crossover Step 6. Mutation Step 7. New Chromosomes (Offspring) Step 8. Solution (Best Chromosomes) The flowchart of algorithm can be seen in Figure 1.

Numerical Example
Here are examples of applications that use genetic algorithms to solve the problem of combination.
Suppose there is equality a +2 b +3 c +4 d = 30, genetic algorithm will be used to find the value of a, b, c, and d that satisfy the above equation. First we should formulate the objective function, for this problem the objective is minimizing the value of function f(x) where f (x) = ((a + 2b + 3c + 4d) -30). Since there are four variables in the equation, namely a, b, c, and d, we can compose the chromosome as follow: To speed up the computation, we can restrict that the values of variables a, b, c, and d are integers between 0 and 30.

Step 1. Initialization
For example we define the number of chromosomes in population are 6, then we generate random value of gene a, b, c, d for 6 chromosomes Step 2. Evaluation We compute the objective function value for each chromosome produced in initialization step:

F_obj[1]
= Abs(( 12 + 2*05 + 3*23 + 4*08 ) -30) = Abs((12 + 10 + 69 + 32 ) -30) Step 3. Selection Step 4. Crossover In this example, we use one-cut point, i.e. randomly select a position in the parent chromosome then exchanging sub-chromosome. Parent chromosome which will mate is randomly selected and the number of mate Chromosomes is controlled using crossover_rate (ρc) parameters. Pseudo-code for the crossover process is as follows: After chromosome selection, the next process is determining the position of the crossover point. This is done by generating random numbers between 1 to (length of Chromosome -1). In this case, generated random numbers should be between 1 and 3. After we get the crossover point, parents Chromosome will be cut at crossover point and its gens will be interchanged. For example we generated 3 random number and we get: Then for first crossover, second crossover and third crossover, parent's gens will be cut at gen number 1, gen number 1 and gen number 3 respectively, e.g. Step 5. Mutation

Chromosome[1] =
Number of chromosomes that have mutations in a population is determined by the mutation rate parameter. Mutation process is done by replacing the gen at random position with a new value. The process is as follows. First we must calculate the total length of gen in the population. In this case the total length of gen is total_gen = number_of_gen_in_Chromosome * number of population = 4 * 6 = 24 Mutation process is done by generating a random integer between 1 and total_gen (1 to 24). If generated random number is smaller than mutation_rate(ρm) variable then marked the position of gen in chromosomes. Suppose we define ρm 10%, it is expected that 10% (0.1) of total_gen in the population that will be mutated: