コード例 #1
0
 def crossover(self, p1, p2, point):    
     # get traits for each parent
     p1t = self.to_list(model.get_indi_traits(p1))
     p2t = self.to_list(model.get_indi_traits(p2))
     split = random.randint(1, model.get_num_traits())
     
     # create each child
     c1 = p1t[:split] + p2t[split:]
     c2 = p2t[:split] + p1t[split:]
     
     # store children in database        
     tmp_id = int(model.get_max_indi_id()) + 1
     tmp_gen = int(model.get_max_gen()) + 1
     
     for i in c1:
         model.insert_trait(tmp_id, tmp_gen, i[0], i[1])
          
     for i in c2:
         model.insert_trait(tmp_id + 1, tmp_gen, i[0], i[1])
 
     return tmp_id
コード例 #2
0
 def create_trait(self, indi_id, generation, pitch, duration):
     model.insert_trait(indi_id, generation, pitch, duration)