def test_adaptive_crossover(self): # Set up for test self.gen.makep() if self.gen.g == 1: self.gen.q = binsel(self.gen.p, self.gen.pop, 'elitism') else: self.q = binsel(self.gen.p, self.gen.pop, 'cco') # Run adaptive crossover self.gen.adaptive_crossover() self.assertEqual( len(self.gen.q) + len(self.gen.newgenes), self.gen.pop)
def rungen(self): self.t += 1 if self.t % 50 == 0: gent = datetime.datetime.now() print(' ', gent) print('t = ', self.t) self.makep() if self.t == 1: self.q = ga.binsel(self.p, self.pop, 'elitism') else: self.q = ga.binsel(self.p, self.pop, 'cco') self.newgenes = ga.xover(self.q, self.pop, 0.9) self.newgenes = ga.mutat(self.n, self.newgenes, self.pop) self.makeq()
def rungen(self): self.update_gen() # Create the parent pool: self.makep() if self.g == 1: self.q = ga.binsel(self.p, self.pop, 'elitism') else: self.q = ga.binsel(self.p, self.pop, 'cco') self.adaptive_crossover() # Mutation random or selected self.q, self.newgenes = \ ga.mutat_mv(self.q, self.newgenes, self.pop, self.prob_mutat) self.fill_q() # Adaptive Local search self.local_search() self.cleanarchive() print(self.funkeval, 'function evaluations have been performed.\n')
def rungen(self): self.g += 1 # Print out generation info: if self.g % 50 == 0: gent = datetime.now() print(' ', gent) print(' ') print('gen = ', self.g) # Create the parent pool: self.makep() if self.g == 1: self.q = ga.binsel(self.p, self.pop, 'elitism') else: self.q = ga.binsel(self.p, self.pop, 'cco') # Use the mixed-variable specific modules: self.q, self.newgenes = ga.xover_mv(self.q, self.pop, 0.9) self.q, self.newgenes = ga.mutat_mv(self.q, self.newgenes, self.pop, 0.3) self.makeq() print(self.funkeval, 'function evaluations have been performed.\n')
def rungen(self): self.t += 1 #if self.t % 50 == 0: gent = datetime.now() print(' ', gent) print('t = ', self.t) print('Selecting parent population...') self.makep() print('GA operation: binary selection...') if self.t == 1: self.q = ga.binsel(self.p, self.pop, 'elitism') else: self.q = ga.binsel(self.p, self.pop, 'cco') print('GA operation: crossover...') self.newgenes = ga.xover(self.q, self.pop, 0.8) print('GA operation: mutation...') self.evoloperators() if self.t % 10 == 0: self.localsearch() print(self.funkeval, 'function evaluations have been performed.\n')
def soga(self, k, mems, numgen): # Initialize single-objective solutions using genetic algorithm q = [] newgenes = [] for t in range(numgen): print(' Subgeneration', t) p, newgenes = self.makesop(t, mems, q, newgenes) if t != 0: q = ga.binsel(p, mems, 'elitism') newgenes = ga.xover(q, mems, 0.9) newgenes = ga.mutat(self.n, newgenes, mems) q = self.makesoq(t, mems, k, p, q, newgenes) q = sorank(q) return q[0]