Próba integracji drzewa z alg. genetycznym

This commit is contained in:
andrzej 2020-06-15 14:10:33 +02:00
parent 1b4fd6579e
commit 6322d823fa
5 changed files with 26 additions and 24 deletions

View File

@ -1,4 +1,3 @@
from pandas.tests.io.json.test_ujson import numpy
from warehouse import Coordinates, Tile, Pack
from queue import PriorityQueue
@ -198,8 +197,8 @@ class Agent:
sys.exit()
pack_id = self.route[0]
self.route = self.route[1:]
print("Next package ID:")
print(pack_id)
# print("Next package ID:")
# print(pack_id)
dst_package = None
for pack in self.warehouse.packages:
if pack.id + 1 == pack_id:
@ -208,11 +207,11 @@ class Agent:
if dst_package is not None:
return dst_package
nmodel = Sequential()
imageClass(nmodel)
nmodel.load_weights('model_weights.h5')
nmodel = Sequential()
imageClass(nmodel)
nmodel.load_weights('model_weights.h5')
imgSkan()
imgSkan()
def rack_heuristics(self, start, goal, can_place):
heur_can_place = not can_place
@ -286,8 +285,8 @@ class Agent:
self.graph_map[0][package1.id + 1] = len(self.path)
def trace_route(self):
for packs in self.warehouse.packages:
print(packs.id)
# for packs in self.warehouse.packages:
# print(packs.id)
self.route = genetic_trace_route(self.graph_map, len(self.warehouse.packages))
print("best route")
print(self.route)
# print("best route")
# print(self.route)

View File

@ -1,6 +1,5 @@
import random
import math
### prawdopodobieństwo mutacji
mutation_prob = 0.03
### ilość osobników w pokoleniu, powinna być parzysta
@ -8,7 +7,7 @@ generation_size = 40
### liczba pokoleń
number_of_generations = 30
### jak bardzo promowane są osobniki wykorzystujące całą pojemność regału
amount_of_promotion = 0
amount_of_promotion = 5
def first_gen(number_of_packages, number_of_racks):
@ -24,11 +23,16 @@ def first_gen(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()
rest_of_capacity = [rack.capacity for rack in racks]
# print("początkowa pojemność: ",rest_of_capacity)
for i in range(number_of_packages):
rest_of_capacity[individual[i]] -= packages[i]
can_place = tree_predictor.check_if_can_place(packages[i], racks[i])
if not can_place:
rest_of_capacity[individual[i]] -= packages[i].size * 5
else:
rest_of_capacity[individual[i]] -= packages[i].size
# print("pozostała pojemność: ",rest_of_capacity)
# pdb.set_trace()
fitness = 0
for i in range(number_of_racks):
# jak regał jest przepełniony, zmniejsza fitness osobnika
@ -36,8 +40,9 @@ def evaluation(individual, packages, racks, number_of_packages, number_of_racks,
fitness += rest_of_capacity[i]
# delikane promowanie osobników wykorzystujących regały w pełni
elif rest_of_capacity[i] == 0:
fitness += amount_of_promotion
### tu dodaj to co zrobi Andrzej
fitness += 2
else:
fitness += 1
return fitness
def roulette(generation, packages, racks, number_of_packages, number_of_racks, tree_predictor):

View File

@ -90,8 +90,8 @@ def genetic_trace_route(graph_map, packages):
population = copy.deepcopy(new_population)
scores = score_all(graph_map, population)
scores.sort(key=lambda x: x[1])
print("Best route of all population in iteration " + str(i + 1))
print(scores[0][1])
# print("Best route of all population in iteration " + str(i + 1))
# print(scores[0][1])
scores = score_all(graph_map, population)
scores.sort(key=lambda x: x[1])

View File

@ -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=100, amount_of_promotion=0):
pygame.font.init()
self.display = pygame.display.set_mode(WINDOW_SIZE)
pygame.display.set_caption("Smart ForkLift")
@ -35,8 +35,8 @@ class MainGameFrame:
packs_coords = [(pack.lays_on_field.x_position, pack.lays_on_field.y_position) for pack in self.warehouse_map.packages]
list_of_racks = self.warehouse_map.get_all_racks(True)
racks_coords = [(line.x_position, line.y_position) for line in list_of_racks]
packs_sizes = [pack.size for pack in self.warehouse_map.packages]
racks_capacities = [rack.capacity for rack in list_of_racks]
packs_sizes = [pack for pack in self.warehouse_map.packages]
racks_capacities = list_of_racks
# print("koordynaty paczek: ",packs_coords)
# print("koordynaty regałów: ",racks_coords)
print("wagi paczek: ",packs_sizes)

View File

@ -41,5 +41,3 @@ def imgSkan():
prediction = numpy.argmax(prediction)
print("Producent:", prediction)
producent.append(prediction)
imgSkan()