Esempio n. 1
0
 def init(self, artist):
     self.markov = markov(open('./static/pitches/pitches_' + artist + '.txt'))
     tmp_pitch = self.markov_pitch()
     duration = [ 'whole', 'half', 'quarter', 'eighth', '16th']
     indi_id = 0
     generation = 0
     
     for i in range(0, model.get_pop_size()):
         tmp_pitch = self.markov_pitch()
         dur = random.choice(duration)
         for j in range(0, model.get_num_traits()):
             self.create_trait(indi_id, generation, tmp_pitch[j], dur)
         indi_id += 1
     
     raise web.seeother('/fitness/0')
Esempio n. 2
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
Esempio n. 3
0
 def markov_pitch(self):
     return self.markov.generate_music(model.get_num_traits())