This talk will introduce into programming with evolutionary algorithms.
We'll build and/or discover a small framework for creating genetic
algorithms.
Genetic algorithms are good to solve certain kind of algorithmic
problems.
The talk will also give a rough picture about situations where
evolutionary programming might be the right solution.
Especially np hard problems like the traveling sales man problem (TSP) or
the rucksack problem are well known combinatoric problems (such as
distributing vservers across a number of vserver-hosts).
4. About me
Julian Fischer
‣Twitter: http://www.twitter.com/railshoster
‣E-Mail: fischer@enterprise-rails.de
5. About me
Julian Fischer
‣Twitter: http://www.twitter.com/railshoster
‣E-Mail: fischer@enterprise-rails.de
‣ CEO of Avarteq GmbH
6. About me
Julian Fischer
‣Twitter: http://www.twitter.com/railshoster
‣E-Mail: fischer@enterprise-rails.de
‣ CEO of Avarteq GmbH
‣ Lecturer „Ruby on Rails“ @ HTWdS
7. About me
Julian Fischer
‣Twitter: http://www.twitter.com/railshoster
‣E-Mail: fischer@enterprise-rails.de
‣ CEO of Avarteq GmbH
‣ Lecturer „Ruby on Rails“ @ HTWdS
‣ Ruby und Ruby on Rails programmer
8. About me
Julian Fischer
‣Twitter: http://www.twitter.com/railshoster
‣E-Mail: fischer@enterprise-rails.de
‣ CEO of Avarteq GmbH
‣ Lecturer „Ruby on Rails“ @ HTWdS
‣ Ruby und Ruby on Rails programmer
‣ Entperise-Rails.de - Head of Hosting
12. About Avarteq GmbH
‣ Founded in Nov. 2008
from two existing companies.
‣ Involvment of Key-Systems GmbH
manages ~2,5 * 10^6 domains for customers of 200+ countries.
13. About Avarteq GmbH
‣ Founded in Nov. 2008
from two existing companies.
‣ Involvment of Key-Systems GmbH
manages ~2,5 * 10^6 domains for customers of 200+ countries.
‣ Team size: 14 people
8 full-time, 6 part-time/freelancer
18. About Avarteq GmbH
‣ Covers all stages of web development
‣ Consulting
‣ Conceptual ~ and screen design
19. About Avarteq GmbH
‣ Covers all stages of web development
‣ Consulting
‣ Conceptual ~ and screen design
‣ Ruby&onplace. development.
In house in
Rails
20. About Avarteq GmbH
‣ Covers all stages of web development
‣ Consulting
‣ Conceptual ~ and screen design
‣ Ruby&onplace. development.
In house in
Rails
‣ Ruby on Rails
hosting/servers/clusters
RailsHoster.de - Enterprise-Rails.de
26. Evolution
‣ Population of individuals (organisms)
‣ Genes are passed from generation to
generation.
‣ Slightgeneration to thein genetic material
from one
changes
next.
27. Evolution
‣ Population of individuals (organisms)
‣ Genes are passed from generation to
generation.
‣ Slightgeneration to thein genetic material
from one
changes
next.
‣ Differences accumulate over time.
28. Evolution
‣ Population of individuals (organisms)
‣ Genes are passed from generation to
generation.
‣ Slightgeneration to thein genetic material
from one
changes
next.
‣ Differences accumulate over time.
‣ New properties or even species emerge.
33. Evolution
‣ Basic genetic operations
‣ Mutation of genetic material.
Random changes
‣ Recombination of two individuals.
Recombine genetic material
34. Evolution
‣ Basic genetic operations
‣ Mutation of genetic material.
Random changes
‣ Recombination of two individuals.
Recombine genetic material
‣ also known as sexual reproduction
42. Evolution
‣ Changing environment and a lot of other changing
temperature, energy resources, competitors
and moving stuff, ...
‣ Huge search space countless possible individuals.
vast amount of dna combinations,
43. Evolution
‣ Changing environment and a lot of other changing
temperature, energy resources, competitors
and moving stuff, ...
‣ Huge search space countless possible individuals.
vast amount of dna combinations,
‣ Restricted resources
Death = release of allocated resources.
46. Evolution
‣ Which combinations to create as an
individual?
‣ Only validthey usually don‘t breed a banana plant but another
If two dogs breed
individuals
dog, instead!
47. Evolution
‣ Which combinations to create as an
individual?
‣ Only validthey usually don‘t breed a banana plant but another
If two dogs breed
individuals
dog, instead!
‣ Preserve good gene materialetc. have a lot of
Maybe that‘s why rockstars, football champions,
girlfriends?! Hey, I am a Ruby programmer, that‘s also awesome!
48. Evolution
‣ Which combinations to create as an
individual?
‣ Only validthey usually don‘t breed a banana plant but another
If two dogs breed
individuals
dog, instead!
‣ Preserve good gene materialetc. have a lot of
Maybe that‘s why rockstars, football champions,
girlfriends?! Hey, I am a Ruby programmer, that‘s also awesome!
‣ Improve! but even improve what‘s good and make it better!
Not only preserve
61. Genetic Algorithms
‣ Generation = Nr. of individuals
‣ Individualbut a valid problem solution
maybe a bad one
=
valid.
‣ Individuals constist of genes
62. Genetic Algorithms
‣ Generation = Nr. of individuals
‣ Individualbut a valid problem solution
maybe a bad one
=
valid.
‣ Individuals constist of genes
‣ Individuals havethe individual (good .. badfitness
indicating the worthiness of
a well known
solution).
71. Genetic Algorithms
‣ Start with a first individual (genesis)
‣ Create 2nd individual through mutation
‣ Randomly/Statistically choose a genetic
operation to create new individuals
74. Genetic Algorithms
‣ If a generation is full create a new one
‣ Select fittest individuals to be passed in to
the next generation.
75. Genetic Algorithms
‣ If a generation is full create a new one
‣ Select fittest individuals to be passed in to
the next generation.
‣ Repeat the process until we have an
acceptable solution or hit a given
boundary.
81. Traveling Salesman
‣ A salesman needs to travel to n cities
‣ Each city needs to be visited once
82. Traveling Salesman
‣ A salesman needs to travel to n cities
‣ Each city needs to be visited once
‣ The salesman wants to end where he
started.
83. Traveling Salesman
‣ A salesman needs to travel to n cities
‣ Each city needs to be visited once
‣ The salesman wants to end where he
started.
‣ The route should be minimal.
88. Traveling Salesman
‣ TSP can be applied to many scenarios:
‣ (Flight) planning, logistics, ...
‣ Manufactoring of microchips
89. Traveling Salesman
‣ TSP can be applied to many scenarios:
‣ (Flight) planning, logistics, ...
‣ Manufactoring of microchips
‣ Slightly modified in DNA sequencing
90. Traveling Salesman
‣ TSP can be applied to many scenarios:
‣ (Flight) planning, logistics, ...
‣ Manufactoring of microchips
‣ Slightly modified in DNA sequencing
‣ ...
94. Traveling Salesman
‣ What‘s the deal about it?
‣ Problem of combinatorical optimization
‣ Not a shortest path problem!
95. Traveling Salesman
‣ What‘s the deal about it?
‣ Problem of combinatorical optimization
‣ Not a shortest path problem!
‣ Computational complexity:
np complete
nondeterministic polynomial time
120. TSP Fitness
‣ Shuffle mutation
‣ Completely shuffle the order of cities in
the roundtrip
121. TSP Fitness
‣ Shuffle mutation
‣ Completely shuffle the order of cities in
the roundtrip
‣ 1-3-5-4-2 → 3-5-1-2-4
122. TSP Fitness
‣ Shuffle mutation
‣ Completely shuffle the order of cities in
the roundtrip
‣ 1-3-5-4-2 → 3-5-1-2-4
‣ (-) Doesn‘t rely on existing individuals
123. TSP Fitness
‣ Shuffle mutation
‣ Completely shuffle the order of cities in
the roundtrip
‣ 1-3-5-4-2 → 3-5-1-2-4
‣ (-) Doesn‘t rely on existing individuals
‣ Not a slightly but a massive change
137. Cycle Crossover
‣ Pass randomly choosen parts from the
the parents to the offsprings
‣ Creates two offsprings
138. Cycle Crossover
‣ Pass randomly choosen parts from the
the parents to the offsprings
‣ Creates two offsprings
‣ Example
139. Cycle Crossover
‣ Pass randomly choosen parts from the
the parents to the offsprings
‣ Creates two offsprings
‣ Example
‣ mom = [2, 3, 5, 7, 1, 6, 4]
140. Cycle Crossover
‣ Pass randomly choosen parts from the
the parents to the offsprings
‣ Creates two offsprings
‣ Example
‣ mom = [2, 3, 5, 7, 1, 6, 4]
‣ dad = [4, 5, 6, 3, 2, 7, 1]
142. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Choose a gene from the first parent
(e.g. gene=3, index=1).
143. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Choose a gene from the first parent
(e.g. gene=3, index=1).
‣ Add it to the cycle.
144. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Choose a gene from the first parent
(e.g. gene=3, index=1).
‣ Add it to the cycle.
‣ Cycle: [3]
146. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for gene with the same index (1) in
Dad's genes (gene=5, index=1).
147. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for gene with the same index (1) in
Dad's genes (gene=5, index=1).
‣ Add it to the cycle.
148. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for gene with the same index (1) in
Dad's genes (gene=5, index=1).
‣ Add it to the cycle.
‣ Cycle: [3, 5]
150. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene
(gene=5, index=2) in Mom's genes.
151. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene
(gene=5, index=2) in Mom's genes.
‣ Look for the gene at index 2 at Dad's
genes (gene=6, index=2).
152. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene
(gene=5, index=2) in Mom's genes.
‣ Look for the gene at index 2 at Dad's
genes (gene=6, index=2).
‣ Add it to the cycle.
153. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene
(gene=5, index=2) in Mom's genes.
‣ Look for the gene at index 2 at Dad's
genes (gene=6, index=2).
‣ Add it to the cycle.
‣ Cycle: [3, 5, 6]
155. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene in
Dad's genes (gene=6, index=5).
156. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene in
Dad's genes (gene=6, index=5).
‣ Look for the gene at index 5 (gene=7,
index=5) in Mom‘s genes.
157. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene in
Dad's genes (gene=6, index=5).
‣ Look for the gene at index 5 (gene=7,
index=5) in Mom‘s genes.
‣ Add it to the cycle.
158. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene in
Dad's genes (gene=6, index=5).
‣ Look for the gene at index 5 (gene=7,
index=5) in Mom‘s genes.
‣ Add it to the cycle.
‣ Cycle: [3, 5, 6, 7]
160. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene in
Moms's genes (gene=7, index=3).
161. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene in
Moms's genes (gene=7, index=3).
‣ Look for the gene at index 3 (gene=3,
index=3).
162. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene in
Moms's genes (gene=7, index=3).
‣ Look for the gene at index 3 (gene=3,
index=3).
‣ Add it to the cycle.
163. Cycle Crossover
mom = [2, 3, 5, 7, 1, 6, 4]
dad = [4, 5, 6, 3, 2, 7, 1]
‣ Search for the corresponding gene in
Moms's genes (gene=7, index=3).
‣ Look for the gene at index 3 (gene=3,
index=3).
‣ Add it to the cycle.
‣ Cycle: [3, 5, 6, 7, 3]
166. Cycle Crossover
cycle = [3, 5, 6, 7, 3]
‣ Now the cycle is complete!
‣ We can create the offsprings.
167. Cycle Crossover
cycle = [3, 5, 6, 7, 3]
‣ Now the cycle is complete!
‣ We can create the offsprings.
‣ Genes which are in the cycle will be taken
from their parents preserving their original positions
168. Cycle Crossover
cycle = [3, 5, 6, 7, 3]
‣ Now the cycle is complete!
‣ We can create the offsprings.
‣ Genes which are in the cycle will be taken
from their parents preserving their original positions
moms_child = [x, 3, 5, 7, x, 6, x]
dads_child = [x, 5, 6, 3, x, 7, x]
194. Genetic Algorithms
‣ How to represent an individual?
‣ Find a meaningful fitness function
‣ Can‘t be applied to boolean fitness
functions (match, no match)
195. Genetic Algorithms
‣ How to represent an individual?
‣ Find a meaningful fitness function
‣ Can‘t be applied to boolean fitness
functions (match, no match)
‣ Define than blind guessing skip it! operations
If it‘s worse
efficient genetic
197. Genetic Algorithms
‣ Don‘t get lost in the metaphor! a problem!
It‘s not about re-modeling the world, it‘s about solving
198. Genetic Algorithms
‣ Don‘t get lost in the metaphor! a problem!
It‘s not about re-modeling the world, it‘s about solving
‣ Non-determinism
1st run might find a very good solution, 2nd a totally bad one, ...
199. Genetic Algorithms
‣ Don‘t get lost in the metaphor! a problem!
It‘s not about re-modeling the world, it‘s about solving
‣ Non-determinism
1st run might find a very good solution, 2nd a totally bad one, ...
‣ Store your best solutions and use them
as the origin for the next run!
207. Genetic Algorithms
‣ Find smart break conditions
‣ e.g. exit if there is no change for n
generations
208. Genetic Algorithms
‣ Find smart break conditions
‣ e.g. exit if there is no change for n
generations
‣ Implement more genetic operations and
evaluate them.
213. Genetic Algorithms
‣ Optimize ratio between
‣ Generation size
‣ Operation propabilities
‣ Fasten your fitness function!
214. Genetic Algorithms
‣ Optimize ratio between
‣ Generation size
‣ Operation propabilities
‣ Fasten your fitness function!
‣ Use heuristic fitness functions
estimate fitness to be faster
215. Genetic Algorithms
‣ Optimize ratio between
‣ Generation size
‣ Operation propabilities
‣ Fasten your fitness function!
‣ Use heuristic fitness functions
estimate fitness to be faster
‣ Cache frequently computed values
e.g. distances between cities
223. FAQ
‣ Why talk about it?
‣ Interesting and generic methodology
224. FAQ
‣ Why talk about it?
‣ Interesting and generic methodology
‣ Solves NP hard problems heuristically
with minimal thought.
225. FAQ
‣ Why talk about it?
‣ Interesting and generic methodology
‣ Solves NP hard problems heuristically
with minimal thought.
‣ Gives a good understanding why some
people are what they are:
Just bad guesses :-)
99,9% of all species(!) ever existed died out. The other 0,1% is about to do the same. But image if all those guys would still exist. Would be a fairly uncomfortable crowd, wouldn‘t it?
99,9% of all species(!) ever existed died out. The other 0,1% is about to do the same. But image if all those guys would still exist. Would be a fairly uncomfortable crowd, wouldn‘t it?
99,9% of all species(!) ever existed died out. The other 0,1% is about to do the same. But image if all those guys would still exist. Would be a fairly uncomfortable crowd, wouldn‘t it?
acceptable = certain fitness,
boundary = n generations, best individual didnt improve for n generations
steady improvement of the fittest individuals
acceptable = certain fitness,
boundary = n generations, best individual didnt improve for n generations
steady improvement of the fittest individuals
acceptable = certain fitness,
boundary = n generations, best individual didnt improve for n generations
steady improvement of the fittest individuals