Figure Above: Biological Inspiration of Genetic Algorithm
Figure Above: Biological Inspiration of Genetic Algorithm
7. Fitness Function : A fitness function simply defined is a function which takes the solution as
input and produces the suitability of the solution as the output. In some cases, the fitness function and
the objective function may be the same, while in others it might be different based on the problem.
8. Genetic Operators :These alter the genetic composition of the offspring. These include
crossover, mutation, selection, etc.
Q4.Demonstrate implementation of strategy of different phases involved in genetic
algorithm.
Answer-: The genetic algorithm is an optimization algorithm inspired by the biological
evolution process. Five phases are considered in a genetic algorithm:
a. Initial population
b. Fitness function
c. Selection
d. Crossover
e. Mutation
Initial Population: This process begins with a group of individuals called a Population. Each
individual is a solution to the problem they want to solve. Individuals are characterized by a set
of parameters (variables) called genes. Genes are joined into a string to form chromosomes
(solutions). In a genetic algorithm, an individual's gene set is represented by a string. Binary
values are usually used (strings of 1's and 0's). We say that chromosomes encode genes.
Fitness Function: A fitness function determines an individual’s fitness (the ability to compete
with others). This will give you a fitness score for each individual. An individual's likelihood of
being selected for reproduction is based on its fitness score.
Selection: The idea of the selection stage is to select the most suitable individuals and pass their
genes on to the next generation. Based on the fitness score he will be selected two pairs of
individuals (parents). Individuals with higher fitness are more likely to be selected for
reproduction.
Reproduction : Generation of offspring happen in 2 ways :
I. Crossover: Crossover is the most important phase in genetic algorithms. Crossovers are
randomly chosen within the gene of each pair of mating parents. There are three major
types of crossover : 1.Single point crossover 2.Two point crossover 3.Uniform
crossover
II. Mutation: Certain newly formed offspring have a low probability of mutating part of the
gene. This means that some bits in a bitstring can be flipped.
Q5. Give a road map how genetic algorithm can be applied to solve a problem Knapsack
Problem(0/1)?
Answer-: Creating one a generation after another continuous until we hit a termination
condition. Post which fittest solution is our high-quality solution to the problem. We take the
example of the knapsack problem and then to solve it using genetic algorithm.
Knapsack using Genetic Algorithm: We have a knapsack that cam hold 15 kg of weight at max.
We have 4 items A, B, C and D; having weights of 7kg, 2 kg, 1 kg ad 9kg and values $5, $4, $7
and $2 respectively. Lets see how we find high-quality solution to this knapsack problem using
Genetic Algorithm and understand each step of it.
Individual Representation: An individual in the Genetic Algorithm is a potential solution. We
first find a way to represent it such that it allows us to evolve. For our knapsack problem, this
representation pretty simple and straightforward; every individual is an n-bit string where each
bit correspond to an item from the n items we have.
Picking individuals: Every single individual is a potential solution to the knapsack problem.
Hence, for the knapsack problem, from a search space of 2πm,we pick a few individuals
randomly.
Fitness Coefficient: The fitness coefficient of an individual completely depends on the problem
at hand, if and if implemented poorly or incorrectly, it can result in misleading data or
inefficiencies. The value the fitness coefficient typically lies in the range 0 to 1 but not a
mandate.
For our, knapsack problem, we can define the fitness co-efficient of an individual as the
summation of the values of the items picked in the knapsack as per the bit string of the total
weight of the picked items is less than the weight knapsack can hold. The fitness coefficient of
an individual is 0 if the total weight of the item picked is greater than the weight that the
knapsack can hold.