You are on page 1of 32

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/312087041

An introduction to Genetic Algorithms

Presentation · November 2013


DOI: 10.13140/RG.2.2.33300.91520

CITATION READS

1 1,613

1 author:

Abdellatif Baba
Türk Hava Kurumu Üniversitesi
100 PUBLICATIONS   37 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Genetic algorithm-based technique for predicting future generations of hazelnuts chromosomes. View project

Modeling, identification, and control of 2 DoF robot arm as a prelude study to mimic insects locomotion View project

All content following this page was uploaded by Abdellatif Baba on 05 January 2017.

The user has requested enhancement of the downloaded file.


Artificial Intelligence
An Introduction to Genetic Algorithms

Intelligence can be defined as the "capability of a system to adapt its


behaviour to an ever changing environment"

12/6/2016 ababa@thk.edu.tr 1
Genetic Algo.
• A class of probabilistic optimization algorithms
• Inspired by the biological evolution process
• Uses concepts of "Natural Selection" and "Genetic
Inheritance" (Darwin 1859)
• Originally developed by John Holland (1975)
• Particularly well suited for hard problems where only
a little is known about the underlying search space
• Widely-used in business, science and engineering

12/6/2016 ababa@thk.edu.tr 2
Classes of Search Techniques
Search Techniques

Guided random search Enumerative


Calculus Base
techniqes Techniques
Techniques

Fibonacci Sort DFS Dynamic BFS


Programming

Tabu Search Hill Simulated Evolutionary


Annealing Algorithms
Climbing

Genetic Genetic
Programming Algorithm
Introduction to Genetic Algorithms 3
The main idea
A Genetic Algorithm maintains a population of candidate solutions for the
problem at hand
And
Makes it evolve by iteratively applying a set of stochastic operators

• Selection replicates the most successful solutions


found in a population at a rate proportional to their
relative quality (The concept of fitness appears)
• Recombination decomposes two distinct solutions and
then randomly mixes their parts to form novel
solutions
• Mutation randomly perturbs a candidate solution
Introduction to Genetic Algorithms 4
GA. Principal Conceptions
Chromosomes and Genes

Each chromosome consists of a number of ‘genes’,


and each gene is represented by (0 or 1)

Two fundamental mechanisms make a GA able to solve a


problem Encoding and Evaluation.

is carried out by An evaluation function is used to


representing chromosomes measure the chromosome’s
as strings of ones and zeros performance, or fitness

12/6/2016 ababa@thk.edu.tr 5
GA. Principal Conceptions
Let’s study a simple Example will help us to understand how a GA works.
Let us find the maximum value of the function where parameter x varies
between 0 and 15.
For simplicity, we may assume that x takes only integer values.
Thus, chromosomes can be built with only four genes:

• Suppose that the size of the chromosome population N is 6.


Note: a real practical problem would typically have a population of thousands of chromosomes.
• The fitness function in our example is defined by .
12/6/2016 ababa@thk.edu.tr 6
GA. Principal Conceptions
Example 1
Select randomly 6 chromosomes
Then calculate the fitness of each individual chromosome.

𝐶ℎ𝑟𝑜𝑚𝐹𝑖𝑡𝑛𝑒𝑠𝑠
𝑁
1 𝐶ℎ𝑟𝑜𝑚𝐹𝑖𝑡𝑛𝑒𝑠𝑠

The average fitness of the initial population is 36. In order to improve it, the initial
population is modified by using selection, crossover and mutation, the genetic operators.
12/6/2016 ababa@thk.edu.tr 7
GA. Principal Conceptions
Example 1
Note : the size of the chromosome population remains unchanged from
one generation to the next.
But how can we maintain the size of the population constant, and at the
same time improve its average fitness?

Roulette wheel selection

12/6/2016 ababa@thk.edu.tr 8
Example 1

Selection:
In our example, we have an initial
population of six chromosomes. Thus,
to establish the same population in the
next generation, the roulette wheel
would be spun six times.

• The first two spins might select


chromosomes X6 and X2 to
become parents,
• The second pair of spins might
choose chromosomes X1 and X5,
• And the last two spins might select
chromosomes X2 and X5.
12/6/2016 ababa@thk.edu.tr 9
Example 1

