Poprawki, metoda zwracająca listę regałów

This commit is contained in:
andrzej 2020-05-11 12:17:58 +02:00
parent 3ff8b95999
commit 8c66ac657c
4 changed files with 24 additions and 14 deletions

View File

@ -54,6 +54,9 @@ class Agent:
self.closed = [] self.closed = []
self.path = [] self.path = []
self.open = PriorityQueue() self.open = PriorityQueue()
packages_to_go = [p for p in self.warehouse.packages if p.status != PackStatus.STORED]
if not packages_to_go and not self.transported_package:
return
if self.is_loaded: if self.is_loaded:
rack = self.find_nearest_rack_for(self.transported_package) rack = self.find_nearest_rack_for(self.transported_package)
self.dest = Node(rack.x_position, rack.y_position, is_rack=True) self.dest = Node(rack.x_position, rack.y_position, is_rack=True)

View File

@ -26,7 +26,7 @@ class MainGameFrame:
agent_radius = int(TILE_WIDTH/2) agent_radius = int(TILE_WIDTH/2)
self.agent_tex = pygame.image.load('forklift.png') self.agent_tex = pygame.image.load('forklift.png')
self.font = pygame.font.Font('freesansbold.ttf', 16) self.font = pygame.font.Font('freesansbold.ttf', 16)
self.warehouse_map = warehouse.Warehouse(20, 20, 180, 50) self.warehouse_map = warehouse.Warehouse(20, 20, 150, 10)
starting_x, starting_y = self.set_starting_agent_position() starting_x, starting_y = self.set_starting_agent_position()
self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map, agent_radius) self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map, agent_radius)
self.clock = pygame.time.Clock() self.clock = pygame.time.Clock()
@ -42,8 +42,12 @@ class MainGameFrame:
self.draw_agent() self.draw_agent()
self.draw_nums() self.draw_nums()
self.agent.move() self.agent.move()
packages_to_go = [p for p in self.warehouse_map.packages if p.status != PackStatus.STORED]
if not packages_to_go and not self.agent.transported_package:
pygame.quit()
sys.exit()
pygame.display.update() pygame.display.update()
self.clock.tick(12) self.clock.tick(6)
def draw_floor(self): def draw_floor(self):
for x in range(self.warehouse_map.width): for x in range(self.warehouse_map.width):

View File

@ -33,13 +33,13 @@ class PackageLocationClassifier():
test_X = pd.get_dummies(testset[feature_cols]) test_X = pd.get_dummies(testset[feature_cols])
test_y = testset.chance_of_survive test_y = testset.chance_of_survive
products = products.sample(frac=1) products = products.sample(frac=1)
X = pd.get_dummies(products[feature_cols]) X_train = pd.get_dummies(products[feature_cols])
y = products.chance_of_survive y_train = products.chance_of_survive
dummies_names = X.columns.tolist() dummies_names = X_train.columns.tolist()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.01, random_state=1, shuffle=True) # X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.01, random_state=1, shuffle=True)
clf = DecisionTreeRegressor(ccp_alpha=0.02, min_samples_leaf=5, max_depth=6) clf = DecisionTreeRegressor(ccp_alpha=0.02, min_samples_leaf=5, max_depth=5)
self.predictor = clf.fit(X_train, y_train) self.predictor = clf.fit(X_train, y_train)
@ -49,10 +49,10 @@ class PackageLocationClassifier():
evaluation = pd.DataFrame({'category': testset.category, 'temperature': testset.temperature , 'humid': testset.humidity ,'Actual': test_y, 'Predicted': y_pred}) evaluation = pd.DataFrame({'category': testset.category, 'temperature': testset.temperature , 'humid': testset.humidity ,'Actual': test_y, 'Predicted': y_pred})
evaluation['Prediction_diff'] = abs(evaluation['Actual'] - evaluation['Predicted']) evaluation['Prediction_diff'] = abs(evaluation['Actual'] - evaluation['Predicted'])
print("Prediction differs from actual value by average {}".format(round(evaluation['Prediction_diff'].mean(), 2))) print("Prediction differs from actual value by average {}".format(round(evaluation['Prediction_diff'].mean(), 2)))
export_graphviz(clf, out_file=data, filled=True, rounded=True, special_characters=True, feature_names=dummies_names) # export_graphviz(clf, out_file=data, filled=True, rounded=True, special_characters=True, feature_names=dummies_names)
graph = pydotplus.graph_from_dot_data(data.getvalue()) # graph = pydotplus.graph_from_dot_data(data.getvalue())
graph.write_png('Ułożenie.png') # graph.write_png('Drzewo.png')
Image(graph.create_png()) # Image(graph.create_png())
def check_if_can_place(self, package, tile): def check_if_can_place(self, package, tile):
category = package.category category = package.category

View File

@ -221,13 +221,16 @@ class Warehouse:
] ]
return diagonals return diagonals
def get_all_racks(self): def get_all_racks(self, all_storages=False):
""":return list of Tile objects""" """:return list of Tile objects"""
racks = [] racks = []
for x in self.tiles: for x in self.tiles:
# row_racks = [t for t in self.tiles[x] if t.category.name == 'Rack'] # row_racks = [t for t in self.tiles[x] if t.category.name == 'Rack']
for y in x: for y in x:
if y.category.name == 'Rack': if all_storages:
if y.category.name in self.storage_types:
racks.append(y)
elif y.category.name == 'Rack':
racks.append(y) racks.append(y)
return racks return racks