Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 2.83 KB

Genetic-Algorithm.md

File metadata and controls

56 lines (44 loc) · 2.83 KB

GENETIC-ALGORITHM

AIMA4e

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

repeat
   population ← [MUTATE(RECOMBINE(SELECT(2, population, FITNESS-FN)))
          for i in population]
until some individual is fit enough, or enough time has elapsed
return the best individual in population, according to FITNESS-FN


function SELECT(ρ, population, FITNESS-FN) returns a set of ρ individuals
selection ← a uniform random sample of 2 * ρ individuals from population
return the top ρ individuals in selection, ranked by FITNESS-FN


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

n ← LENGTH(x)
crossover ← random integer from 0 to n
return APPEND(x[0:crossover], y[crossover: n])


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

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.