Exemplo n.º 1
0
    def set_bees(self, nu1, nu2, crossover, mutation):

        for i in range(0, self.bee_count):
            self.bee_net.append(
                (neural_gen.neural(nu1[0], nu1[1], nu1[2], nu1[3]), neural_gen.neural(nu2[0], nu2[1], nu2[2], nu2[3]))
            )
            self.bee.append(
                (random.uniform(0, self.width), random.uniform(0, self.height), random.uniform(0, self.depth), 0)
            )
            self.bee_old.append(
                (random.uniform(0, self.width), random.uniform(0, self.height), random.uniform(0, self.depth), 0)
            )
            self.bee_net[i][0].init()
            self.bee_net[i][1].init()

        self.w_num1 = self.bee_net[0][0].get_num_weights()
        self.w_num2 = self.bee_net[0][1].get_num_weights()

        self.pop = ga.population(self.bee_count, self.w_num1 + self.w_num2, crossover, mutation)
        self.chro = self.pop.genarate()

        for i in range(0, self.bee_count):
            l = self.split_list(self.chro[i])
            for j in range(0, 2):
                self.bee_net[i][j].put_weights(l[j])
Exemplo n.º 2
0
root = Tk()
root.title("artificial bees")

bee_count = 20
flower_count = 40
total = 1
sizeX = 1200
sizeY = 700
hive = (sizeX/2, sizeY/2)
bee = list()
bee_old = list()
flower = list()
bee_net = list()

for i in range(0, bee_count):
    bee_net.append((neural_gen.neural(2, 6, 3, 5),
        neural_gen.neural(1, 1, 2, 0)))
    bee.append((random.uniform(0, sizeX), random.uniform(0, sizeY), 0))
    bee_old.append((random.uniform(0, sizeX), random.uniform(0, sizeY), 0))

for i in range(0, bee_count):
    bee_net[i][0].init()
    bee_net[i][1].init()

for i in range(0, flower_count):
    x = random.randrange(50, sizeX-50)
    while x > hive[0] - 60 and x < hive[0] + 60:
        x = random.randrange(50, 550)
    y = random.randrange(50, 550)
    while y > hive[1] - 60 and y < hive[1] + 60:
        y = random.randrange(50, sizeY-50)