Przebudowa drzewa decyzyjnego, trainsetu, oraz stworzenie funkcji heurystycznej dla szukania regału, oraz testsetu

This commit is contained in:
andrzej 2020-05-10 14:31:00 +02:00
parent 8f1767c50f
commit 5ba42f7942
6 changed files with 271 additions and 78 deletions

View File

@ -4,6 +4,8 @@ from math import sqrt
from attributes import TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS, PackStatus
import pygame
import sys
import pdb
from package_location_classifier.classifier import PackageLocationClassifier
class Node:
def __init__(self, coord_x, coord_y, package=None, is_rack=False):
@ -38,6 +40,14 @@ class Agent:
self.closed = list()
self.open = PriorityQueue()
self.path = list()
self.location_classifier = PackageLocationClassifier()
self.check_packages_locations()
def check_packages_locations(self):
for pack in self.warehouse.packages:
if pack.lays_on_field.category.name in self.warehouse.storage_types:
can_place = self.location_classifier.check_if_can_place(pack, pack.lays_on_field)
pack.status = PackStatus.STORED if (can_place and pack.lays_on_field.capacity >= 0) else PackStatus.STORED_BAD_LOCATION
def find_path(self):
@ -90,14 +100,6 @@ class Agent:
diff_x = pow(goal.x - start.x, 2)
diff_y = pow(goal.y - start.y, 2)
additional_cost = 0
# if diff_x < diff_y:
# column = self.warehouse.tiles[start.x]
# tiles = column[goal.y:start.y] if goal.y < start.y else column[start.y:goal.y]
# additional_cost += len([t for t in tiles if not t.category.passable])
# elif diff_x > diff_y:
# row = [col[start.x] for col in self.warehouse.tiles]
# tiles = row[goal.x:start.x] if goal.x < start.x else row[start.x:goal.x]
# additional_cost += len([t for t in tiles if not t.category.passable])
return round(sqrt(diff_x + diff_y), 3) + float(10*additional_cost)
def check_if_open(self, node: Node):
@ -168,7 +170,7 @@ class Agent:
if not tile_on_map:
return False
next_tile = self.warehouse.tiles[next_coords.x][next_coords.y]
if not self.is_loaded or (next_coords.x, next_coords.y) != (self.dest.x, self.dest.y):
if (next_coords.x, next_coords.y) != (self.dest.x, self.dest.y):
tile_passable = isinstance(next_tile, Tile) and next_tile.category.passable
return tile_passable
@ -188,9 +190,17 @@ class Agent:
return
# pygame.quit()
# sys.exit()
package = min(packages_costs, key=lambda l: l[1])[0]
return package
def rack_heuristics(self, start, goal, can_place):
heur_can_place = not can_place
diff_x = pow(goal.x - start.x, 2)
diff_y = pow(goal.y - start.y, 2)
place_cost = 100 * float(heur_can_place)
return round(sqrt(diff_x + diff_y), 3) + float(place_cost)
def find_nearest_rack_for(self, package, expand_box=0):
weight = package.size
storage = "Rack"
@ -209,7 +219,8 @@ class Agent:
racks_costs = []
for rack in quarter_racks:
new_node = Node(rack.x_position, rack.y_position)
cost = self.heuristic(start_node, new_node)
can_place = self.location_classifier.check_if_can_place(package, rack)
cost = self.rack_heuristics(start_node, new_node, can_place)
if cost > 0:
racks_costs.append((rack, cost))
@ -236,4 +247,4 @@ class Agent:
pack.lays_on_field.capacity -= pack.size
pack.status = PackStatus.STORED
self.warehouse.packages.append(pack)
print(tile.air_temperature, tile.humidity)
# print(tile.air_temperature, tile.humidity)

View File

@ -26,7 +26,7 @@ class MainGameFrame:
agent_radius = int(TILE_WIDTH/2)
self.agent_tex = pygame.image.load('forklift.png')
self.font = pygame.font.Font('freesansbold.ttf', 16)
self.warehouse_map = warehouse.Warehouse(20, 20, 150, 20)
self.warehouse_map = warehouse.Warehouse(20, 20, 180, 50)
starting_x, starting_y = self.set_starting_agent_position()
self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map, agent_radius)
self.clock = pygame.time.Clock()
@ -43,18 +43,13 @@ class MainGameFrame:
self.draw_nums()
self.agent.move()
pygame.display.update()
self.clock.tick(5)
self.clock.tick(12)
def draw_floor(self):
for x in range(self.warehouse_map.width):
for y in range(self.warehouse_map.height):
self.draw_field(x, y)
def draw_target(self, x, y):
target_screen_position = (
(x * TILE_WIDTH) + CIRCLE_CENTER_X, (y * TILE_HEIGHT) + CIRCLE_CENTER_Y)
pygame.draw.circle(self.display, COLORS['lightblue'], target_screen_position, 6)
def draw_field(self, x, y):
current_tile = self.warehouse_map.tiles[x][y]
color = COLOR_OF_FIELD.get(current_tile.category.name, 'white')

