Example #1
0
    def step_ga(self):

        for m in self.pop:
            m.fitness = self.world.evaluate(m)

        pop = sorted(self.pop, key=lambda x: x.fitness, reverse=True)

        p = self.pop[0]

        if p.fitness > self.best or (self.count % 10) == 0:
            text = " evaluations:" + str(
                self.count * self.pop_size) + "   fitness:" + str(p.fitness)
            self.iter.append(self.count * self.pop_size + 1)
            self.cost.append(-p.fitness)
            self.best = p.fitness
            self.world.evaluate(p, True)
            self.canvas.delete(Tkinter.ALL)
            gui.draw_world(self.world, self.canvas, text)
            self.plot()

        # give the GUI a chance to do stuff
        self.master.update()

        elite_percent = self.elite_percent.get()
        select_percent = self.select_percent.get()
        breed_prob_percent = self.breed_prob_percent.get()
        mutate_percent = self.mutate_percent.get()
        mutate_tokens = self.mutate_tokens.get()
        mutate_amount_percent = self.mutate_amount_percent.get()

        self.pop = ga.breedPopulation(pop, world.World.maxTok, elite_percent,
                                      select_percent, breed_prob_percent,
                                      mutate_percent, mutate_tokens,
                                      mutate_amount_percent)
        self.count += 1
Example #2
0
 def step_random(self):
     g=random_gene(self.world.gene_length,self.world.maxTok)
     fit=self.world.evaluate(g)
     if fit > self.best:
         text=" evaluations:"+str(self.count)+ "   fitness:"+str(fit) 
         self.iter.append(self.count)
         self.cost.append(fit)   
         self.best = fit
         self.world.evaluate(g, True)
         self.canvas.delete(Tkinter.ALL)
         gui.draw_world(self.world, self.canvas,text)
    # give the GUI a chance to do stuff  
     if (self.count % POPSIZE) == 0:
         self.frame.update()
     self.count += 1
Example #3
0
    def step_random(self):
        g = random_gene(self.world.gene_length, self.world.maxTok)
        fit = self.world.evaluate(g)
        if fit > self.best:
            text = " evaluations:" + str(self.count) + "   fitness:" + str(fit)
            self.iter.append(self.count)
            self.cost.append(fit)
            self.best = fit
            self.world.evaluate(g, True)
            self.canvas.delete(Tkinter.ALL)
            gui.draw_world(self.world, self.canvas, text)

    # give the GUI a chance to do stuff
        if (self.count % POPSIZE) == 0:
            self.frame.update()
        self.count += 1
Example #4
0
 def step_random(self):
     
     g=ga.random_gene(self.world.gene_length,self.world.maxTok)
     fit=self.world.evaluate(g)
     if fit > self.best or (self.count % 1000) == 0 :
         text=" evaluations:"+str(self.count)+ "   fitness:"+str(fit) 
         self.iter.append(self.count+1)
         self.cost.append(-fit)   
         self.best = fit
         self.world.evaluate(g, True)
         self.canvas.delete(Tkinter.ALL)
         gui.draw_world(self.world, self.canvas,text)
         self.plot()
             
    # give the GUI a chance to do stuff  
     if (self.count % self.pop_size) == 0:
         self.master.update()
     self.count += 1
Example #5
0
    def step_random(self):

        g = ga.random_gene(self.world.gene_length, self.world.maxTok)
        fit = self.world.evaluate(g)
        if fit > self.best or (self.count % 1000) == 0:
            text = " evaluations:" + str(self.count) + "   fitness:" + str(fit)
            self.iter.append(self.count + 1)
            self.cost.append(-fit)
            self.best = fit
            self.world.evaluate(g, True)
            self.canvas.delete(Tkinter.ALL)
            gui.draw_world(self.world, self.canvas, text)
            self.plot()

    # give the GUI a chance to do stuff
        if (self.count % self.pop_size) == 0:
            self.master.update()
        self.count += 1
Example #6
0
    def step_ga(self):
        
        for m in self.pop:
            m.fitness=self.world.evaluate(m)
            
        pop = sorted(self.pop, key = lambda x:x.fitness,reverse=True)
    
        p = self.pop[0]
        
        if p.fitness > self.best or (self.count % 10) == 0 :
            text=" evaluations:"+str(self.count*self.pop_size)+ "   fitness:"+str(p.fitness) 
            self.iter.append(self.count*self.pop_size+1)
            self.cost.append(-p.fitness)
            self.best = p.fitness
            self.world.evaluate(p, True)
            self.canvas.delete(Tkinter.ALL)
            gui.draw_world(self.world, self.canvas,text)
            self.plot()
        

        # give the GUI a chance to do stuff  
        self.master.update()
          
          
        elite_percent=self.elite_percent.get()        
        select_percent=self.select_percent.get()
        breed_prob_percent=self.breed_prob_percent.get()
        mutate_percent=self.mutate_percent.get()
        mutate_tokens=self.mutate_tokens.get()
        mutate_amount_percent=self.mutate_amount_percent.get()
      
         
              
        self.pop = ga.breedPopulation(pop,world.World.maxTok,
                                      elite_percent,
                                      select_percent,
                                      breed_prob_percent,
                                      mutate_percent,
                                      mutate_tokens,
                                      mutate_amount_percent)
        self.count += 1
Example #7
0
 def step(self):
     
     for m in self.pop:
         m.fitness=self.world.evaluate(m)
         
     pop = sorted(self.pop, key = lambda x:x.fitness,reverse=True)
 
     p = self.pop[0]
     
     if p.fitness > self.best:
         text=" evaluations:"+str(self.count*POPSIZE)+ "   fitness:"+str(p.fitness) 
         self.iter.append(self.count*POPSIZE)
         self.cost.append(p.fitness)
         self.best = p.fitness
         self.world.evaluate(p, True)
         self.canvas.delete(Tkinter.ALL)
         gui.draw_world(self.world, self.canvas,text)
   
     # give the GUI a chance to do stuff  
     self.frame.update()
           
     self.pop = breedPopulation(pop);
     self.count += 1
Example #8
0
    def step(self):

        for m in self.pop:
            m.fitness = self.world.evaluate(m)

        pop = sorted(self.pop, key=lambda x: x.fitness, reverse=True)

        p = self.pop[0]

        if p.fitness > self.best:
            text = " evaluations:" + str(
                self.count * POPSIZE) + "   fitness:" + str(p.fitness)
            self.iter.append(self.count * POPSIZE)
            self.cost.append(p.fitness)
            self.best = p.fitness
            self.world.evaluate(p, True)
            self.canvas.delete(Tkinter.ALL)
            gui.draw_world(self.world, self.canvas, text)

        # give the GUI a chance to do stuff
        self.frame.update()

        self.pop = breedPopulation(pop)
        self.count += 1
Example #9
0
 def draw(self,screen):
     gui.draw_world(self,screen)
     """