decision tree
This commit is contained in:
parent
335e333eed
commit
1f7b9c780c
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (SI projekt)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (wozek-projekt)" project-jdk-type="Python SDK" />
|
||||
<component name="PythonCompatibilityInspectionAdvertiser">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PySciProjectComponent">
|
||||
<option name="PY_SCI_VIEW_SUGGESTED" value="true" />
|
||||
</component>
|
||||
</project>
|
|
@ -4,7 +4,7 @@
|
|||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (SI projekt)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (wozek-projekt)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -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()
|
||||
pygame.display.flip()
|
||||
|
||||
|
|
53
Program.py
53
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:
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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
|
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
|
@ -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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;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"
|
|
Binary file not shown.
After Width: | Height: | Size: 60 KiB |
Loading…
Reference in New Issue