0% found this document useful (0 votes)
27 views50 pages

CS632 Lecture 07

The document discusses genetic algorithms. It explains that genetic algorithms are adaptive heuristic search algorithms inspired by Darwinian evolution. They use techniques like mutation, crossover, and selection to evolve solutions to problems iteratively. The document provides examples of how genetic algorithms can be used to solve optimization problems like the traveling salesman problem by representing possible solutions as chromosomes and evolving the population toward better solutions over multiple generations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views50 pages

CS632 Lecture 07

The document discusses genetic algorithms. It explains that genetic algorithms are adaptive heuristic search algorithms inspired by Darwinian evolution. They use techniques like mutation, crossover, and selection to evolve solutions to problems iteratively. The document provides examples of how genetic algorithms can be used to solve optimization problems like the traveling salesman problem by representing possible solutions as chromosomes and evolving the population toward better solutions over multiple generations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 50

ARTIFICIAL

INTELLIGENCE

GENETIC ALGORITHMS

CS-632

Dr. Ghulam Mustafa

University Institute of Information Technology


PMAS-Arid Agriculture University Rawalpindi
WHAT ARE GENETIC ALGORITHMS?
• Genetic Algorithms (GAs) are adaptive heuristic search algorithm
based on the evolutionary ideas of natural selection in genetics.

• As such they represent an intelligent exploitation of a random search


used to solve optimization problems.

• Exploit historical information to search into the region of better


performance within the search space.

• Follow the principles first laid down by Charles Darwin of "survival of


the fittest.". Since in nature, competition among individuals for scanty
resources results in the fittest individuals dominating over the weaker
ones.
WHY GENETIC ALGORITHMS?
• It is better than conventional AI in that it is more robust.

• Unlike older AI systems, they do not break easily even if the


inputs changed slightly, or in the presence of reasonable noise.

• In large state-space, multi-modal state-space, or n-dimensional


