import copy import random from evolalg.repair import Repair class HallOfFameRepair(Repair): def __init__(self, excepted_size, halloffame, top): super(HallOfFameRepair, self).__init__(excepted_size) self.halloffame = halloffame self.top = top def generate_new(self, population, missing_count): ind = random.randint(0, min(self.top, len(self.halloffame)) - 1) return copy.deepcopy(population[ind])