Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Evolutionary Algorithms In Ruby

4,087 views

Published on

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).

Published in: Technology

Evolutionary Algorithms In Ruby

  1. 1. Evolutionary Algorithms in Ruby Julian Fischer fischer@enterprise-rails.de http://www.enterprise-rails.de
  2. 2. Introduction
  3. 3. Introduction About me
  4. 4. About me Julian Fischer ‣Twitter: http://www.twitter.com/railshoster ‣E-Mail: fischer@enterprise-rails.de
  5. 5. About me Julian Fischer ‣Twitter: http://www.twitter.com/railshoster ‣E-Mail: fischer@enterprise-rails.de ‣ CEO of Avarteq GmbH
  6. 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. 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. 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
  9. 9. Introduction About Avarteq GmbH
  10. 10. About Avarteq GmbH
  11. 11. About Avarteq GmbH ‣ Founded in Nov. 2008 from two existing companies.
  12. 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. 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
  14. 14. Introduction Portfolio
  15. 15. About Avarteq GmbH
  16. 16. About Avarteq GmbH ‣ Covers all stages of web development
  17. 17. About Avarteq GmbH ‣ Covers all stages of web development ‣ Consulting
  18. 18. About Avarteq GmbH ‣ Covers all stages of web development ‣ Consulting ‣ Conceptual ~ and screen design
  19. 19. About Avarteq GmbH ‣ Covers all stages of web development ‣ Consulting ‣ Conceptual ~ and screen design ‣ Ruby&onplace. development. In house in Rails
  20. 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
  21. 21. Evolution
  22. 22. Evolution
  23. 23. Evolution
  24. 24. Evolution ‣ Population of individuals (organisms)
  25. 25. Evolution ‣ Population of individuals (organisms) ‣ Genes are passed from generation to generation.
  26. 26. Evolution ‣ Population of individuals (organisms) ‣ Genes are passed from generation to generation. ‣ Slightgeneration to thein genetic material from one changes next.
  27. 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. 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.
  29. 29. Evolution Genetic Operations
  30. 30. Evolution
  31. 31. Evolution ‣ Basic genetic operations
  32. 32. Evolution ‣ Basic genetic operations ‣ Mutation of genetic material. Random changes
  33. 33. Evolution ‣ Basic genetic operations ‣ Mutation of genetic material. Random changes ‣ Recombination of two individuals. Recombine genetic material
  34. 34. Evolution ‣ Basic genetic operations ‣ Mutation of genetic material. Random changes ‣ Recombination of two individuals. Recombine genetic material ‣ also known as sexual reproduction
  35. 35. Evolution
  36. 36. Evolution ‣ Selection
  37. 37. Evolution ‣ Selection ‣ Who will survive and thus
  38. 38. Evolution ‣ Selection ‣ Who will survive and thus ‣ is able to create the most offsprings?
  39. 39. Evolution Challenges
  40. 40. Evolution
  41. 41. Evolution ‣ Changing environment and a lot of other changing temperature, energy resources, competitors and moving stuff, ...
  42. 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. 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.
  44. 44. Evolution
  45. 45. Evolution ‣ Which combinations to create as an individual?
  46. 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. 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. 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
  49. 49. How does that relate to computer science and Ruby?
  50. 50. Evolution and Ruby?
  51. 51. Evolution and Ruby? Given: Search or optimization problem with a huge search space
  52. 52. Evolution and Ruby? Given: Search or optimization problem with a huge search space Wanted: A (heuristic) solution.
  53. 53. Evolutionary Programming (EP) ...
  54. 54. ...with Genetic Algorithms (GA)
  55. 55. Genetic Algorithms Basic Idea
  56. 56. Imitate the evolutionary process.
  57. 57. Genetic Algorithms What we need
  58. 58. Genetic Algorithms
  59. 59. Genetic Algorithms ‣ Generation = Nr. of individuals
  60. 60. Genetic Algorithms ‣ Generation = Nr. of individuals ‣ Individualbut a valid problem solution maybe a bad one = valid.
  61. 61. Genetic Algorithms ‣ Generation = Nr. of individuals ‣ Individualbut a valid problem solution maybe a bad one = valid. ‣ Individuals constist of genes
  62. 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).
  63. 63. Genetic Algorithms
  64. 64. Genetic Algorithms ‣ Mutation operation
  65. 65. Genetic Algorithms ‣ Mutation operation ‣ Recombination operation
  66. 66. Genetic Algorithms ‣ Mutation operation ‣ Recombination operation ‣ Selection operation
  67. 67. Genetic Algorithms Evolutionary Process
  68. 68. Genetic Algorithms
  69. 69. Genetic Algorithms ‣ Start with a first individual (genesis)
  70. 70. Genetic Algorithms ‣ Start with a first individual (genesis) ‣ Create 2nd individual through mutation
  71. 71. Genetic Algorithms ‣ Start with a first individual (genesis) ‣ Create 2nd individual through mutation ‣ Randomly/Statistically choose a genetic operation to create new individuals
  72. 72. Genetic Algorithms
  73. 73. Genetic Algorithms ‣ If a generation is full create a new one
  74. 74. Genetic Algorithms ‣ If a generation is full create a new one ‣ Select fittest individuals to be passed in to the next generation.
  75. 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.
  76. 76. Concrete?!
  77. 77. Genetic Algorithms Example
  78. 78. Travelling Salesman Problem (TSP)
  79. 79. Traveling Salesman
  80. 80. Traveling Salesman ‣ A salesman needs to travel to n cities
  81. 81. Traveling Salesman ‣ A salesman needs to travel to n cities ‣ Each city needs to be visited once
  82. 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. 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.
  84. 84. Why should we care about salesmen?
  85. 85. Traveling Salesman
  86. 86. Traveling Salesman ‣ TSP can be applied to many scenarios:
  87. 87. Traveling Salesman ‣ TSP can be applied to many scenarios: ‣ (Flight) planning, logistics, ...
  88. 88. Traveling Salesman ‣ TSP can be applied to many scenarios: ‣ (Flight) planning, logistics, ... ‣ Manufactoring of microchips
  89. 89. Traveling Salesman ‣ TSP can be applied to many scenarios: ‣ (Flight) planning, logistics, ... ‣ Manufactoring of microchips ‣ Slightly modified in DNA sequencing
  90. 90. Traveling Salesman ‣ TSP can be applied to many scenarios: ‣ (Flight) planning, logistics, ... ‣ Manufactoring of microchips ‣ Slightly modified in DNA sequencing ‣ ...
  91. 91. Traveling Salesman
  92. 92. Traveling Salesman ‣ What‘s the deal about it?
  93. 93. Traveling Salesman ‣ What‘s the deal about it? ‣ Problem of combinatorical optimization
  94. 94. Traveling Salesman ‣ What‘s the deal about it? ‣ Problem of combinatorical optimization ‣ Not a shortest path problem!
  95. 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
  96. 96. Too many possible combinations!
  97. 97. Traveling Salesman
  98. 98. Traveling Salesman ‣ Most direct solution: Check permutations
  99. 99. Traveling Salesman ‣ Most direct solution: Check permutations ‣ O(n!)
  100. 100. Traveling Salesman ‣ Most direct solution: Check permutations ‣ O(n!) ‣ 5! = 120 combinations
  101. 101. Traveling Salesman ‣ Most direct solution: Check permutations ‣ O(n!) ‣ 5! = 120 combinations ‣ 10! = 3.628.800 combinations
  102. 102. Traveling Salesman ‣ Most direct solution: Check permutations ‣ O(n!) ‣ 5! = 120 combinations ‣ 10! = 3.628.800 combinations ‣ 15! = 1.307.674.368.000 combinations
  103. 103. Traveling Salesman ‣ Most direct solution: Check permutations ‣ O(n!) ‣ 5! = 120 combinations ‣ 10! = 3.628.800 combinations ‣ 15! = 1.307.674.368.000 combinations ‣ 20! ~ 2,43 * 10^18 combinations
  104. 104. Genetic Algorithms TSP
  105. 105. Use a genetic algorithm to find a heuristic solution
  106. 106. TSP Individual
  107. 107. TSP Individual
  108. 108. TSP Individual ‣ Valid roundtrip- = cycle of -cities Saarbrücken. Saarbrücken - Amsterdam Madrid - Poznan Berlin -
  109. 109. TSP Individual ‣ Valid roundtrip- = cycle of -cities Saarbrücken. Saarbrücken - Amsterdam Madrid - Poznan Berlin - ‣ Individual = valid roundtrip
  110. 110. TSP Individual ‣ Valid roundtrip- = cycle of -cities Saarbrücken. Saarbrücken - Amsterdam Madrid - Poznan Berlin - ‣ Individual = valid roundtrip ‣ Genes = cities
  111. 111. TSP Fitness
  112. 112. TSP Fitness
  113. 113. TSP Fitness ‣ Each city knows its geo coords (lat, lon)
  114. 114. TSP Fitness ‣ Each city knows its geo coords (lat, lon) ‣ Calculate distance between two geo coords
  115. 115. TSP Fitness ‣ Each city knows its geo coords (lat, lon) ‣ Calculate distance between two geo coords ‣ Fitness = sum of distances between cities
  116. 116. TSP Genetic Operations
  117. 117. Genetic Operations Mutation
  118. 118. TSP Fitness
  119. 119. TSP Fitness ‣ Shuffle mutation
  120. 120. TSP Fitness ‣ Shuffle mutation ‣ Completely shuffle the order of cities in the roundtrip
  121. 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. 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. 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
  124. 124. TSP Fitness
  125. 125. TSP Fitness ‣ Partly shuffle
  126. 126. TSP Fitness ‣ Partly shuffle ‣ Exchange two randomly choosen cities
  127. 127. TSP Fitness ‣ Partly shuffle ‣ Exchange two randomly choosen cities ‣ 1-3-5-4-2 → 1-3-4-5-2
  128. 128. TSP Fitness ‣ Partly shuffle ‣ Exchange two randomly choosen cities ‣ 1-3-5-4-2 → 1-3-4-5-2 ‣ (+) Uses existing individuals
  129. 129. TSP Fitness ‣ Partly shuffle ‣ Exchange two randomly choosen cities ‣ 1-3-5-4-2 → 1-3-4-5-2 ‣ (+) Uses existing individuals ‣ Many more mutation operations imaginable.
  130. 130. Genetic Operations Recombination
  131. 131. TSP Recombination
  132. 132. TSP Recombination ‣ Recombination challenge:
  133. 133. TSP Recombination ‣ Recombination challenge: ‣ How to combine parts of individuals in a way that a valid roundtrip will be produced?
  134. 134. Recombination Cycle Crossover
  135. 135. Cycle Crossover
  136. 136. Cycle Crossover ‣ Pass randomly choosen parts from the the parents to the offsprings
  137. 137. Cycle Crossover ‣ Pass randomly choosen parts from the the parents to the offsprings ‣ Creates two offsprings
  138. 138. Cycle Crossover ‣ Pass randomly choosen parts from the the parents to the offsprings ‣ Creates two offsprings ‣ Example
  139. 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. 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]
  141. 141. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1]
  142. 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. 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. 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]
  145. 145. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1]
  146. 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. 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. 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]
  149. 149. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1]
  150. 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. 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. 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. 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]
  154. 154. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1]
  155. 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. 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. 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. 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]
  159. 159. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1]
  160. 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. 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. 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. 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]
  164. 164. Cycle Crossover cycle = [3, 5, 6, 7, 3]
  165. 165. Cycle Crossover cycle = [3, 5, 6, 7, 3] ‣ Now the cycle is complete!
  166. 166. Cycle Crossover cycle = [3, 5, 6, 7, 3] ‣ Now the cycle is complete! ‣ We can create the offsprings.
  167. 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. 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]
  169. 169. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [x, 3, 5, 7, x, 6, x] dads_child = [x, 5, 6, 3, x, 7, x]
  170. 170. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [x, 3, 5, 7, x, 6, x] dads_child = [x, 5, 6, 3, x, 7, x] ‣ Missing genes will be taken from the other parent.
  171. 171. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [x, 3, 5, 7, x, 6, x] dads_child = [x, 5, 6, 3, x, 7, x] ‣ Missing genes will be taken from the other parent. mom = [2, 3, 5, 7, 1, 6, 4] dads_child = [2, 5, 6, 3, 1, 7, 4]
  172. 172. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [x, 3, 5, 7, x, 6, x] dads_child = [x, 5, 6, 3, x, 7, x] ‣ Missing genes will be taken from the other parent. mom = [2, 3, 5, 7, 1, 6, 4] dads_child = [2, 5, 6, 3, 1, 7, 4]
  173. 173. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [x, 3, 5, 7, x, 6, x] dads_child = [x, 5, 6, 3, x, 7, x] ‣ Missing genes will be taken from the other parent. mom = [2, 3, 5, 7, 1, 6, 4] dads_child = [2, 5, 6, 3, 1, 7, 4]
  174. 174. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [x, 3, 5, 7, x, 6, x] dads_child = [x, 5, 6, 3, x, 7, x] ‣ Missing genes will be taken from the other parent. mom = [2, 3, 5, 7, 1, 6, 4] dads_child = [2, 5, 6, 3, 1, 7, 4]
  175. 175. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [x, 3, 5, 7, x, 6, x] dads_child = [x, 5, 6, 3, x, 7, x] ‣ Missing genes will be taken from the other parent. mom = [2, 3, 5, 7, 1, 6, 4] dads_child = [2, 5, 6, 3, 1, 7, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [4, 3, 5, 7, 2, 6, 1]
  176. 176. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [x, 3, 5, 7, x, 6, x] dads_child = [x, 5, 6, 3, x, 7, x] ‣ Missing genes will be taken from the other parent. mom = [2, 3, 5, 7, 1, 6, 4] dads_child = [2, 5, 6, 3, 1, 7, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [4, 3, 5, 7, 2, 6, 1]
  177. 177. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [x, 3, 5, 7, x, 6, x] dads_child = [x, 5, 6, 3, x, 7, x] ‣ Missing genes will be taken from the other parent. mom = [2, 3, 5, 7, 1, 6, 4] dads_child = [2, 5, 6, 3, 1, 7, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [4, 3, 5, 7, 2, 6, 1]
  178. 178. Cycle Crossover mom = [2, 3, 5, 7, 1, 6, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [x, 3, 5, 7, x, 6, x] dads_child = [x, 5, 6, 3, x, 7, x] ‣ Missing genes will be taken from the other parent. mom = [2, 3, 5, 7, 1, 6, 4] dads_child = [2, 5, 6, 3, 1, 7, 4] dad = [4, 5, 6, 3, 2, 7, 1] moms_child = [4, 3, 5, 7, 2, 6, 1]
  179. 179. TSP Evolver
  180. 180. Setup the evolutionary process
  181. 181. TSP Evolver
  182. 182. TSP Evolver ‣ Generation size
  183. 183. TSP Evolver ‣ Generation size ‣ Choose genetic operations
  184. 184. TSP Evolver ‣ Generation size ‣ Choose genetic operations ‣ Probabilities of genetic operations
  185. 185. TSP Evolver ‣ Generation size ‣ Choose genetic operations ‣ Probabilities of genetic operations ‣ e.g. 30% mutation, 70% x-over
  186. 186. TSP Evolver ‣ Generation size ‣ Choose genetic operations ‣ Probabilities of genetic operations ‣ e.g. 30% mutation, 70% x-over ‣ Set exit condition
  187. 187. TSP Evolver ‣ Generation size ‣ Choose genetic operations ‣ Probabilities of genetic operations ‣ e.g. 30% mutation, 70% x-over ‣ Set exit condition ‣ ...
  188. 188. Go!
  189. 189. Code and Demo!
  190. 190. GA Challenges
  191. 191. Genetic Algorithms
  192. 192. Genetic Algorithms ‣ How to represent an individual?
  193. 193. Genetic Algorithms ‣ How to represent an individual? ‣ Find a meaningful fitness function
  194. 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. 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
  196. 196. Genetic Algorithms
  197. 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. 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. 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!
  200. 200. What is it good for again?
  201. 201. Genetic Algorithms
  202. 202. Genetic Algorithms ‣ Find good solutions for np hard combinatorical problems
  203. 203. Genetic Algorithms ‣ Find good solutions for np hard combinatorical problems ‣ ... even for difficult search spaces!
  204. 204. What else can be done?
  205. 205. Genetic Algorithms
  206. 206. Genetic Algorithms ‣ Find smart break conditions
  207. 207. Genetic Algorithms ‣ Find smart break conditions ‣ e.g. exit if there is no change for n generations
  208. 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.
  209. 209. Genetic Algorithms
  210. 210. Genetic Algorithms ‣ Optimize ratio between
  211. 211. Genetic Algorithms ‣ Optimize ratio between ‣ Generation size
  212. 212. Genetic Algorithms ‣ Optimize ratio between ‣ Generation size ‣ Operation propabilities
  213. 213. Genetic Algorithms ‣ Optimize ratio between ‣ Generation size ‣ Operation propabilities ‣ Fasten your fitness function!
  214. 214. Genetic Algorithms ‣ Optimize ratio between ‣ Generation size ‣ Operation propabilities ‣ Fasten your fitness function! ‣ Use heuristic fitness functions estimate fitness to be faster
  215. 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
  216. 216. FAQ
  217. 217. FAQ
  218. 218. FAQ ‣ Do you use EP/GA for your everyday work?
  219. 219. FAQ ‣ Do you use EP/GA for your everyday work? ‣ Not very often ...
  220. 220. FAQ ‣ Do you use EP/GA for your everyday work? ‣ Not very often ... ‣ ... but how often do you encounter np- hard problems in everyday‘s work?
  221. 221. FAQ
  222. 222. FAQ ‣ Why talk about it?
  223. 223. FAQ ‣ Why talk about it? ‣ Interesting and generic methodology
  224. 224. FAQ ‣ Why talk about it? ‣ Interesting and generic methodology ‣ Solves NP hard problems heuristically with minimal thought.
  225. 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 :-)
  226. 226. Further questions?
  227. 227. Thank you for your attention! Headquarter: Rails Enterprise Hosting: http://www.avarteq.de http://www.enterprise- rails.de Blog: http://ww.treibstofff.de Rails Hosting: http://www.railshoster.de
  228. 228. Resources
  229. 229. Resources ‣ http://en.wikipedia.org/wiki/Travelling_salesman_problem
  230. 230. Resources ‣ http://en.wikipedia.org/wiki/Travelling_salesman_problem ‣ http://en.wikipedia.org/wiki/Evolution
  231. 231. Resources ‣ http://en.wikipedia.org/wiki/Travelling_salesman_problem ‣ http://en.wikipedia.org/wiki/Evolution ‣ http://en.wikipedia.org/wiki/Genetic_algorithm

×