View File

@ -1,4 +1,4 @@
from sklearn.tree import DecisionTreeClassifier, plot_tree, export_graphviz
from sklearn.tree import DecisionTreeClassifier, plot_tree, export_graphviz, DecisionTreeRegressor
from sklearn.externals.six import StringIO
from IPython.display import Image
import pandas as pd
@ -7,31 +7,72 @@ import pydotplus
from sklearn.model_selection import train_test_split
from sklearn import metrics
data = StringIO()
cols_names= ["product", "category", "temperature", "humidity", "chance_of_survive", "place_here"]
# import pdb
# pdb.set_trace()
products = pd.read_csv("trainset/trainset.csv", header=0, sep=",", names=cols_names)
feature_cols = ["category", "temperature", "humidity"]
X = pd.get_dummies(products[feature_cols])
y = products.place_here
dummies_names = X.columns.tolist()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1, shuffle=True)
clf = DecisionTreeClassifier(criterion="entropy", ccp_alpha=0.02, max_features=4)
clf = clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
print("Correctly placed in : {} % of cases".format(
round(100 * metrics.accuracy_score(y_test, y_pred), 3)
)
)
PACKAGE_PLACE_TRESHOLD = {
"normal": 0.8,
"freezed": 0.85,
"fragile": 0.85,
"flammable": 0.9,
"keep_dry": 0.8
}
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.write_png('Ułożenie.png')
Image(graph.create_png())
class PackageLocationClassifier():
def __init__(self):
data = StringIO()
cols_names = ["product", "category", "temperature", "humidity", "chance_of_survive", "place_here"]
feature_cols = ["category", "temperature", "humidity"]
products = pd.read_csv("package_location_classifier/trainset/trainset.csv", header=0, sep=",", names=cols_names)
testset = pd.read_csv("package_location_classifier/testset/testset.csv", header=None, sep=",", names=cols_names)
products = products.round({"chance_of_survive": 1})
testset = testset.round({"chance_of_survive": 1})
products.chance_of_survive *= 10
testset.chance_of_survive *= 10
test_X = pd.get_dummies(testset[feature_cols])
test_y = testset.chance_of_survive
products = products.sample(frac=1)
X = pd.get_dummies(products[feature_cols])
y = products.chance_of_survive
dummies_names = X.columns.tolist()
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)
self.predictor = clf.fit(X_train, y_train)
y_pred = self.predictor.predict(test_X)
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'])
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)
graph = pydotplus.graph_from_dot_data(data.getvalue())
graph.write_png('Ułożenie.png')
Image(graph.create_png())
def check_if_can_place(self, package, tile):
category = package.category
cat_treshold = PACKAGE_PLACE_TRESHOLD[category]
fields = [[
tile.air_temperature,
tile.humidity,
category == "flammable",
category == "fragile",
category=="freezed" ,
category == "keep_dry",
category == "normal"
]]
quality_of_place = round(self.predictor.predict(fields)[0]/10, 2)
# print("{} - dopasowanie {}".format(package,quality_of_place))
# pdb.set_trace()
if quality_of_place > cat_treshold:
return True
return False
if __name__ == '__main__':
cfer = PackageLocationClassifier()

View File

