def step(self, count=1): for i in range(count): self.age += 1 self.evaluate() if len(self.children_before_eval) == 0: new_generation = self.survival_selection() self.population.extend(new_generation) parents = self.select_parents() self.children_before_eval = crossoverer.rex(parents, self.nchi) for i in self.children_before_eval: i.birth_year = self.age
def until_goal(self, goal=10e-7, max_count=200000): for i in range(max_count): self.age += 1 self.evaluate() if len(self.children_before_eval) == 0: if self.get_best_individual().raw_fitness < goal: # print("goal") return True new_generation = self.survival_selection() self.population.extend(new_generation) parents = self.select_parents() self.children_before_eval = crossoverer.rex(parents, self.nchi) for i in self.children_before_eval: i.birth_year = self.age # print("time is up") return False
def generate_first_children(self): parents = self.select_parents() self.children_before_eval = crossoverer.rex(parents, self.nchi) self.children_after_eval = []
def op(x): x.sort(key=lambda i: i.fitness) return crossoverer.rex(x[:npar])
def gaq_op_plain_origopt(x): x.sort(key=lambda i: i.fitness) n = x[0].n return crossoverer.rex(x[:n + 1])
def gaq_op_plain_origopt(x): x.sort(key=lambda i: i.fitness) parents = x[:n + 1] for p in parents: p.state = State.USED_IN_GAQ return crossoverer.rex(parents)