diff --git a/.idea/misc.xml b/.idea/misc.xml index e502517..8ef29e2 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/other.xml b/.idea/other.xml new file mode 100644 index 0000000..a708ec7 --- /dev/null +++ b/.idea/other.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/sztuczna.iml b/.idea/sztuczna.iml index 9bc6b4f..ee48f2b 100644 --- a/.idea/sztuczna.iml +++ b/.idea/sztuczna.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Package.py b/Package.py index 85974f5..b417bae 100644 --- a/Package.py +++ b/Package.py @@ -16,10 +16,11 @@ class Package: def getMarkingImage(self): file_path_type = ["resources/package/*.jpg"] images = glob2.glob(random.choice(file_path_type)) - markImage = random.choice(images) - print(markImage) - return markImage + mark_image = random.choice(images) + # print(mark_image) + return mark_image def drawPackage(self): self.window.blit(self.imageDefault, (self.x, self.y)) - pygame.display.flip() \ No newline at end of file + pygame.display.flip() + diff --git a/Program.py b/Program.py index a84b914..5bc11ef 100644 --- a/Program.py +++ b/Program.py @@ -4,26 +4,66 @@ import a_star from pygame.locals import * from Forklift import Forklift +import decision_tree HORIZONTAL = 1250 VERTICAL = 750 TILE_SIZE = 50 +c_label = random.randint(0, 3) # 0 - no label, 1 - fragile, 2 - hazardous, 3 - any other +c_size = random.randint(1, 3) # 1 - small, 2 - medium, 3 - large +c_weight = random.randint(1, 3) # -||- +c_urgent = random.randint(0, 1) # yes/no +c_weekend = random.randint(0, 1) # stays for the weekend yes/no +c_payment_method = random.randint(0, 2) # not paid, prepaid, cash on delivery +c_international = random.randint(1, 4) # domestic, european, us, everywhere else +c_delayed = random.randint(0, 1) # yes/no + +# sectors: +# 1 - regular, +# 2 - hazardous, +# 3 - international, +# 4 - overdue + +tree = decision_tree.treelearn() +decision = decision_tree.make_decision(tree, c_label, c_size, c_weight, c_urgent, c_weekend, c_payment_method, c_international, c_delayed) + +def handle_decision(): + global row, col + if decision == '1': + row = 10 + 2 * random.randint(0, 2) + col = random.randint(1, 5) + 6 * random.randint(0, 1) + print('regular') + if decision == '2': + row = 10 + 2 * random.randint(0, 2) + col = random.randint(1, 5) + 6 * random.randint(2, 3) + print('hazardous') + if decision == '3': + row = 2 * random.randint(0, 2) + col = random.randint(1, 5) + 6 * random.randint(0, 1) + print('international') + if decision == '4': + row = 2 * random.randint(0, 2) + col = random.randint(1, 5) + 6 * random.randint(2, 3) + print('overdue') + return row, col + def handle_turn(initial_state, turn_count): if turn_count % 2 == 0: commands = a_star.a_star(state=initial_state, goal=(7, 23)) else: - row = random.randint(0, 1) * 10 + 2 * random.randint(0, 2) - col = random.randint(1, 5) + 6 * random.randint(0, 3) - commands = a_star.a_star(state=initial_state, goal=(row, col)) - print('I need to go to row: ' + str(row) + ' column: ' + str(col)) + # row = random.randint(0, 1) * 10 + 2 * random.randint(0, 2) + # col = random.randint(1, 5) + 6 * random.randint(0, 3) + commands = a_star.a_star(state=initial_state, goal=(handle_decision())) + print('I need to go to row, column: ' + str(handle_decision())) return commands class Program: def __init__(self): + pygame.init() self.window = pygame.display.set_mode((HORIZONTAL, VERTICAL)) self.caption = pygame.display.set_caption('Autonomiczny wózek widłowy') @@ -33,10 +73,13 @@ class Program: running = True turn_count = 0 - initial_state = a_star.State(row=int(self.agent.y/50), column=int(self.agent.x/50), + initial_state = a_star.State(row=int(self.agent.y / 50), column=int(self.agent.x / 50), direction=self.agent.direction) while running: + + handle_decision() + commands = handle_turn(initial_state=initial_state, turn_count=turn_count) while commands: diff --git a/__pycache__/Environment.cpython-310.pyc b/__pycache__/Environment.cpython-310.pyc new file mode 100644 index 0000000..2fb7c1a Binary files /dev/null and b/__pycache__/Environment.cpython-310.pyc differ diff --git a/__pycache__/Forklift.cpython-310.pyc b/__pycache__/Forklift.cpython-310.pyc new file mode 100644 index 0000000..e633dd7 Binary files /dev/null and b/__pycache__/Forklift.cpython-310.pyc differ diff --git a/__pycache__/Grid.cpython-310.pyc b/__pycache__/Grid.cpython-310.pyc new file mode 100644 index 0000000..fbf4189 Binary files /dev/null and b/__pycache__/Grid.cpython-310.pyc differ diff --git a/__pycache__/Package.cpython-310.pyc b/__pycache__/Package.cpython-310.pyc new file mode 100644 index 0000000..7eb998d Binary files /dev/null and b/__pycache__/Package.cpython-310.pyc differ diff --git a/__pycache__/Program.cpython-310.pyc b/__pycache__/Program.cpython-310.pyc new file mode 100644 index 0000000..d5923ab Binary files /dev/null and b/__pycache__/Program.cpython-310.pyc differ diff --git a/__pycache__/Shelf.cpython-310.pyc b/__pycache__/Shelf.cpython-310.pyc new file mode 100644 index 0000000..df576e9 Binary files /dev/null and b/__pycache__/Shelf.cpython-310.pyc differ diff --git a/__pycache__/a_star.cpython-310.pyc b/__pycache__/a_star.cpython-310.pyc new file mode 100644 index 0000000..7127475 Binary files /dev/null and b/__pycache__/a_star.cpython-310.pyc differ diff --git a/__pycache__/decision_tree.cpython-310.pyc b/__pycache__/decision_tree.cpython-310.pyc new file mode 100644 index 0000000..0f7c3da Binary files /dev/null and b/__pycache__/decision_tree.cpython-310.pyc differ diff --git a/__pycache__/num_map.cpython-310.pyc b/__pycache__/num_map.cpython-310.pyc new file mode 100644 index 0000000..a329ca5 Binary files /dev/null and b/__pycache__/num_map.cpython-310.pyc differ diff --git a/decision_tree.py b/decision_tree.py new file mode 100644 index 0000000..a451691 --- /dev/null +++ b/decision_tree.py @@ -0,0 +1,43 @@ +import matplotlib.image as pltimg +import matplotlib.pyplot as plt +import os +import pandas +import pydotplus +from sklearn import tree +from sklearn.tree import DecisionTreeClassifier + + + +def treelearn(): + dataframe = pandas.read_csv('./resources/dataset.csv', delimiter=';', header=None, skiprows=1, names=["label", "size", "weight", "urgent", "weekend", "payment_method", "international", "delayed", "sector"]) + + attributes = ["label", "size", "weight", "urgent", "weekend", "payment_method", "international", "delayed"] + x = dataframe[attributes] + y = dataframe['sector'] + + #dataframe[["label", ]]=dataframe["label"].str.split(";", expand=True) + dataframe = dataframe['label'].str.split(';', n=8, expand=True) + x = dataframe.iloc[:, 0:8] + y = dataframe.iloc[:, -1:] + print(attributes) + # print(y) + decision_tree = DecisionTreeClassifier() + decision_tree = decision_tree.fit(x, y) + + # visualize and display decision tree + data = tree.export_graphviz(decision_tree, out_file=None, feature_names=attributes) + graph = pydotplus.graph_from_dot_data(data) + graph.write_png(os.path.join('resources', 'decision_tree.png')) + img = pltimg.imread(os.path.join('resources', 'decision_tree.png')) + imgplot = plt.imshow(img) + + plt.show() + + return decision_tree + + +def make_decision(tree, label, size, weight, urgent, weekend, payment_method, international, + delayed): + decision = tree.predict([[label, size, weight, urgent, weekend, payment_method, international, + delayed]]) + return decision diff --git a/resources/Zrzut ekranu 2023-03-12 213310.png b/resources/Zrzut ekranu 2023-03-12 213310.png new file mode 100644 index 0000000..28faeb4 Binary files /dev/null and b/resources/Zrzut ekranu 2023-03-12 213310.png differ diff --git a/resources/dataset.csv b/resources/dataset.csv new file mode 100644 index 0000000..9274428 --- /dev/null +++ b/resources/dataset.csv @@ -0,0 +1,202 @@ +"label;size;weight;urgent;weekend;payment_method;international;delayed;sector" +"0;1;3;0;0;0;4;0;3" +"0;1;2;1;1;0;3;0;3" +"0;2;3;0;0;1;2;0;3" +"0;3;1;0;1;1;3;0;3" +"0;2;1;0;0;2;2;0;3" +"0;1;2;0;1;1;1;0;1" +"0;1;3;1;0;2;3;1;4" +"0;2;3;1;0;1;4;1;4" +"0;2;2;1;1;0;3;0;3" +"0;2;2;1;0;0;1;0;1" +"0;3;1;0;0;0;2;1;4" +"0;3;1;0;0;1;4;1;4" +"0;3;1;0;1;2;1;0;1" +"0;3;3;1;1;1;4;1;4" +"0;2;3;1;1;0;3;0;3" +"0;1;3;0;0;0;4;1;4" +"0;2;2;0;0;2;2;0;3" +"0;1;2;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+"3;3;1;1;1;2;1;0;1" +"3;2;3;1;0;0;2;0;3" +"3;2;3;0;0;0;2;1;4" +"3;2;2;0;1;1;3;0;3" +"3;1;2;1;1;1;4;1;4" +"3;1;1;0;0;2;2;0;3" +"3;2;1;1;0;1;2;1;4" +"3;2;3;0;0;0;1;0;1" +"3;1;3;0;0;0;1;1;4" +"3;1;2;1;1;1;4;0;3" +"3;2;2;1;1;2;4;1;4" +"3;2;1;0;1;1;2;0;3" +"3;3;1;0;1;1;2;1;4" +"3;3;3;0;1;2;1;0;1" +"3;2;3;0;0;1;1;1;4" +"3;3;2;1;0;2;4;1;4" +"3;1;2;0;1;1;2;0;3" +"3;1;1;1;0;0;2;0;3" +"3;2;1;0;1;2;2;0;3" +"3;1;3;1;0;1;1;0;1" +"3;3;3;0;1;0;1;0;1" +"3;2;2;0;0;2;3;0;3" +"3;2;2;1;1;2;3;0;3" +"3;1;1;0;0;1;2;0;3" +"3;3;1;1;0;1;2;1;4" +"3;2;3;1;1;2;1;1;4" +"3;2;3;1;0;2;4;1;4" +"3;1;3;0;1;0;2;1;4" +"3;3;2;0;0;0;3;1;4" +"3;2;2;1;0;0;4;1;4" diff --git a/resources/decision_tree.png b/resources/decision_tree.png new file mode 100644 index 0000000..bd23429 Binary files /dev/null and b/resources/decision_tree.png differ