L7 Problem Solving n Search p6 Ga Ex
-
Upload
bomezzz-enterprises -
Category
Documents
-
view
21 -
download
0
Transcript of L7 Problem Solving n Search p6 Ga Ex
1
241-320 Design Architecture and Engineeringfor Intelligent System
SuntornSuntorn WitosurapotWitosurapot
Contact Address:Phone: 074 287369 or
Email: [email protected]
November 2009
Lecture 7:Problem Solving and Search – part 6
Informed Search (Genetic Algorithms - Examples)
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 3
Recall: The Evolutionary Cycle of GA
selection
population evaluation
modification
discard
deleted members
parents
modifiedoffspring
evaluated offspring
initiate &evaluate
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 4
Example: Traveling Salesman Problem
Find the shortest distance journey of a givenset of cities so that– each city is visited only once– the total distance traveled is minimized
Assume we know the distancebetween each city
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 5
Problem
This is known to be a hard problem to solve because the number of possible routes is N! where N = the number of cities
There is no simple algorithm that gives the best answer quickly 3,628,800.0010
362,880.009
40,320.008
5,040.007
720.006
120.005
24.004
6.003
2.002
1.001
n!n
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 6
Problem
Design a chromosome encoding, a mutation operation and a crossover function for the Travelling Salesman Problem (TSP)
Assume number of cities N = 8 After all operations the produced chromosomes
should always represent valid possible journeys (visit each city once only)
There is no single answer to this, many different schemes have been used previously
2
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 7
Representation
Representation is an ordered list of citynumbers known as an order-based GA.
1) London 3) Dunedin 5) Beijing 7) Tokyo2) 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)
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 8
Mutating Permutations
Changing just one entry in the permutationwould give an inadmissible solution
Alternative:– Pick two allele values at random– Move the second to follow the first, shifting the
rest along to accommodate– Note that this preserves most of the order and the
adjacency information
1 2 3 4 5 6 7 8 9 1 2 3 45 6 7 8 9
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 9
Crossover operators for permutations “Normal” crossover operators will often lead to
inadmissible solutions, i.e.– Child goes to some cities twice, and – never goes to some cities
Many specialised operators have been devised whichfocus on combining order or adjacency informationfrom the two parents
1 2 3 4 5
5 4 3 2 1
1 2 3 2 1
5 4 3 4 5
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 10
Order 1 Crossover
Idea is to preserve relative order that elements occur Informal procedure:
1. Choose an arbitrary part from the first parent2. Copy this part to the first child3. Copy the numbers that are not in the first part, to
the first child:• starting right from cut point of the copied part,• using the order of the second parent• and wrapping around at the end
4. Analogous for the second child, with parent rolesreversed
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 11
(3 5 7 2 1 6 4 8)Example: Order 1 Crossover (2 5 7 6 8 1 3 4)
Parent1
Parent2
( _ _ 7 2 1 6 _ _ )Child1
3. Copy the numbers thatare not in the first part,to the first child:
• starting right fromcut point of
the copied part ofthe second
parent,• using the order of
the secondparent and
• wrapping aroundat the end
( 3 4 2 5 7 6 8 1 )
( 3 4 2 5 7 6 8 1 )
( 3 4 5 8)
1. Choose an arbitrary part from the 1st parent2. Copy this part to the first child
( 5 8 7 2 1 6 3 4 )Child11
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 12
Crossover
Parent1 (3 5 7 2 1 6 4 8)Parent2 (2 5 7 6 8 1 3 4)
Child1 (5 8 7 2 1 6 3 4)Child2
Crossover combines inversion & recombination:
Q: Can you find the Order1 crossover of Child2 ?
A: (5 2 7 6 8 1 4 3 )
3
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 13
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)
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 14
TSP Example: 30 Cities
0
20
40
60
80
100
120
0 10 20 30 40 50 60 70 80 90 100
x
y
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 15
Solution i (Distance = 941)TSP30 (Performance = 941)
0
20
40
60
80
100
120
0 10 20 30 40 50 60 70 80 90 100
x
y
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 16
Solution j (Distance = 800)TSP30 (Performance = 800)
0
20
40
60
80
100
120
0 10 20 30 40 50 60 70 80 90 100
x
y
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 17
Solution k (Distance = 652)TSP30 (Performance = 652)
0
20
40
60
80
100
120
0 10 20 30 40 50 60 70 80 90 100
x
y
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 18
Best Solution (Distance = 420)TSP30 Solution (Performance = 420)
0
20
40
60
80
100
120
0 10 20 30 40 50 60 70 80 90 100
x
y
4
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 19
Overview of PerformanceTSP30 - Overview o f Pe rform ance
0
200
400
600
800
1000
1200
1400
1600
1800
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31
Ge n e ratio ns (1000)
Dis
tanc
e
Best
Wors t
A verage
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 20
Demo: TSP using Genetic Algorithms Web site: http://www.lalena.com/AI/Tsp/
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 21
Demo: TSP using GA (cont.)
Extract file to a directory Notice the file (Cities.xml)
for the city list
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 22
Demo: TSP using GA: Control Parameters
Population Size: the initial number of random toursthat are created when the algorithm starts.– A large population takes longer to find a result.– A smaller population increases the chance that every
tour in the population will eventually look the same. Group Size / Neighborhood: the number of tours
are chosen from the population in each generation,.– The best 2 tours are the parents. The worst 2 tours
get replaced by the children.– For group size, a high number will increase the
likelyhood that the really good tours will be selected asparents, but it will also cause many tours to never beused as parents.
– A large group size will cause the algorithm to runfaster, but it might not find the best solution.
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 23
Demo: TSP using GA: Control Parameters (cont.)
Mutation % - The percentage that each child after crossover will undergo mutation
# Nearby Cities - As part of a greedy initial population, the GA will prefer to link cities that are close to each other to make the initial tours.
Maximum Generations - How many crossoversare run before the algorithm is terminated.
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 24
Demo: TSP using GA: Algorithms
The GA algorithm of this program does not work on the Order 1 Crossover such as we have learned
It use the alternate links between cities in both directions for each tour
AB
C
D
E
F
5
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 25
Suggested Web Site A recommended tutorials on GA can be found at
http://www.obitko.com/tutorials/genetic-algorithms/example-function-minimum.php
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 26
Suggested Web Site (cont.)Single step feature allows you to see & learn the GA easily
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 27
Change crossover & mutation probabilityMoreover, the effects of crossover and mutation probability for a GA performance can be also seen
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 28
A "Hello World!" Genetic Algorithm Example http://www.generation5.org/content/2003/gahelloworld.asp?Action=
List&Topic=Genetic%20Algorithms See a simple program (~ 138 lines of C++ Code)
Basically, all this does it go through each member of the population and compare it with the target string. It adds up the differences between the characters and uses the cumulative sum as the fitness value (therefore, the lower the value, the better).
241-320 Design Architecture & Engineering for Intelligent System
Problem Solving and Search – part 3 29
Reading
The thai paper named“จีนเนติกอัลกอริทึม” thatcan be downloaded from the LMS website (L6_reading_GA.zip)
บทที่ 12 การคํานวณเชิงวิวัฒนาการ