Genetic Algorithm
Aim :
To find the global maxima for the stalagmite function using genetic algorithm in MATLAB.
Theory :
What is a Genetic Algorithm?
Genetic Algorithm (GA) is a search-based optimization technique based on the principles of Genetics and Natural Selection. It is frequently used to find optimal or near-optimal solutions to difficult problems which otherwise would take a lifetime to solve. It is frequently used to solve optimization problems, in research, and in machine learning.
The genetic algorithm uses three main types of rules at each step to create the next generation from the current population:
• Selection rules select the individuals, called parents, that contribute to the population at the next generation.
• Crossover rules combine two parents to form children for the next generation.
• Mutation rules apply random changes to individual parents to form children.
How does the Genetic Algorithm Work?
The following outline summarizes how the genetic algorithm works:
-
The algorithm begins by creating a random initial population.
-
The algorithm then creates a sequence of new populations. At each step, the algorithm uses the individuals in the current generation to create the next population. To create the new population, the algorithm performs the following steps:
-
Scores each member of the current population by computing its fitness value. These values are called the raw fitness scores.
-
Scales the raw fitness scores to convert them into a more usable range of values. These scaled values are called expectation values.
-
Selects members, called parents, based on their expectation.
-
Some of the individuals in the current population that have lower fitness are chosen as elite. These elite individuals are passed to the next population.
-
Produces children from the parents. Children are produced either by making random changes to a single parent—mutation—or by combining the vector entries of a pair of parents—crossover.
-
Replaces the current population with the children to form the next generation.
- The algorithm stops when one of the stopping criteria is met.
- The algorithm takes modified steps for linear and integer constraints.
- The algorithm is further modified for nonlinear constraints.
Genetic Algorithm (ga) syntax (used in our program):
1. x=ga (@func, nvars), where "func" is the function name and 'nvars is the number of variables.
2 x=ga (@func, nvars, A, B, Aeq, Beq), a set of lower and upper bounds is given so that the solution lies in that range.
3. x=ga (@func, nvars, A, B, Aeq, Beq, lb, ub, nonlcon, lntCon, options), where
A, B= linear inequality constraints
Aeq, Beq= linear equality constraints
lb=lower bound
ub= upper bound
nonlcon=non-linear constraints
lntcon=vector of positve integers
options=optimisation options
Stalagmite function :
What is a Stalagmite?
A stalagmite is a type of rock formation that rises from the floor of a cave due to the accumulation of material deposited on the floor from celling drippings. Stalagmites may be composed of lava,minerals, mud, peat, pitch,sand, sinter and amber.

Here, in this program, the graph we get looks like hanging stalagmites, that is why it is referred to as stalagmite function.
The equation of stalagmite function is :
`f(x,y)=f_(1,x)f_(2,x)f_(1,y)f_(2,y)`
`f_(1,x)=[sin(5.1pix+0.5)]^6`
`f_(1,y)=[sin(5.1piy+0.5)]^6`
`f_(2,x)=exp[-4ln(2)((x-0.0667)^2)/0.64]`
`f_(2,y)=exp[-4ln(2)((y-0.0667)^2)/0.64]`
Program for Stalagmite Function :
Program for finding Global maxima :
Output :
Study 1:

Study 2:

Study 3:

This point on the peak is called the Global Maxima.
Results and Conclusions:
Hence by using genetic algorithm, we were able to find the Global Maxima point of the stalagmite function.
By default in MATLAB, ga calculates the global minima in order to make it show the global maxima,we add a negative sign to 'f' and 'fopt' everywhere.
Initially, the time required to run the program is long.We can reduce this time by reducing the limits.Decreasing the population size will get more accurate results.