Added mating pool selection function

This commit is contained in:
Marcin Kostrzewski 2020-05-16 13:51:09 +02:00
parent 0cd91fd1a1
commit f56eedb657

View File

@ -28,6 +28,27 @@ def geneticAlgorithm(map, iter, solutions):
# TODO: Parents selection, mating, offspring # TODO: Parents selection, mating, offspring
def selectMatingPool(population, fitness, count):
"""
Pick best players from a population.
:param population: Entire population pool
:param fitness: Fitnesses coresponding to each player
:param count: Selection count
"""
result = []
bestIdxs = []
for i in range(count):
bestIdx = (numpy.where(fitness == numpy.max(fitness)))[0][0]
fitness[bestIdx] = 0
bestIdxs.append(bestIdx)
for id in bestIdxs:
result.append(population[id])
print(result)
return result
def doSimulation(weights, map): def doSimulation(weights, map):
""" """
Runs the simulation. Returns fitness. Runs the simulation. Returns fitness.
@ -46,7 +67,6 @@ def doSimulation(weights, map):
player.kill() player.kill()
del player del player
map.respawn() map.respawn()
print(fitness)
return fitness return fitness