Crossover:
The crossover operator randomly
chooses a crossover point where two
parent chromosomes ‘break’, and then
exchanges the chromosome parts after
that point. As a result, two new
offspring are created. For example,
the chromosomes X6 and X2 could be
crossed over after the second gene in
each to produce the two offspring, as
shown in Figure
12/6/2016 ababa@thk.edu.tr 10
Example 1

Crossover:
• If a pair of chromosomes does not
cross over, then chromosome
cloning takes place.
• A value of 0.7 for the crossover
probability (Pc) generally produces
good results.
• After selection and crossover, the
average fitness of the chromosome
population has improved and gone
from 36 to 42.
12/6/2016 ababa@thk.edu.tr 11
Example 1

Mutation:

• It is equivalent to a random search

• It represents a change in one


randomly selected gene in a
chromosome.

12/6/2016 ababa@thk.edu.tr 12
Example 1

Mutation:
• To guarantee that the search algorithm
is not trapped on a local optimum (The
sequence of selection and crossover operations
may stagnate at any homogeneous set of
solutions. Thus all chromosomes are identical,
and thus the average fitness of the population

cannot be improved)

• Mutation occurs at any gene in a


chromosome with some probability.
The mutation probability is typically
in the range between 0.001 and 0.01.
12/6/2016 ababa@thk.edu.tr 13
Example 1

Note:
GAs assure the continuous improvement of the average fitness of the population, and
after a number of generations (typically several hundred) the population evolves to a
near-optimal solution.
In our example, the final population would consist of only chromosomes 0111 and 1000.
12/6/2016 ababa@thk.edu.tr 14
The algorithm
• Step 1:
1. Represent the problem variable domain as a chromosome of a fixed length,
2. Initialize the size of a chromosome population N, the crossover probability Pc
and the mutation probability Pm.
• Step 2: Define a fitness function to measure the performance, or fitness, of an
individual chromosome in the problem domain.
• Step 3: Randomly generate an initial population of chromosomes of size N
• Step 4: Calculate the fitness of each individual chromosome
• Step 5: Select a pair of chromosomes for mating from the current population. Parent
chromosomes are selected with a probability related to their fitness. (Roulette wheel
selection)
• Step 6: Create a pair of offspring chromosomes by applying the stochastic
operators – crossover and mutation.
• Step 7: Place the created offspring chromosomes in the new population.
• Step 8: Repeat Step 5 until the size of the new chromosome population becomes
equal to the size of the initial population, N.
12/6/2016 ababa@thk.edu.tr 15
The algorithm

12/6/2016 ababa@thk.edu.tr 16
Example 2

In this example suppose it is desired to find the maximum of the "peak" function of
two variables. Where parameters x and y vary between -3 and 3

• The first step is to represent the problem variables as a chromosome.


We represent each parameter (x and y) by eight binary bits:

• Then, we choose the size of the chromosome population, for instance 6, and
randomly generate an initial population.
• The next step is to calculate the fitness of each chromosome. This is done for this
example in two stages.
1. First, a chromosome is decoded by converting it into two real numbers, x and y, in
the interval between -3 and 3.
2. Then the decoded values of x and y are substituted into the "peak" function.
12/6/2016 ababa@thk.edu.tr 17
Example 2

First, a chromosome, that is a string of 16 bits, is partitioned into two 8-bit strings:

x y

Then these strings are converted from binary (base 2) to decimal (base 10):

12/6/2016 ababa@thk.edu.tr 18
Example 2

Now the range of integers that can be handled by 8 bits, that is the range from 0 to 255,
is mapped to the actual range of parameters x and y, that is the range from -3 to 3:

To obtain the actual values of x and y, we multiply their decimal values by 0.0235294
and subtract 3 from the results:

For each x and y the "peak" function will be calculated

12/6/2016 ababa@thk.edu.tr 19
Example 2

Chromosome locations on the surface and contour plot of the ‘peak’ function: (a) initial
population; (b) first generation; (c) local maximum solution; (d) global maximum solution
12/6/2016 ababa@thk.edu.tr 20
Example 2

Performance graphs for 100 generations of six chromosomes: global maximum


solution of the "peak" function

12/6/2016 ababa@thk.edu.tr 21
Case Study : maintenance scheduling with genetic algorithms
Power system components are made to operate continuously throughout their life by
means of preventive maintenance. The purpose of maintenance scheduling is to find the
sequence of outages of power units over a given period of time (normally a year) such that
the security of a power system is maximised.
• Any outage in a power system is associated with some loss in security. The security
margin is determined by the system’s net reserve.
• The net reserve, is defined as "the total installed generating capacity of the system
minus the power lost due to a scheduled outage and minus the maximum load forecast
during the maintenance period." For Example: If we assume that the total installed
capacity is 150MW and a unit of 20MW is scheduled for maintenance during the period
when the maximum load is predicted to be 100MW, then the net reserve will be 30MW.
Conclusion; the maintenance scheduling must ensure that sufficient net reserve is provided
for secure power supply during any maintenance period.
Suppose, there are seven power units to be maintained in four equal intervals. The
maximum loads expected during these intervals are 80, 90, 65 and 70MW. The unit
capacities and their maintenance requirements are presented in the following table:
12/6/2016 ababa@thk.edu.tr 22
Case Study : maintenance scheduling with genetic algorithms

The constraints for this problem can be specified as follows:


• Maintenance of any unit starts at the beginning of an interval and finishes at the end of
the same interval. The maintenance cannot be aborted or finished earlier than
scheduled.
• The net reserve of the power system must be greater than or equal to zero at any
interval.
The optimum criterion here is that the net reserve must be at the maximum during any
maintenance period.
12/6/2016 ababa@thk.edu.tr 23
Case Study : maintenance scheduling with genetic algorithms
Our objective is to represent a complete schedule as a chromosome of a fixed length

The idea:
Assigning to each unit a binary number and to let the chromosome be a sequence
of these binary numbers.
As we have 4 maintenance intervals the unit schedule can be easily represented as
a 4-bit string.
If a unit is to be maintained in a particular interval, the corresponding bit assumes
value 1.
Example: the string 0100 presents a schedule for a unit to be maintained in the
second interval. It also shows that the number of intervals required for
maintenance of this unit is equal to 1.

Thus, a complete maintenance schedule for our problem can be represented as


a 28-bit chromosome, as an example:

12/6/2016 ababa@thk.edu.tr 24
Case Study : maintenance scheduling with genetic algorithms

Traditionally, each gene is represented by only 1 bit and cannot be broken into smaller
elements.

In our example: Problem

• Crossover and mutation operators could create binary strings that call for
maintaining some units more than once and others not at all.
• They could call for maintenance periods that would exceed the number of intervals
really required for unit maintenance.

Solution

Represent a gene by 4 bits


This representation allows crossover and mutation operators to act according to the
theoretical grounding of GAs.
12/6/2016 ababa@thk.edu.tr 25
Case Study : maintenance scheduling with genetic algorithms

The pool of genes for each unit:

The GA can now create an initial population of chromosomes by filling seven gene
chromosomes with genes randomly selected from the corresponding pools

12/6/2016 ababa@thk.edu.tr 26
Case Study : maintenance scheduling with genetic algorithms
Fitness function
The evaluation of a chromosome starts with the sum of capacities
of the units scheduled for maintenance at each interval

12/6/2016 ababa@thk.edu.tr 27
Case Study : maintenance scheduling with genetic algorithms
Fitness function Then these values are subtracted from the total installed capacity of
the power system (in our case, 150MW):

And finally, by subtracting the maximum loads expected at each interval, we obtain the
respective net reserves:

Since all the results are positive, this chromosome does not violate any constraint, and
thus represents a legal schedule.
The chromosome’s fitness is determined as the lowest of the net reserves (20)
12/6/2016 ababa@thk.edu.tr 28
Case Study : maintenance scheduling with genetic algorithms
Crossover and mutation

12/6/2016 ababa@thk.edu.tr 29
To conclude
A typical process of the GA development includes the following
steps:

1. Specify the problem, define constraints and optimum criteria.

2. Represent the problem domain as a chromosome.

3. Define a fitness function to evaluate the chromosome


performance.

4. Construct the genetic operators.

5. Run the GA and tune its parameters.


12/6/2016 ababa@thk.edu.tr 30
To conclude

A larger population can achieve better solutions than a smaller one, but will
work more slowly. In fact, the most effective population size depends on the
problem being solved.

• We could choose a very large population and run it only once.


• We could choose a smaller population and run it several times.

In any case, only experimentation can give us the answer.

12/6/2016 ababa@thk.edu.tr 31
View publication stats

You might also like