Skip to content

Instantly share code, notes, and snippets.

@18182324
Created April 12, 2021 12:00
Show Gist options
  • Save 18182324/24742f043cae306dfdb37c84b43c278b to your computer and use it in GitHub Desktop.
Save 18182324/24742f043cae306dfdb37c84b43c278b to your computer and use it in GitHub Desktop.
i=0
fitness = 0
counter = 0
while i < max_iter:
if counter > n_repeats:
STOP
Y = [ ]
fit = [ ]
pairs = randompairsfrom (X)
for j in pairs:
y = crossover ( j )
y = randommutation ( y )
Y. append (y)
fit.append (fitness(y))
Y, fit = ordermaxtomin (Y, fit )
bestfitness = fit[ 0 ]
if bestfitness < fitness:
counter = counter+1
else:
counter = 0
X = Y [0: N]
i=i+1
fitness = bestfitness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment