Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 1.47 KB

Genetic-Algorithm.md

File metadata and controls

28 lines (23 loc) · 1.47 KB

GENETIC-ALGORITHM

AIMA3e

function GENETIC-ALGORITHM(population,FITNESS-FN) returns an individual
inputs: population, a set of individuals
    FITNESS-FN, a function that measures the fitness of an individual

repeat
   new_population ← empty set
   for i = 1 to SIZE(population) do
     x ← RANDOM-SELECTION(population,FITNESS-FN)
     y ← RANDOM-SELECTION(population,FITNESS-FN)
     child ← REPRODUCE(x,y)
     if (small random probability) then child ← MUTATE(child)
     add child to new_population
   populationnew_population
until some individual is fit enough, or enough time has elapsed
return the best individual in population, according to FITNESS-FN


function REPRODUCE(x, y) returns an individual
inputs: x,y, parent individuals

n ← LENGTH(x); c ← random number from 1 to n
return APPEND(SUBSTRING(x, 1, c),SUBSTRING(y, c+1, n))


Figure ?? A genetic algorithm. The algorithm is the same as the one diagrammed in Figure ??, with one variation: in this more popular version, each mating of two parents produces only one offspring, not two.