Merge branch 'master' of https://git.wmi.amu.edu.pl/s444360/SI_2020
This commit is contained in:
commit
9b693a0d1c
33
agent.py
33
agent.py
@ -4,6 +4,8 @@ from math import sqrt
|
|||||||
from attributes import TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS, PackStatus
|
from attributes import TURN_LEFT_DIRECTIONS, TURN_RIGHT_DIRECTIONS, PackStatus
|
||||||
import pygame
|
import pygame
|
||||||
import sys
|
import sys
|
||||||
|
import pdb
|
||||||
|
from package_location_classifier.classifier import PackageLocationClassifier
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, coord_x, coord_y, package=None, is_rack=False):
|
def __init__(self, coord_x, coord_y, package=None, is_rack=False):
|
||||||
@ -38,6 +40,14 @@ class Agent:
|
|||||||
self.closed = list()
|
self.closed = list()
|
||||||
self.open = PriorityQueue()
|
self.open = PriorityQueue()
|
||||||
self.path = list()
|
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):
|
def find_path(self):
|
||||||
@ -90,14 +100,6 @@ class Agent:
|
|||||||
diff_x = pow(goal.x - start.x, 2)
|
diff_x = pow(goal.x - start.x, 2)
|
||||||
diff_y = pow(goal.y - start.y, 2)
|
diff_y = pow(goal.y - start.y, 2)
|
||||||
additional_cost = 0
|
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)
|
return round(sqrt(diff_x + diff_y), 3) + float(10*additional_cost)
|
||||||
|
|
||||||
def check_if_open(self, node: Node):
|
def check_if_open(self, node: Node):
|
||||||
@ -168,7 +170,7 @@ class Agent:
|
|||||||
if not tile_on_map:
|
if not tile_on_map:
|
||||||
return False
|
return False
|
||||||
next_tile = self.warehouse.tiles[next_coords.x][next_coords.y]
|
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
|
tile_passable = isinstance(next_tile, Tile) and next_tile.category.passable
|
||||||
return tile_passable
|
return tile_passable
|
||||||
|
|
||||||
@ -188,9 +190,17 @@ class Agent:
|
|||||||
return
|
return
|
||||||
# pygame.quit()
|
# pygame.quit()
|
||||||
# sys.exit()
|
# sys.exit()
|
||||||
|
|
||||||
package = min(packages_costs, key=lambda l: l[1])[0]
|
package = min(packages_costs, key=lambda l: l[1])[0]
|
||||||
return package
|
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):
|
def find_nearest_rack_for(self, package, expand_box=0):
|
||||||
weight = package.size
|
weight = package.size
|
||||||
storage = "Rack"
|
storage = "Rack"
|
||||||
@ -209,7 +219,8 @@ class Agent:
|
|||||||
racks_costs = []
|
racks_costs = []
|
||||||
for rack in quarter_racks:
|
for rack in quarter_racks:
|
||||||
new_node = Node(rack.x_position, rack.y_position)
|
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:
|
if cost > 0:
|
||||||
racks_costs.append((rack, cost))
|
racks_costs.append((rack, cost))
|
||||||
|
|
||||||
@ -236,4 +247,4 @@ class Agent:
|
|||||||
pack.lays_on_field.capacity -= pack.size
|
pack.lays_on_field.capacity -= pack.size
|
||||||
pack.status = PackStatus.STORED
|
pack.status = PackStatus.STORED
|
||||||
self.warehouse.packages.append(pack)
|
self.warehouse.packages.append(pack)
|
||||||
print(tile.air_temperature, tile.humidity)
|
# print(tile.air_temperature, tile.humidity)
|
||||||
|
9
main.py
9
main.py
@ -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, 150, 20)
|
self.warehouse_map = warehouse.Warehouse(20, 20, 180, 50)
|
||||||
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()
|
||||||
@ -43,18 +43,13 @@ class MainGameFrame:
|
|||||||
self.draw_nums()
|
self.draw_nums()
|
||||||
self.agent.move()
|
self.agent.move()
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
self.clock.tick(5)
|
self.clock.tick(12)
|
||||||
|
|
||||||
def draw_floor(self):
|
def draw_floor(self):
|
||||||
for x in range(self.warehouse_map.width):
|
for x in range(self.warehouse_map.width):
|
||||||
for y in range(self.warehouse_map.height):
|
for y in range(self.warehouse_map.height):
|
||||||
self.draw_field(x, y)
|
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):
|
def draw_field(self, x, y):
|
||||||
current_tile = self.warehouse_map.tiles[x][y]
|
current_tile = self.warehouse_map.tiles[x][y]
|
||||||
color = COLOR_OF_FIELD.get(current_tile.category.name, 'white')
|
color = COLOR_OF_FIELD.get(current_tile.category.name, 'white')
|
||||||
|
@ -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 sklearn.externals.six import StringIO
|
||||||
from IPython.display import Image
|
from IPython.display import Image
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@ -7,31 +7,72 @@ import pydotplus
|
|||||||
from sklearn.model_selection import train_test_split
|
from sklearn.model_selection import train_test_split
|
||||||
from sklearn import metrics
|
from sklearn import metrics
|
||||||
|
|
||||||
|
PACKAGE_PLACE_TRESHOLD = {
|
||||||
|
"normal": 0.8,
|
||||||
|
"freezed": 0.85,
|
||||||
|
"fragile": 0.85,
|
||||||
|
"flammable": 0.9,
|
||||||
|
"keep_dry": 0.8
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class PackageLocationClassifier():
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
data = StringIO()
|
data = StringIO()
|
||||||
|
|
||||||
cols_names = ["product", "category", "temperature", "humidity", "chance_of_survive", "place_here"]
|
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"]
|
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])
|
X = pd.get_dummies(products[feature_cols])
|
||||||
y = products.place_here
|
y = products.chance_of_survive
|
||||||
dummies_names = X.columns.tolist()
|
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)
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.01, random_state=1, shuffle=True)
|
||||||
|
|
||||||
clf = DecisionTreeClassifier(criterion="entropy", ccp_alpha=0.02, max_features=4)
|
clf = DecisionTreeRegressor(ccp_alpha=0.02, min_samples_leaf=5, max_depth=6)
|
||||||
clf = clf.fit(X_train, y_train)
|
self.predictor = 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)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
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('Ułożenie.png')
|
||||||
Image(graph.create_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()
|
26
package_location_classifier/testset/testset.csv
Normal file
26
package_location_classifier/testset/testset.csv
Normal 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
|
|
@ -45,7 +45,7 @@ clothes,keep_dry, 22, 0.4, 0.95, 1
|
|||||||
clothes,keep_dry, 21, 0.5, 0.5, 0
|
clothes,keep_dry, 21, 0.5, 0.5, 0
|
||||||
metal,normal,20, 0.3, 1, 1
|
metal,normal,20, 0.3, 1, 1
|
||||||
metal,normal, 21, 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,28, 0.7, 0.9, 1
|
||||||
metal,normal,30, 0.7, 0.9, 1
|
metal,normal,30, 0.7, 0.9, 1
|
||||||
wood,normal,25, 0.2, 0.98, 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, 23, 0.3, 0.88, 1
|
||||||
drugs,keep_dry, 21, 0.37, 0.90, 1
|
drugs,keep_dry, 21, 0.37, 0.90, 1
|
||||||
glass,fragile, 20, 0.7, 0.995, 1
|
glass,fragile, 20, 0.7, 0.995, 1
|
||||||
glass,fragile, -15, 0.3, 0.7, 0
|
glass,fragile, -15, 0.3, 0.2, 0
|
||||||
vials,fragile, -15, 0.3, 0.75, 0
|
vials,fragile, -15, 0.3, 0.2, 0
|
||||||
vials,fragile, 20, 0.5, 0.92, 1
|
vials,fragile, 20, 0.5, 0.95, 1
|
||||||
plate,fragile, 25, 0.3, 1, 1
|
plate,fragile, 25, 0.3, 1, 1
|
||||||
phials,fragile, 25, 0.5, 0.999, 1
|
phials,fragile, 25, 0.5, 0.999, 1
|
||||||
cardboard,keep_dry, 22, 0.3, 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,-12, 0.3, 0.999, 1
|
||||||
frozen food,freezed,-10, 0.3, 0.99, 1
|
frozen food,freezed,-10, 0.3, 0.99, 1
|
||||||
frozen food,freezed,20, 0.5, 0.01, 0
|
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,20, 0.3, 0.01, 0
|
||||||
frozen food,freezed,22, 0.5, 0.01, 0
|
frozen food,freezed,22, 0.5, 0.01, 0
|
||||||
frozen food,freezed,22, 0.2, 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.3, 0.01, 0
|
||||||
frozen food,freezed,20, 0.7, 0.01, 0
|
frozen food,freezed,20, 0.7, 0.01, 0
|
||||||
frozen food,freezed,20, 0.2, 0.01, 0
|
frozen food,freezed,20, 0.2, 0.01, 0
|
||||||
|
|
||||||
seeds,freezed, 25, 0.5, 0.2, 0
|
seeds,freezed, 25, 0.5, 0.2, 0
|
||||||
seeds,freezed, 20, 0.8, 0.01, 0
|
seeds,freezed, 20, 0.8, 0.01, 0
|
||||||
seeds,freezed, -10, 0.3, 0.998, 1
|
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.7, 1, 1
|
||||||
gasoline,flammable, 20, 0.4, 1, 1
|
gasoline,flammable, 20, 0.4, 1, 1
|
||||||
plate,fragile, 20, 0.7, 1, 1
|
plate,fragile, 20, 0.7, 1, 1
|
||||||
plate,fragie, 24, 0.3, 1, 1
|
plate,fragile, 24, 0.3, 1, 1
|
||||||
plate,fragile, -15, 0.3, 0.6, 0
|
plate,fragile, -15, 0.3, 0.1, 0
|
||||||
plate,fragile, -10, 0.3, 0.65, 0
|
plate,fragile, -10, 0.3, 0.2, 0
|
||||||
vials,fragile, -15, 0.3, 0.6, 0
|
vials,fragile, -15, 0.3, 0.15, 0
|
||||||
vials,fragile, 20, 0.7, 1, 1
|
vials,fragile, 20, 0.7, 1, 1
|
||||||
vials,fragile, 20, 0.2, 1, 1
|
vials,fragile, 20, 0.2, 1, 1
|
||||||
books,keep_dry, 20, 0.3, 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.2, 1, 1
|
||||||
wood,normal, 23, 0.7, 0.98, 1
|
wood,normal, 23, 0.7, 0.98, 1
|
||||||
wood,normal,30,0.7,0.95,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,28,0.5,0.7,0
|
||||||
food,normal,26,0.3,0.9,1
|
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
|
food,normal,22,0.3,0.99,1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
26
warehouse.py
26
warehouse.py
@ -18,7 +18,7 @@ class CategoryData:
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Pack:
|
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.size = size
|
||||||
self.category = categ
|
self.category = categ
|
||||||
self.products_inside = self.set_products_inside()
|
self.products_inside = self.set_products_inside()
|
||||||
@ -31,9 +31,6 @@ class Pack:
|
|||||||
status = PackStatus.LOOSE
|
status = PackStatus.LOOSE
|
||||||
if self.lays_on_field.category.name in ['Floor', 'FridgeFloor']:
|
if self.lays_on_field.category.name in ['Floor', 'FridgeFloor']:
|
||||||
status = PackStatus.LOOSE
|
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:
|
else:
|
||||||
status = PackStatus.STORED
|
status = PackStatus.STORED
|
||||||
return status
|
return status
|
||||||
@ -53,10 +50,13 @@ class Pack:
|
|||||||
products_category = "flammable"
|
products_category = "flammable"
|
||||||
|
|
||||||
products_in_category = PRODUCT_TYPES.get(products_category, ["food"])
|
products_in_category = PRODUCT_TYPES.get(products_category, ["food"])
|
||||||
|
self.category = products_category
|
||||||
product_inside = random.choice(products_in_category)
|
product_inside = random.choice(products_in_category)
|
||||||
print(product_inside)
|
# print(product_inside)
|
||||||
return product_inside
|
return product_inside
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "Pack {} -{}, on field {}".format(self.products_inside, self.category, self.lays_on_field)
|
||||||
|
|
||||||
CATEGORY = {
|
CATEGORY = {
|
||||||
'floor': CategoryData('Floor', True, False), #lava
|
'floor': CategoryData('Floor', True, False), #lava
|
||||||
@ -78,8 +78,8 @@ class Warehouse:
|
|||||||
self.open_isolated_areas()
|
self.open_isolated_areas()
|
||||||
self.set_temperature(20, 30)
|
self.set_temperature(20, 30)
|
||||||
self.set_humidity()
|
self.set_humidity()
|
||||||
self.create_fridge(10)
|
self.create_fridge(8)
|
||||||
print([row[0].air_temperature for row in self.tiles])
|
# print([row[0].air_temperature for row in self.tiles])
|
||||||
self.packages = self.place_packages(no_of_packages)
|
self.packages = self.place_packages(no_of_packages)
|
||||||
self.tiles[1][1] = Tile('floor', 1, 1)
|
self.tiles[1][1] = Tile('floor', 1, 1)
|
||||||
def __str__(self):
|
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_x, node_y = random.randrange(1, self.width-1), random.randrange(1, self.height-1)
|
||||||
node = self.tiles[node_x][node_y]
|
node = self.tiles[node_x][node_y]
|
||||||
next_node = None
|
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)
|
q.put(node)
|
||||||
while not q.empty():
|
while not q.empty():
|
||||||
if next_node is not None:
|
if next_node is not None:
|
||||||
@ -121,7 +121,7 @@ class Warehouse:
|
|||||||
return
|
return
|
||||||
node_x = next_node.x_position
|
node_x = next_node.x_position
|
||||||
node_y = next_node.y_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):
|
def set_temperature(self, min_temperature=20, max_temperature=30):
|
||||||
for num, row in enumerate(self.tiles):
|
for num, row in enumerate(self.tiles):
|
||||||
@ -149,8 +149,6 @@ class Warehouse:
|
|||||||
start_x = 0
|
start_x = 0
|
||||||
end_x = size
|
end_x = size
|
||||||
else:
|
else:
|
||||||
# import pdb
|
|
||||||
# pdb.set_trace()
|
|
||||||
start_x = (self.width-1) - size
|
start_x = (self.width-1) - size
|
||||||
end_x = self.width - 1
|
end_x = self.width - 1
|
||||||
|
|
||||||
@ -240,10 +238,6 @@ class Warehouse:
|
|||||||
pack_x, pack_y = self._set_package_position(new_package_size)
|
pack_x, pack_y = self._set_package_position(new_package_size)
|
||||||
package_field = self.tiles[pack_x][pack_y]
|
package_field = self.tiles[pack_x][pack_y]
|
||||||
new_package = Pack(lays_on_field=package_field)
|
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
|
new_package.size = new_package_size
|
||||||
if package_field.category.name in self.storage_types:
|
if package_field.category.name in self.storage_types:
|
||||||
package_field.capacity -= new_package.size
|
package_field.capacity -= new_package.size
|
||||||
@ -253,7 +247,7 @@ class Warehouse:
|
|||||||
def _set_package_position(self, pack_size: int):
|
def _set_package_position(self, pack_size: int):
|
||||||
starting_x, starting_y = random.randrange(self.width), random.randrange(self.height)
|
starting_x, starting_y = random.randrange(self.width), random.randrange(self.height)
|
||||||
while not isinstance(self.tiles[starting_x][starting_y], Tile) \
|
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(
|
starting_x, starting_y = random.randrange(self.width), random.randrange(
|
||||||
self.height)
|
self.height)
|
||||||
return starting_x, starting_y
|
return starting_x, starting_y
|
||||||
|
Loading…
Reference in New Issue
Block a user