Work in progress
This commit is contained in:
parent
385afbf00a
commit
54e42b30e8
@ -21,7 +21,7 @@ def first_gen(number_of_packages, number_of_racks):
|
||||
first_generation.append(individual)
|
||||
return first_generation
|
||||
|
||||
def evaluation(individual, packages, racks, number_of_packages, number_of_racks):
|
||||
def evaluation(individual, packages, racks, number_of_packages, number_of_racks, tree_predictor):
|
||||
# im większy fitness tym lepszy osobnik
|
||||
# print("regały: ",racks)
|
||||
rest_of_capacity = racks.copy()
|
||||
@ -40,11 +40,11 @@ def evaluation(individual, packages, racks, number_of_packages, number_of_racks)
|
||||
### tu dodaj to co zrobi Andrzej
|
||||
return fitness
|
||||
|
||||
def roulette(generation, packages, racks, number_of_packages, number_of_racks):
|
||||
def roulette(generation, packages, racks, number_of_packages, number_of_racks, tree_predictor):
|
||||
# print('pokolenie: ', generation)
|
||||
evaluations = []
|
||||
for i in range(generation_size):
|
||||
individual_fitness = evaluation(generation[i], packages, racks, number_of_packages, number_of_racks)
|
||||
individual_fitness = evaluation(generation[i], packages, racks, number_of_packages, number_of_racks, tree_predictor)
|
||||
evaluations.append(individual_fitness)
|
||||
# print("tablica dopasowań: ", evaluations)
|
||||
maximum = min(evaluations)
|
||||
@ -90,7 +90,7 @@ def mutation(individual, number_of_packages, number_of_racks):
|
||||
return individual
|
||||
|
||||
|
||||
def gen_alg(packages, racks, number_of_generations, generation_size, mutation_prob, amount_of_promotion):
|
||||
def gen_alg(packages, racks, number_of_generations, generation_size, mutation_prob, amount_of_promotion, tree_predictor):
|
||||
number_of_packages = len(packages)
|
||||
number_of_racks = len(racks)
|
||||
|
||||
@ -100,18 +100,18 @@ def gen_alg(packages, racks, number_of_generations, generation_size, mutation_pr
|
||||
|
||||
# pętla znajdująca najlepszy fitness w pierwszym pokoleniu
|
||||
for i in range(generation_size):
|
||||
evaluation_of_individual = evaluation(generation[i], packages, racks, number_of_packages, number_of_racks)
|
||||
evaluation_of_individual = evaluation(generation[i], packages, racks, number_of_packages, number_of_racks, tree_predictor)
|
||||
if evaluation_of_individual > global_maximum:
|
||||
global_maximum = evaluation_of_individual
|
||||
best_individual = generation[i].copy()
|
||||
|
||||
#właściwa pętla programu
|
||||
for generation_index in range(number_of_generations):
|
||||
print('pokolenie numer: ', generation_index)
|
||||
# print('pokolenie numer: ', generation_index)
|
||||
# print(generation)
|
||||
|
||||
### RULETKA
|
||||
survivors = roulette(generation, packages, racks, number_of_packages, number_of_racks)
|
||||
survivors = roulette(generation, packages, racks, number_of_packages, number_of_racks, tree_predictor)
|
||||
# print('przetrwali: ',survivors)
|
||||
|
||||
### KRZYŻOWANIE
|
||||
@ -131,7 +131,7 @@ def gen_alg(packages, racks, number_of_generations, generation_size, mutation_pr
|
||||
### NAJLEPSZE DOPASOWANIE
|
||||
local_maximum = -math.inf
|
||||
for each in range(generation_size):
|
||||
specific_fitness = evaluation(descendants[each], packages, racks, number_of_packages, number_of_racks)
|
||||
specific_fitness = evaluation(descendants[each], packages, racks, number_of_packages, number_of_racks, tree_predictor)
|
||||
if specific_fitness > local_maximum:
|
||||
local_maximum = specific_fitness
|
||||
generation_best_individual = descendants[each].copy()
|
||||
@ -141,5 +141,5 @@ def gen_alg(packages, racks, number_of_generations, generation_size, mutation_pr
|
||||
best_individual = generation_best_individual.copy()
|
||||
generation = descendants
|
||||
print('maksimum globalne: ', global_maximum)
|
||||
print("jeśli maksimum globalne wynosi 0, każda paczka ma swój regał")
|
||||
# print("jeśli maksimum globalne wynosi 0, każda paczka ma swój regał")
|
||||
print("najlepsze dopasowanie: ", best_individual)
|
||||
|
4
main.py
4
main.py
@ -20,7 +20,7 @@ TILE_HEIGHT = 32
|
||||
CIRCLE_CENTER_X, CIRCLE_CENTER_Y = int(TILE_WIDTH/2), int(TILE_HEIGHT/2)
|
||||
|
||||
class MainGameFrame:
|
||||
def __init__(self, mutation_prob = 0.03, generation_size = 40, number_of_generations = 30, amount_of_promotion = 0):
|
||||
def __init__(self, mutation_prob=0.03, generation_size=40, number_of_generations=30, amount_of_promotion=0):
|
||||
pygame.font.init()
|
||||
self.display = pygame.display.set_mode(WINDOW_SIZE)
|
||||
pygame.display.set_caption("Smart ForkLift")
|
||||
@ -40,7 +40,7 @@ class MainGameFrame:
|
||||
# print("koordynaty regałów: ",racks_coords)
|
||||
print("wagi paczek: ",packs_sizes)
|
||||
print("pojemności regałów: ",racks_capacities)
|
||||
gen_alg(packs_sizes, racks_capacities, number_of_generations, generation_size, mutation_prob, amount_of_promotion)
|
||||
gen_alg(packs_sizes, racks_capacities, number_of_generations, generation_size, mutation_prob, amount_of_promotion, self.agent.location_classifier)
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
|
Loading…
Reference in New Issue
Block a user