surface, a genetic algorithm may offer significant benefits over
more typical search of optimization techniques. For example,
linear programming, heuristic, depth-first, breath-first.
GENETIC ALGORITHMS OVERVIEW
• GAs simulate the survival of the fittest among individuals over consecutive
generation for solving a problem.
• Each generation consists of a population of character strings that are
analogous to the chromosome that we see in our DNA.
• Each individual represents a point in a search space and a possible solution.
The individuals in the population are then made to go through a process of
evolution.
• GAs are based on an analogy with the genetic structure and behavior of
chromosomes within a population of individuals using the following
foundations:
• Individuals in a population compete for resources and mates.
• Successful individuals in each 'competition' will produce more offspring than those
individuals that perform poorly.
• Genes from `good' individuals propagate throughout the population so that two good
parents will sometimes produce offspring that are better than either parent.
• Thus, each successive generation will become more suited to their environment.
IMPLEMENTATION DETAILS
After an initial population is randomly generated, the algorithm
evolves through three operators:

• Selection, which equates to survival of the fittest;


• Crossover, which represents mating between individuals;
• Mutation, which introduces random modifications.
SELECTION OPERATOR
• Key idea: give preference to better individuals, allowing them to
pass on their genes to the next generation.

• The goodness of each individual depends on its fitness.

• Fitness may be determined by an objective function or by a


subjective judgement.
CROSSOVER OPERATOR
• Prime distinguished factor of GA from other optimization techniques
• Two individuals are chosen from the population using the selection
operator
• A crossover site along the bit strings is randomly chosen
• The values of the two strings are exchanged up to this point
• If S1=000000 and S2=111111 and the crossover point is 2 then
S1'=110000 and S2'=001111
• The two new offspring created from this mating are put into the next
generation of the population
• By recombining portions of good individuals, this process is likely to
create even better individuals
CROSSOVER OPERATOR (CONT.)
Order 1 Crossover is a fairly simple permutation crossover. Basically, a swath
of consecutive alleles from parent 1 drops down, and remaining values are
placed in the child in the order which they appear in parent 2.
Parent 1: 8 4 7 3 6 2 5 1 9 0
Parent 2: 0 1 2 3 4 5 6 7 8 9
Child 1: 0 4 7 3 6 2 5 1 8 9

Step 1: Select a random swath of consecutive alleles from parent 1.


(underlined)
Step 2: Drop the swath down to Child 1 and mark out these alleles in Parent
2.
Step 3: Starting on the right side of the swath, grab alleles from parent 2 and
insert them in Child 1 at the right edge of the swath. Since 8 is in that position
in Parent 2, it is inserted into Child 1 first at the right edge of the swath. Notice
that alleles 1, 2 and 3 are skipped because they are marked out and 4 is
inserted into the 2nd spot in Child 1.
Step 4: If you desire a second child from the two parents, flip Parent 1 and
Parent 2 and go back to Step 1.
MUTATION OPERATOR
• With some low probability, a portion of the new individuals will
have some of their bits flipped.
• Its purpose is to maintain diversity within the population and inhibit
premature convergence.
• Mutation alone induces a random walk through the search space
• Mutation and selection (without crossover) create a parallel, noise-
tolerant, hill-climbing algorithms
EFFECTS OF GENETIC OPERATORS
• Using selection alone will tend to fill the population with copies of
the best individual from the population.

• Using selection and crossover operators will tend to cause the


algorithms to converge on a good but sub-optimal solution.

• Using mutation alone induces a random walk through the search


space.

• Using selection and mutation creates a parallel, noise-tolerant,


hill climbing algorithm
THE ALGORITHMS

1. randomly initialize population(t)


2. determine fitness of population(t)
3. repeat
1. select parents from population(t)
2. perform crossover on parents creating population(t+1)
3. perform mutation of population(t+1)
4. determine fitness of population(t+1)

4. until best individual is good enough


INITIAL POPULATION

https://www.youtube.com/watch?v=ejxfTy4lI6I
60 %
60 %

25 %

15 %
60 %

25 %

15 %
60 %

25 %

15 %
60 %

25 %

50
15 %
%
A Simple Example

The Traveling Salesman Problem:

Find a tour of a given set of cities so that


– each city is visited only once
– the total distance traveled is minimized

21
Representation

Representation is an ordered list of city


numbers known as an order-based GA.
1) London 3) Dunedin 5) Beijing 7) Tokyo
2) Venice 4) Singapore 6) Phoenix 8) Victoria

CityList1 (3 5 7 2 1 6 4 8)
CityList2 (2 5 7 6 8 1 3 4)

22
Crossover

Crossover combines inversion and


recombination:
* *
Parent1 (3 5 7 2 1 6 4 8)
Parent2 (2 5 7 6 8 1 3 4)

Child (5 8 7 2 1 6 3 4)

This operator is called the Order1 crossover.


23
Mutation

Mutation involves reordering of the list:

* *
Before: (5 8 7 2 1 6 3 4)

After: (5 8 6 2 1 7 3 4)

24
TSP Example: 30 Cities

120

100

80

y 60

40

20

0
0 10 20 30 40 50 60 70 80 90 100
x

25
Solution i (Distance = 941)
TSP30 (Performance = 941)

120

100

80

y 60

40

20

0
0 10 20 30 40 50 60 70 80 90 100
x

26
Solution j (Distance = 800)
44
62 TSP30(Performance =800)
69
67 120
78
64 100
62
54
80
42
50
40 y 60
40
38 40
21
35
20
67
60
60 0

40 0 10 20 30 40 50 60 70 80 90 100
42 x
50
99

27
Solution k (Distance = 651)

TSP30 (Performance = 652)

120

100

80

y 60

40

20

0
0 10 20 30 40 50 60 70 80 90 100
x

28
Best Solution (Distance = 420)
42
38 TSP30 Solution (Performance = 420)
35
120
26
21
35 100
32
7 80
38
46
44 y 60
58
60 40
69
76
20
78
71
69 0

67 0 10 20 30 40 50 60 70 80 90 100
62 x
84
94

29
Thank You

You might also like