Ejemplo n.º 1
0
 def adaptive_crossover(self):
     # Decide adaptively if random crossover or selected crossover
     n_rand = int(self.pop * self.frac_random)
     if n_rand % 2 != 0:
         n_rand -= 1
     set_random = self.q[:n_rand]
     set_clustr = self.q[n_rand:]
     # Send fractions to their respective operators
     set_random, newgenes_r = ga.xover(set_random, n_rand, self.prob_xover)
     set_clustr, newgenes_c = self.clustered_crossover(set_clustr)
     self.q = set_random + set_clustr
     self.newgenes = newgenes_r + newgenes_c
Ejemplo n.º 2
0
 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]
 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()
Ejemplo n.º 4
0
 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')
Ejemplo n.º 5
0
 def clustered_crossover(self, setc):
     # This module clusters set_c into m*2 groups and then performs crossover
     # operations within each group
     self.update_ideal_values()
     newgenes = []
     # Split set_c into m*2 groups
     n_clustr = self.moop.nobj * 2
     cluster_sets = self.cluster_solutions(n_clustr, setc)
     for c in range(n_clustr):
         # If some region of the objective space is undiscovered,
         # increase mutation rate
         if len(cluster_sets[c]) < 2:
             # Ensure probability does not goes past 1.0
             increase = min(0.01, 1.0 - self.prob_mutat)
             self.prob_mutat += round(increase, 2)
         else:
             c_pop = 2 * (len(cluster_sets[c]) // 2)
             cluster_sets[c], ngc = \
                 ga.xover(cluster_sets[c], c_pop, self.prob_xover)
             newgenes.extend(ngc)
     setc = [sol for sublist in cluster_sets for sol in sublist]
     return setc, newgenes