@ -0,0 +1,26 @@
food,normal,20,0.3,0.95,1
food,normal,-15,0.3,0.2,0
metal,normal,-15,0.3,0.2,0
frozen_food,freezed,-15,0.2,1,1
frozen_food,freezed,20,0.3,0.01,0
frozen_food,freezed,30,0.5,0,0
frozen_food,freezed,28,0.5,0,0
frozen_food,freezed,28,0.3,0,0
electronic,keep_dry,22,0.3,0.99,1
electronic,keep_dry,25,0.3,0.99,1
electronic,keep_dry,25,0.7,0.4,0
electronic,keep_dry,28,0.7,0.3,0
gasoline,flammable,28,0.3,0.2,0
gasoline,flammable,28,0.7,0.2,0
gasoline,flammable,22,0.5,0.95,0
gasoline,flammable,20,0.5,1,1
gasoline,flammable,20,0.2,1,1
books,keep_dry,30,0.7,0.3,0
books,keep_dry,30,0.3,0.85,1
books,keep_dry,25,0.2,1,1
glass,fragile,-15,0.3,0.1,0
seeds,freezed,-15,0.3,1,1
seeds,freezed,20,0.3,0.1,0
metal,normal,25,0.4,0.99,1
wood,normal,26,0.3,0.99,1
wood,normal,22,0.3,1,1
1 food normal 20 0.3 0.95 1
2 food normal -15 0.3 0.2 0
3 metal normal -15 0.3 0.2 0
4 frozen_food freezed -15 0.2 1 1
5 frozen_food freezed 20 0.3 0.01 0
6 frozen_food freezed 30 0.5 0 0
7 frozen_food freezed 28 0.5 0 0
8 frozen_food freezed 28 0.3 0 0
9 electronic keep_dry 22 0.3 0.99 1
10 electronic keep_dry 25 0.3 0.99 1
11 electronic keep_dry 25 0.7 0.4 0
12 electronic keep_dry 28 0.7 0.3 0
13 gasoline flammable 28 0.3 0.2 0
14 gasoline flammable 28 0.7 0.2 0
15 gasoline flammable 22 0.5 0.95 0
16 gasoline flammable 20 0.5 1 1
17 gasoline flammable 20 0.2 1 1
18 books keep_dry 30 0.7 0.3 0
19 books keep_dry 30 0.3 0.85 1
20 books keep_dry 25 0.2 1 1
21 glass fragile -15 0.3 0.1 0
22 seeds freezed -15 0.3 1 1
23 seeds freezed 20 0.3 0.1 0
24 metal normal 25 0.4 0.99 1
25 wood normal 26 0.3 0.99 1
26 wood normal 22 0.3 1 1

View File

