Example #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
Example #2
0
 def create_pheno(self, indi):
     '''
     converts the individuals pitch, accidental, octave, and rhythm to a music stream
     using the music21 library. the music stream is then used to create a midi file
     '''
     gene = self.to_list(model.get_indi_traits(indi))
     partupper = stream.Part()
     m = stream.Measure()
     for _note, _duration in gene:
         print "note    :", _note
         print "duration    :", _duration
         n = note.Note(_note)
         n.duration.type = _duration
         m.append(n)
     partupper.append(m)    
     return partupper