@ -45,7 +45,7 @@ clothes,keep_dry, 22, 0.4, 0.95, 1
clothes,keep_dry, 21, 0.5, 0.5, 0
metal,normal,20, 0.3, 1, 1
metal,normal, 21, 0.3, 1, 1
metal,normal, -10, 0.3, 0.98, 1
metal,normal, -10, 0.3, 0.2, 1
metal,normal,28, 0.7, 0.9, 1
metal,normal,30, 0.7, 0.9, 1
wood,normal,25, 0.2, 0.98, 1
@ -64,9 +64,9 @@ drugs,keep_dry, 28, 0.3, 0.81, 0
drugs,keep_dry, 23, 0.3, 0.88, 1
drugs,keep_dry, 21, 0.37, 0.90, 1
glass,fragile, 20, 0.7, 0.995, 1
glass,fragile, -15, 0.3, 0.7, 0
vials,fragile, -15, 0.3, 0.75, 0
vials,fragile, 20, 0.5, 0.92, 1
glass,fragile, -15, 0.3, 0.2, 0
vials,fragile, -15, 0.3, 0.2, 0
vials,fragile, 20, 0.5, 0.95, 1
plate,fragile, 25, 0.3, 1, 1
phials,fragile, 25, 0.5, 0.999, 1
cardboard,keep_dry, 22, 0.3, 0.999, 1
@ -94,6 +94,26 @@ frozen food,freezed,-14, 0.3, 1, 1
frozen food,freezed,-12, 0.3, 0.999, 1
frozen food,freezed,-10, 0.3, 0.99, 1
frozen food,freezed,20, 0.5, 0.01, 0
food,normal,28,0.5,0.7,0
food,normal,26,0.3,0.9,1
food,normal,22,0.3,0.99,1
gasoline,flammable, 20, 0.4, 1, 1
gasoline,flammable,-15,0.3,0.5,0
metal,normal,-15,0.3,0.1,0
metal,normal,-15,0.4,0.1,0
metal,normal,-15,0.2,0.1,0
metal,normal,-10,0.2,0.1,0
electronic,keep_dry,-15,0.3,0.1,0
lacquer,flammable,-15,0.3,0.2,0
books,keep_dry,-15,0.3,0.3,0
plate,fragile, 20, 0.7, 1, 1
plate,fragile, 24, 0.3, 1, 1
plate,fragile, -15, 0.3, 0.15, 0
plate,fragile, -10, 0.3, 0.2, 0
vials,fragile, -15, 0.3, 0.12, 0
vials,fragile, 20, 0.7, 1, 1
vials,fragile, 20, 0.2, 1, 1
books,keep_dry, 20, 0.3, 1, 1
frozen food,freezed,20, 0.3, 0.01, 0
frozen food,freezed,22, 0.5, 0.01, 0
frozen food,freezed,22, 0.2, 0.01, 0
@ -115,7 +135,6 @@ frozen food,freezed,25, 0.5, 0.01, 0
frozen food,freezed,20, 0.3, 0.01, 0
frozen food,freezed,20, 0.7, 0.01, 0
frozen food,freezed,20, 0.2, 0.01, 0
seeds,freezed, 25, 0.5, 0.2, 0
seeds,freezed, 20, 0.8, 0.01, 0
seeds,freezed, -10, 0.3, 0.998, 1
@ -176,10 +195,10 @@ gasoline,flammable, 20, 0.5, 1, 1
gasoline,flammable, 20, 0.7, 1, 1
gasoline,flammable, 20, 0.4, 1, 1
plate,fragile, 20, 0.7, 1, 1
plate,fragie, 24, 0.3, 1, 1
plate,fragile, -15, 0.3, 0.6, 0
plate,fragile, -10, 0.3, 0.65, 0
vials,fragile, -15, 0.3, 0.6, 0
plate,fragile, 24, 0.3, 1, 1
plate,fragile, -15, 0.3, 0.1, 0
plate,fragile, -10, 0.3, 0.2, 0
vials,fragile, -15, 0.3, 0.15, 0
vials,fragile, 20, 0.7, 1, 1
vials,fragile, 20, 0.2, 1, 1
books,keep_dry, 20, 0.3, 1, 1
@ -238,13 +257,120 @@ wood,normal, 20, 0.3, 1, 1
wood,normal, 23, 0.2, 1, 1
wood,normal, 23, 0.7, 0.98, 1
wood,normal,30,0.7,0.95,1
books,keep_dry, 20, 0.7, 0.79, 0
books,keep_dry, 25, 0.7, 0.75, 0
books,keep_dry, 25, 0.2, 0.99, 1
books,keep_dry,-15,0.3,0.2,0
books,keep_dry,-15,0.2,0.2,0
cardboard,keep_dry,-10,0.2,0.2,0
cardboard,keep_dry,-15,0.3,0.2,0
books,keep_dry, 28, 0.2, 0.9, 1
books,keep_dry, 28, 0.7, 0.2, 0
books,keep_dry, 28, 0.6, 0.25, 0
books,keep_dry, 26, 0.6, 0.28, 0
seeds,freezed, -15, 0.3, 1, 1
seeds,freezed, -15, 0.3, 1, 1
seeds,freezed, -15, 0.3, 1, 1
seeds,freezed, -15, 0.3, 1, 1
seeds,freezed, -15, 0.3, 1, 1
seeds,freezed, -15, 0.3, 1, 1
books,keep_dry,26, 0.2, 0.95, 1
cardboard,keep_dry, 28, 0.7, 0.15, 0
cardboard,keep_dry, 28, 0.2, 0.9, 1
cardboard,keep_dry, 25, 0.2, 0.95, 1
cardboard,keep_dry, 25, 0.6, 0.3, 0
cardboard,keep_dry, 25, 0.7, 0.2, 0
electronics,keep_dry, 21, 0.4, 0.999, 1
electronic,keep_dry, 21, 0.7, 0.68, 0
electronic,keep_dry, 29, 0.2, 0.998, 1
electronic,keep_dry, 29, 0.6, 0.45, 0
cardboard,keep_dry, 30, 0.7, 0.2, 0
cardboard,keep_dry, 30, 0.6, 0.25, 0
electronic,keep_dry, 29, 0.7, 0.35, 0
electronic,keep_dry, 25, 0.4, 0.82, 1
electronic,keep_dry, 25, 0.5, 0.70, 0
electronic,keep_dry, 25, 0.7, 0.5, 0
electronic,keep_dry, 28, 0.2, 0.995, 1
electronic,keep_dry, 28, 0.4, 0.81, 1
electronic,keep_dry, 28, 0.6, 0.5, 0
electronic,keep_dry, 28, 0.7, 0.4, 0
electronic,keep_dry, 28, 0.3, 0.93, 1
clothes,keep_dry, 28, 0.3, 0.95, 1
clothes,keep_dry, 28, 0.2, 0.999, 1
clothes,keep_dry, 28, 0.7, 0.3, 0
wood,normal, 27, 0.2, 1, 1
wood,normal, 27, 0.7, 0.95, 1
wood,normal, 25, 0.7, 0.96, 1
wood,normal, 20, 0.3, 1, 1
cardboard,keep_dry, 28, 0.5, 0.55, 0
cardboard,keep_dry, 25, 0.7, 0.45, 0
cardboard,keep_dry, 27, 0.3, 0.9, 1
cardboard,keep_dry, 29, 0.3, 0.9, 1
cardboard,keep_dry, 24, 0.4, 0.8, 1
frozen food,freezed, 20, 0.4, 0.001, 0
seeds,freezed, 25, 0.5, 0.2, 0
seeds,freezed, 20, 0.8, 0.01, 0
seeds,freezed, -10, 0.3, 0.998, 1
seeds,freezed, 20, 0.3, 0.6, 0
seeds,freezed, -8, 0.3, 0.99, 1
seeds,freezed, -10, 0.5, 0.995, 1
seeds,freezed, -15, 0.3, 1, 1
seeds,freezed, -15, 0.4, 1, 1
frozen food,freezed,-15, 0.3, 1, 1
frozen food,freezed,-15, 0.3, 1, 1
frozen food,freezed,-15, 0.3, 1, 1
frozen food,freezed,-15, 0.3, 1, 1
frozen food,freezed,-14, 0.3, 1, 1
frozen food,freezed,-12, 0.3, 0.999, 1
frozen food,freezed,-2, 0.3, 0.7, 0
frozen food,freezed,2, 0.3, 0.5, 0
frozen food,freezed,5, 0.3, 0.2, 0
frozen food,freezed,-10, 0.3, 0.99, 1
frozen food,freezed,20, 0.3, 0, 0
frozen food,freezed,25, 0.3, 0, 0
frozen food,freezed,25, 0.7, 0, 0
frozen food,freezed,22, 0.4, 0, 0
frozen food,freezed,22, 0.5, 0, 0
frozen food,freezed,22, 0.2, 0, 0
seeds,freezed, 25, 0.5, 0, 0
seeds,freezed, 20, 0.8, 0.01, 0
seeds,freezed, -5, 0.3, 0.5, 1
seeds,freezed, 20, 0.3, 0.1, 0
seeds,freezed, -8, 0.3, 0.8, 1
seeds,freezed, 20, 0.5, 0.1, 0
wood,normal, 20, 0.3, 1, 1
wood,normal, 23, 0.2, 1, 1
wood,normal, 23, 0.7, 0.98, 1
electronic,keep_dry, 29, 0.6, 0.45, 0
electronic,keep_dry, 29, 0.7, 0.35, 0
electronic,keep_dry, 24, 0.4, 0.82, 1
electronic,keep_dry, 20, 0.5, 0.72, 0
electronic,keep_dry, 25, 0.7, 0.5, 0
electronic,keep_dry, 28, 0.2, 0.995, 1
electronic,keep_dry, 28, 0.4, 0.81, 1
electronic,keep_dry, 28, 0.6, 0.5, 0
electronic,keep_dry, 30, 0.7, 0.35, 0
electronic,keep_dry, 28, 0.3, 0.93, 1
clothes,keep_dry, 28, 0.3, 0.95, 1
clothes,keep_dry, 28, 0.2, 0.999, 1
clothes,keep_dry, 28, 0.7, 0.3, 0
wood,normal, 27, 0.2, 1, 1
wood,normal, 27, 0.7, 0.95, 1
wood,normal, 25, 0.7, 0.96, 1
wood,normal, 20, 0.3, 1, 1
wood,normal, 23, 0.2, 1, 1
wood,normal, 23, 0.7, 0.98, 1
wood,normal,-10,0.3,0.2,0
wood,normal,-15,0.3,0.1,0
wood,normal,-15,0.2,0.2,0
wood,normal,-15,0.3,0.1,0
wood,normal,30,0.7,0.95,1
food,normal,28,0.5,0.7,0
food,normal,26,0.3,0.9,1
food,normal,-15,0.2,0.2,0
food,normal,-12,0.2,0.3,0
electronic,keep_dry,-15,0.3,0.1,0
food,normal,-15,0.3,0.2,0
food,normal,22,0.3,0.99,1

1 product category temperature humidity chance_of_survive place_here
45 clothes keep_dry 21 0.5 0.5 0
46 metal normal 20 0.3 1 1
47 metal normal 21 0.3 1 1
48 metal normal -10 0.3 0.98 0.2 1
49 metal normal 28 0.7 0.9 1
50 metal normal 30 0.7 0.9 1
51 wood normal 25 0.2 0.98 1
64 drugs keep_dry 23 0.3 0.88 1
65 drugs keep_dry 21 0.37 0.90 1
66 glass fragile 20 0.7 0.995 1
67 glass fragile -15 0.3 0.7 0.2 0
68 vials fragile -15 0.3 0.75 0.2 0
69 vials fragile 20 0.5 0.92 0.95 1
70 plate fragile 25 0.3 1 1
71 phials fragile 25 0.5 0.999 1
72 cardboard keep_dry 22 0.3 0.999 1
94 frozen food freezed -12 0.3 0.999 1
95 frozen food freezed -10 0.3 0.99 1
96 frozen food freezed 20 0.5 0.01 0
97 food normal 28 0.5 0.7 0
98 food normal 26 0.3 0.9 1
99 food normal 22 0.3 0.99 1
100 gasoline flammable 20 0.4 1 1
101 gasoline flammable -15 0.3 0.5 0
102 metal normal -15 0.3 0.1 0
103 metal normal -15 0.4 0.1 0
104 metal normal -15 0.2 0.1 0
105 metal normal -10 0.2 0.1 0
106 electronic keep_dry -15 0.3 0.1 0
107 lacquer flammable -15 0.3 0.2 0
108 books keep_dry -15 0.3 0.3 0
109 plate fragile 20 0.7 1 1
110 plate fragile 24 0.3 1 1
111 plate fragile -15 0.3 0.15 0
112 plate fragile -10 0.3 0.2 0
113 vials fragile -15 0.3 0.12 0
114 vials fragile 20 0.7 1 1
115 vials fragile 20 0.2 1 1
116 books keep_dry 20 0.3 1 1
117 frozen food freezed 20 0.3 0.01 0
118 frozen food freezed 22 0.5 0.01 0
119 frozen food freezed 22 0.2 0.01 0
135 frozen food freezed 20 0.3 0.01 0
136 frozen food freezed 20 0.7 0.01 0
137 frozen food freezed 20 0.2 0.01 0
seeds freezed 25 0.5 0.2 0
138 seeds freezed 20 25 0.8 0.5 0.01 0.2 0
139 seeds freezed -10 20 0.3 0.8 0.998 0.01 1 0
140 seeds freezed 20 -10 0.3 0.6 0.998 0 1
195 gasoline flammable 20 0.4 0.7 1 1
196 plate gasoline fragile flammable 20 0.7 0.4 1 1
197 plate fragie fragile 24 20 0.3 0.7 1 1
198 plate fragile -15 24 0.3 0.6 1 0 1
199 plate fragile -10 -15 0.3 0.65 0.1 0
200 vials plate fragile -15 -10 0.3 0.6 0.2 0
201 vials fragile 20 -15 0.7 0.3 1 0.15 1 0
202 vials fragile 20 0.2 0.7 1 1
203 books vials keep_dry fragile 20 0.3 0.2 1 1
204 books keep_dry 20 0.7 0.3 0.79 1 0 1
257 wood normal 23 0.7 0.2 0.98 1 1
258 wood normal 30 23 0.7 0.95 0.98 1
259 food wood normal 28 30 0.5 0.7 0.7 0.95 0 1
260 books keep_dry 20 0.7 0.79 0
261 books keep_dry 25 0.7 0.75 0
262 books keep_dry 25 0.2 0.99 1
263 books keep_dry -15 0.3 0.2 0
264 books keep_dry -15 0.2 0.2 0
265 cardboard keep_dry -10 0.2 0.2 0
266 cardboard keep_dry -15 0.3 0.2 0
267 books keep_dry 28 0.2 0.9 1
268 books keep_dry 28 0.7 0.2 0
269 books keep_dry 28 0.6 0.25 0
270 books keep_dry 26 0.6 0.28 0
271 seeds freezed -15 0.3 1 1
272 seeds freezed -15 0.3 1 1
273 seeds freezed -15 0.3 1 1
274 seeds freezed -15 0.3 1 1
275 seeds freezed -15 0.3 1 1
276 seeds freezed -15 0.3 1 1
277 books keep_dry 26 0.2 0.95 1
278 cardboard keep_dry 28 0.7 0.15 0
279 cardboard keep_dry 28 0.2 0.9 1
280 cardboard keep_dry 25 0.2 0.95 1
281 cardboard keep_dry 25 0.6 0.3 0
282 cardboard keep_dry 25 0.7 0.2 0
283 electronics keep_dry 21 0.4 0.999 1
284 electronic keep_dry 21 0.7 0.68 0
285 electronic keep_dry 29 0.2 0.998 1
286 electronic keep_dry 29 0.6 0.45 0
287 cardboard keep_dry 30 0.7 0.2 0
288 cardboard keep_dry 30 0.6 0.25 0
289 electronic keep_dry 29 0.7 0.35 0
290 electronic keep_dry 25 0.4 0.82 1
291 electronic keep_dry 25 0.5 0.70 0
292 electronic keep_dry 25 0.7 0.5 0
293 electronic keep_dry 28 0.2 0.995 1
294 electronic keep_dry 28 0.4 0.81 1
295 electronic keep_dry 28 0.6 0.5 0
296 electronic keep_dry 28 0.7 0.4 0
297 electronic keep_dry 28 0.3 0.93 1
298 clothes keep_dry 28 0.3 0.95 1
299 clothes keep_dry 28 0.2 0.999 1
300 clothes keep_dry 28 0.7 0.3 0
301 wood normal 27 0.2 1 1
302 wood normal 27 0.7 0.95 1
303 wood normal 25 0.7 0.96 1
304 wood normal 20 0.3 1 1
305 cardboard keep_dry 28 0.5 0.55 0
306 cardboard keep_dry 25 0.7 0.45 0
307 cardboard keep_dry 27 0.3 0.9 1
308 cardboard keep_dry 29 0.3 0.9 1
309 cardboard keep_dry 24 0.4 0.8 1
310 frozen food freezed 20 0.4 0.001 0
311 seeds freezed 25 0.5 0.2 0
312 seeds freezed 20 0.8 0.01 0
313 seeds freezed -10 0.3 0.998 1
314 seeds freezed 20 0.3 0.6 0
315 seeds freezed -8 0.3 0.99 1
316 seeds freezed -10 0.5 0.995 1
317 seeds freezed -15 0.3 1 1
318 seeds freezed -15 0.4 1 1
319 frozen food freezed -15 0.3 1 1
320 frozen food freezed -15 0.3 1 1
321 frozen food freezed -15 0.3 1 1
322 frozen food freezed -15 0.3 1 1
323 frozen food freezed -14 0.3 1 1
324 frozen food freezed -12 0.3 0.999 1
325 frozen food freezed -2 0.3 0.7 0
326 frozen food freezed 2 0.3 0.5 0
327 frozen food freezed 5 0.3 0.2 0
328 frozen food freezed -10 0.3 0.99 1
329 frozen food freezed 20 0.3 0 0
330 frozen food freezed 25 0.3 0 0
331 frozen food freezed 25 0.7 0 0
332 frozen food freezed 22 0.4 0 0
333 frozen food freezed 22 0.5 0 0
334 frozen food freezed 22 0.2 0 0
335 seeds freezed 25 0.5 0 0
336 seeds freezed 20 0.8 0.01 0
337 seeds freezed -5 0.3 0.5 1
338 seeds freezed 20 0.3 0.1 0
339 seeds freezed -8 0.3 0.8 1
340 seeds freezed 20 0.5 0.1 0
341 wood normal 20 0.3 1 1
342 wood normal 23 0.2 1 1
343 wood normal 23 0.7 0.98 1
344 electronic keep_dry 29 0.6 0.45 0
345 electronic keep_dry 29 0.7 0.35 0
346 electronic keep_dry 24 0.4 0.82 1
347 electronic keep_dry 20 0.5 0.72 0
348 electronic keep_dry 25 0.7 0.5 0
349 electronic keep_dry 28 0.2 0.995 1
350 electronic keep_dry 28 0.4 0.81 1
351 electronic keep_dry 28 0.6 0.5 0
352 electronic keep_dry 30 0.7 0.35 0
353 electronic keep_dry 28 0.3 0.93 1
354 clothes keep_dry 28 0.3 0.95 1
355 clothes keep_dry 28 0.2 0.999 1
356 clothes keep_dry 28 0.7 0.3 0
357 wood normal 27 0.2 1 1
358 wood normal 27 0.7 0.95 1
359 wood normal 25 0.7 0.96 1
360 wood normal 20 0.3 1 1
361 wood normal 23 0.2 1 1
362 wood normal 23 0.7 0.98 1
363 wood normal -10 0.3 0.2 0
364 wood normal -15 0.3 0.1 0
365 wood normal -15 0.2 0.2 0
366 wood normal -15 0.3 0.1 0
367 wood normal 30 0.7 0.95 1
368 food normal 26 28 0.3 0.5 0.9 0.7 1 0
369 food normal 22 26 0.3 0.99 0.9 1
370 food normal -15 0.2 0.2 0
371 food normal -12 0.2 0.3 0
372 electronic keep_dry -15 0.3 0.1 0
373 food normal -15 0.3 0.2 0
374 food normal 22 0.3 0.99 1
375
376

View File

@ -5,7 +5,7 @@ import queue
from collections import namedtuple
import itertools
Coordinates = namedtuple("Coordinates",'x y')
Coordinates = namedtuple("Coordinates", 'x y')
class CategoryData:
def __init__(self, name, passable=False, can_store=True, location='general'):
@ -18,7 +18,7 @@ class CategoryData:
return self.name
class Pack:
def __init__(self, size=5, categ='general', lays_on_field=None):
def __init__(self, size=5, categ='normal', lays_on_field=None):
self.size = size
self.category = categ
self.products_inside = self.set_products_inside()
@ -31,9 +31,6 @@ class Pack:
status = PackStatus.LOOSE
if self.lays_on_field.category.name in ['Floor', 'FridgeFloor']:
status = PackStatus.LOOSE
elif self.lays_on_field.category.name in ['Rack', 'Fridge']:
if self.category == 'freezed' and self.lays_on_field.category.name != 'Fridge':
status = PackStatus.STORED_BAD_LOCATION
else:
status = PackStatus.STORED
return status
@ -53,10 +50,13 @@ class Pack:
products_category = "flammable"
products_in_category = PRODUCT_TYPES.get(products_category, ["food"])
self.category = products_category
product_inside = random.choice(products_in_category)
print(product_inside)
# print(product_inside)
return product_inside
def __repr__(self):
return "Pack {} -{}, on field {}".format(self.products_inside, self.category, self.lays_on_field)
CATEGORY = {
'floor': CategoryData('Floor', True, False), #lava
@ -78,8 +78,8 @@ class Warehouse:
self.open_isolated_areas()
self.set_temperature(20, 30)
self.set_humidity()
self.create_fridge(10)
print([row[0].air_temperature for row in self.tiles])
self.create_fridge(8)
# print([row[0].air_temperature for row in self.tiles])
self.packages = self.place_packages(no_of_packages)
self.tiles[1][1] = Tile('floor', 1, 1)
def __str__(self):
@ -99,7 +99,7 @@ class Warehouse:
node_x, node_y = random.randrange(1, self.width-1), random.randrange(1, self.height-1)
node = self.tiles[node_x][node_y]
next_node = None
self.tiles[node_x][node_y] = Tile('rack', node_x, node_y, capacity=random.randrange(16, 20))
self.tiles[node_x][node_y] = Tile('rack', node_x, node_y, capacity=random.randrange(15, 20), temperature=node.air_temperature, humidity=node.humidity)
q.put(node)
while not q.empty():
if next_node is not None:
@ -121,7 +121,7 @@ class Warehouse:
return
node_x = next_node.x_position
node_y = next_node.y_position
self.tiles[node_x][node_y] = Tile('rack', node_x, node_y)
self.tiles[node_x][node_y] = Tile('rack', node_x, node_y, capacity=random.randrange(15, 20), temperature=next_node.air_temperature, humidity=next_node.humidity)
def set_temperature(self, min_temperature=20, max_temperature=30):
for num, row in enumerate(self.tiles):
@ -149,8 +149,6 @@ class Warehouse:
start_x = 0
end_x = size
else:
# import pdb
# pdb.set_trace()
start_x = (self.width-1) - size
end_x = self.width - 1
@ -240,10 +238,6 @@ class Warehouse:
pack_x, pack_y = self._set_package_position(new_package_size)
package_field = self.tiles[pack_x][pack_y]
new_package = Pack(lays_on_field=package_field)
categ_seed = random.random()
if categ_seed > 0.8:
new_package.category = "freezed"
# new_package.set_status()
new_package.size = new_package_size
if package_field.category.name in self.storage_types:
package_field.capacity -= new_package.size
@ -253,7 +247,7 @@ class Warehouse:
def _set_package_position(self, pack_size: int):
starting_x, starting_y = random.randrange(self.width), random.randrange(self.height)
while not isinstance(self.tiles[starting_x][starting_y], Tile) \
and self.tiles[starting_x][starting_y].size - pack_size < 0:
or self.tiles[starting_x][starting_y].capacity - pack_size < 0:
starting_x, starting_y = random.randrange(self.width), random.randrange(
self.height)
return starting_x, starting_y