Compare commits

..

No commits in common. "3651768e3eb21b217d6806248adf7b0fdea10d44" and "dd25c7a145b940e008f6860b2f56575e3c68954f" have entirely different histories.

21 changed files with 716 additions and 417 deletions

8
.gitignore vendored
View File

@ -57,6 +57,8 @@ docs/_build/
Pipfile
Pipfile.lock
# output
/out
decision_tree
decision_tree.pdf
Source.gv.pdf
Source.gv
decision_tree.txt

View File

@ -41,14 +41,8 @@
---
- [x] **Drzewa decyzyjne: wymagania dot. trzeciego przyrostu**
- [x] Należy wykorzystać algorytm ID3 (tj. schemat indukcyjnego uczenia drzewa decyzyjnego oraz procedurę wyboru atrybutu o największym przyroście informacji) lub któreś z jego uogólnień.
- [x] Należy przygotować zbiór uczący złożony z co najmniej 200 przykładów.
- [ ] **Drzewa decyzyjne: wymagania dot. trzeciego przyrostu**
- [ ] Należy wykorzystać algorytm ID3 (tj. schemat indukcyjnego uczenia drzewa decyzyjnego oraz procedurę wyboru atrybutu o największym przyroście informacji) lub któreś z jego uogólnień.
- [ ] Należy przygotować zbiór uczący złożony z co najmniej 200 przykładów.
- [x] Decyzja stanowiąca cel uczenia powinna zostać opisana przynajmniej ośmioma atrybutami.
- [x] Powinna pojawić się opcja podglądu wyuczonego drzewa (np. w logach lub w pliku z graficzną reprezentacją drzewa).
---
- [ ] **Sieci neuronowe: wymagania dot. czwartego przyrostu**
- [ ] Należy przygotować zbiór uczący zawierający co najmniej 1000 przykładów dla każdej klasy.
- [ ] Agent powinien wykorzystywać wyuczoną sieć w procesie podejmowania decyzji.
- [ ] Powinna pojawić się opcja podglądu wyuczonego drzewa (np. w logach lub w pliku z graficzną reprezentacją drzewa).

38
TreeConcept.py Normal file
View File

@ -0,0 +1,38 @@
from sklearn import tree
import pandas as pd #for manipulating the csv data
import numpy as np
import graphviz
import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz/bin/'
#importing the dataset from the disk
train_data_m=np.genfromtxt("dataset/converted_dataset.csv", delimiter=",",skip_header=1);
# Separate the attributes and labels
X_train = [data[:-1] for data in train_data_m]
y_train = [data[-1] for data in train_data_m]
# Create the decision tree classifier using the ID3 algorithm
clf = tree.DecisionTreeClassifier(criterion='entropy')
#clf = tree.DecisionTreeClassifier(criterion='gini')
# Train the decision tree on the training data
clf.fit(X_train, y_train)
# Visualize the trained decision tree
tree_text = tree.export_text(clf,feature_names=['Battery Charge', 'Fullness', 'Ready orders', 'Waiting tables','Availability', 'Cleanliness', 'Error'])
with open('decision_tree.txt', 'w') as f:
f.write(tree_text) # Save the visualization as a text file
dot_data = tree.export_graphviz(clf, out_file=None, feature_names=['Battery Charge', 'Fullness', 'Ready orders', 'Waiting tables','Availability', 'Cleanliness', 'Error'], class_names=['NO', 'YES'], filled=True,rounded=True)
graph = graphviz.Source(dot_data)
graph.render("decision_tree") # Save the visualization as a PDF file
# Test the decision tree with a new example
#Battery Charge,Fullness,Ready orders,Waiting tables,Availability,Cleanliness,Error
new_example = [2, 0, 1, 1, 1 ,2, 0]
predicted_label = clf.predict([new_example])
if predicted_label[0]>0:
result="YES"
else:
result="NO"
print("Predicted Label:", result)

View File

@ -11,16 +11,17 @@ SCREEN_SIZE = [800, 800]
SQUARE_SIZE = 40
waiter = Waiter([0, 0], 0, SQUARE_SIZE, SCREEN_SIZE)
kitchen = Kitchen([0, 0], 0, SQUARE_SIZE, SCREEN_SIZE)
objects = []
objects = [
Kitchen([0, 0], 0, SQUARE_SIZE, SCREEN_SIZE)
]
for i in range(150):
pos = [0, 0]
while any([o.compare_pos(pos) for o in objects]) or pos == [0, 0]:
pos = [random.randint(1, SCREEN_SIZE[0]/SQUARE_SIZE - 1),
random.randint(1, SCREEN_SIZE[0]/SQUARE_SIZE - 1)]
while any([o.compare_pos(pos) for o in objects]):
pos = [random.randint(1, SCREEN_SIZE[0]/SQUARE_SIZE),
random.randint(1, SCREEN_SIZE[0]/SQUARE_SIZE)]
if (random.randint(0, 1)):
objects.append(Block(pos, 0, SQUARE_SIZE, SCREEN_SIZE))
@ -29,7 +30,7 @@ for i in range(150):
user = UserController(waiter)
state = StateController(waiter)
engine = Engine(SCREEN_SIZE, SQUARE_SIZE, kitchen, user, state)
engine = Engine(SCREEN_SIZE, SQUARE_SIZE, user, state)
for o in objects:
engine.subscribe(o)

201
dataset/Dataset.csv Normal file
View File

@ -0,0 +1,201 @@
Battery Charge,Fullness,Ready orders,Waiting tables,Availability,Cleanliness,Error,To go
high,full,none,none,available,low,yes,no
low,full,none,none,unavailable,medium,yes,no
high,full,none,none,unavailable,medium,no,no
medium,empty,none,none,unavailable,low,no,no
high,full,none,none,available,medium,no,no
low,full,none,available,unavailable,medium,yes,no
medium,empty,none,available,unavailable,high,yes,no
medium,full,none,available,available,low,yes,no
medium,full,available,none,unavailable,low,yes,no
high,empty,none,none,unavailable,medium,yes,no
medium,empty,none,available,unavailable,medium,yes,no
low,empty,available,none,available,high,no,no
high,full,available,none,available,low,yes,no
medium,full,none,available,available,low,no,no
medium,full,none,available,available,medium,no,yes
empty,full,none,none,unavailable,high,yes,no
low,full,none,none,unavailable,medium,no,no
low,full,available,none,unavailable,low,no,no
medium,empty,none,available,unavailable,medium,no,no
low,empty,available,available,unavailable,medium,no,no
medium,empty,available,available,unavailable,medium,yes,no
low,empty,none,none,unavailable,high,no,no
medium,full,available,available,unavailable,medium,yes,no
high,empty,available,none,available,medium,no,yes
empty,empty,available,available,unavailable,low,yes,no
high,empty,none,none,unavailable,high,yes,no
medium,empty,available,available,available,medium,no,yes
medium,full,available,available,available,low,no,no
empty,full,none,available,available,high,no,no
empty,empty,none,none,unavailable,low,no,no
medium,full,none,none,unavailable,medium,no,no
medium,empty,available,available,unavailable,high,yes,no
high,full,available,none,available,medium,yes,no
medium,empty,none,available,unavailable,low,yes,no
low,empty,none,none,available,low,no,no
high,full,available,available,available,low,yes,no
high,full,available,available,unavailable,high,yes,no
low,full,available,available,unavailable,high,yes,no
low,full,none,none,unavailable,low,yes,no
medium,full,none,none,unavailable,medium,yes,no
high,full,none,available,available,medium,yes,no
low,empty,none,none,unavailable,low,no,no
high,empty,available,none,unavailable,low,yes,no
medium,full,none,available,available,high,no,yes
low,empty,available,available,available,high,yes,no
low,full,available,none,unavailable,high,yes,no
medium,full,available,none,unavailable,low,no,no
medium,full,available,available,unavailable,high,no,no
medium,full,none,available,unavailable,low,yes,no
medium,empty,available,none,unavailable,low,yes,no
medium,empty,none,none,available,high,no,no
empty,full,none,none,available,low,no,no
low,full,available,available,available,medium,yes,no
low,full,available,none,unavailable,high,no,no
high,full,available,none,available,medium,no,no
low,full,none,available,available,medium,no,no
empty,empty,none,available,available,high,no,no
low,full,none,available,unavailable,low,no,no
high,full,none,none,unavailable,high,no,no
medium,full,none,none,available,high,yes,no
low,empty,none,available,available,medium,no,no
empty,empty,none,available,unavailable,low,no,no
empty,full,available,none,available,low,yes,no
empty,empty,available,available,available,medium,no,no
empty,empty,available,none,unavailable,medium,no,no
empty,empty,none,none,unavailable,high,no,no
medium,empty,available,none,unavailable,high,no,no
empty,empty,available,none,available,medium,yes,no
empty,empty,none,none,unavailable,high,yes,no
high,full,available,available,unavailable,low,no,no
high,empty,available,available,available,high,yes,no
high,empty,available,none,available,low,no,no
low,empty,none,available,unavailable,medium,no,no
medium,full,none,available,unavailable,low,no,no
medium,empty,none,available,available,high,yes,no
medium,empty,available,available,available,high,no,yes
high,empty,none,available,unavailable,low,yes,no
low,full,available,available,available,high,no,no
medium,empty,none,available,available,high,no,no
medium,empty,available,none,available,high,no,yes
empty,full,available,available,unavailable,high,no,no
low,empty,none,available,available,low,no,no
high,full,none,available,available,low,yes,no
high,empty,none,none,available,medium,yes,no
empty,empty,available,none,unavailable,low,no,no
high,full,none,available,unavailable,low,yes,no
empty,full,none,available,unavailable,high,no,no
empty,full,available,none,available,low,no,no
medium,full,none,none,available,high,no,no
medium,full,available,available,unavailable,low,yes,no
empty,full,available,available,unavailable,low,yes,no
low,empty,none,none,unavailable,medium,no,no
low,full,none,none,unavailable,low,no,no
low,full,available,available,unavailable,low,yes,no
low,empty,none,available,available,low,yes,no
empty,full,available,none,unavailable,high,no,no
low,full,available,none,available,high,no,no
high,full,available,available,available,medium,yes,no
empty,full,none,available,available,medium,yes,no
low,full,none,none,available,medium,no,no
empty,full,available,available,available,low,no,no
medium,full,available,none,unavailable,medium,yes,no
empty,empty,none,none,available,medium,no,no
high,full,none,available,unavailable,low,no,no
low,empty,available,available,available,high,no,no
low,empty,none,available,available,high,yes,no
high,full,none,available,available,medium,no,yes
empty,full,available,none,available,medium,yes,no
high,full,none,none,available,low,no,no
low,empty,available,available,unavailable,high,no,no
low,full,available,none,available,medium,yes,no
high,empty,none,none,unavailable,low,no,no
low,full,none,none,unavailable,high,yes,no
high,empty,none,available,available,low,yes,no
empty,full,available,available,unavailable,low,no,no
low,empty,available,available,unavailable,low,no,no
low,full,available,none,unavailable,low,yes,no
empty,empty,available,available,unavailable,high,no,no
medium,full,available,none,available,medium,yes,no
high,full,available,none,available,high,no,no
low,full,none,available,available,medium,yes,no
low,empty,none,available,unavailable,medium,yes,no
high,full,available,available,unavailable,medium,yes,no
high,full,none,none,unavailable,medium,yes,no
low,full,available,available,available,low,yes,no
low,full,available,available,unavailable,high,no,no
empty,full,none,none,available,medium,no,no
empty,empty,available,none,available,low,yes,no
high,full,available,none,unavailable,high,no,no
high,full,none,available,unavailable,high,no,no
low,empty,available,available,unavailable,medium,yes,no
high,empty,available,available,available,low,yes,no
empty,full,none,none,unavailable,low,no,no
high,full,none,available,unavailable,medium,yes,no
high,empty,available,none,unavailable,medium,no,no
empty,empty,available,none,available,high,yes,no
high,empty,available,none,unavailable,medium,yes,no
empty,empty,none,none,unavailable,medium,no,no
high,empty,none,available,available,high,no,no
medium,empty,none,none,unavailable,low,yes,no
medium,full,available,none,unavailable,high,no,no
high,full,none,none,unavailable,low,no,no
high,empty,none,none,unavailable,medium,no,no
medium,full,available,none,available,low,no,no
high,empty,none,none,available,high,yes,no
empty,full,available,available,available,high,no,no
medium,full,available,available,unavailable,low,no,no
empty,full,available,none,available,medium,no,no
empty,full,available,available,unavailable,medium,yes,no
empty,empty,available,none,available,high,no,no
low,empty,none,none,available,high,yes,no
empty,full,none,available,unavailable,medium,yes,no
medium,full,none,available,unavailable,medium,yes,no
medium,full,available,none,available,low,yes,no
medium,full,available,none,unavailable,high,yes,no
medium,full,available,available,available,high,no,yes
medium,full,none,none,available,low,no,no
high,full,none,available,available,high,no,yes
low,empty,available,available,unavailable,low,yes,no
low,full,none,available,unavailable,high,yes,no
medium,full,available,available,available,high,yes,no
high,full,available,available,available,low,no,no
medium,full,none,none,unavailable,high,yes,no
medium,full,none,available,unavailable,high,no,no
high,empty,none,available,unavailable,high,yes,no
empty,empty,none,available,available,medium,no,no
empty,empty,available,none,unavailable,high,no,no
high,empty,available,available,unavailable,high,yes,no
medium,empty,available,available,unavailable,low,yes,no
medium,full,none,none,unavailable,low,no,no
high,empty,none,none,available,low,no,no
high,full,available,none,unavailable,medium,no,no
high,full,available,none,unavailable,low,yes,no
empty,empty,available,available,available,low,yes,no
high,empty,none,none,unavailable,low,yes,no
medium,empty,none,none,available,low,no,no
low,full,none,available,unavailable,medium,no,no
low,full,none,available,available,high,yes,no
high,full,none,available,unavailable,high,yes,no
medium,full,none,available,available,medium,yes,no
empty,empty,none,available,unavailable,high,yes,no
medium,empty,available,none,unavailable,medium,yes,no
empty,empty,none,available,unavailable,low,yes,no
high,empty,none,available,unavailable,medium,no,no
medium,empty,available,none,available,low,yes,no
medium,full,available,available,available,medium,no,yes
high,full,available,none,unavailable,medium,yes,no
high,full,available,available,unavailable,medium,no,no
low,full,available,none,available,medium,no,no
medium,empty,available,none,unavailable,high,yes,no
medium,empty,available,none,available,medium,yes,no
high,empty,none,none,available,high,no,no
empty,full,available,none,unavailable,high,yes,no
low,empty,available,none,unavailable,low,yes,no
empty,full,available,available,available,low,yes,no
medium,empty,available,available,unavailable,medium,no,no
medium,empty,none,none,unavailable,high,no,no
medium,full,available,available,unavailable,medium,no,no
empty,full,available,available,available,medium,no,no
low,empty,available,none,available,low,no,no
1 Battery Charge Fullness Ready orders Waiting tables Availability Cleanliness Error To go
2 high full none none available low yes no
3 low full none none unavailable medium yes no
4 high full none none unavailable medium no no
5 medium empty none none unavailable low no no
6 high full none none available medium no no
7 low full none available unavailable medium yes no
8 medium empty none available unavailable high yes no
9 medium full none available available low yes no
10 medium full available none unavailable low yes no
11 high empty none none unavailable medium yes no
12 medium empty none available unavailable medium yes no
13 low empty available none available high no no
14 high full available none available low yes no
15 medium full none available available low no no
16 medium full none available available medium no yes
17 empty full none none unavailable high yes no
18 low full none none unavailable medium no no
19 low full available none unavailable low no no
20 medium empty none available unavailable medium no no
21 low empty available available unavailable medium no no
22 medium empty available available unavailable medium yes no
23 low empty none none unavailable high no no
24 medium full available available unavailable medium yes no
25 high empty available none available medium no yes
26 empty empty available available unavailable low yes no
27 high empty none none unavailable high yes no
28 medium empty available available available medium no yes
29 medium full available available available low no no
30 empty full none available available high no no
31 empty empty none none unavailable low no no
32 medium full none none unavailable medium no no
33 medium empty available available unavailable high yes no
34 high full available none available medium yes no
35 medium empty none available unavailable low yes no
36 low empty none none available low no no
37 high full available available available low yes no
38 high full available available unavailable high yes no
39 low full available available unavailable high yes no
40 low full none none unavailable low yes no
41 medium full none none unavailable medium yes no
42 high full none available available medium yes no
43 low empty none none unavailable low no no
44 high empty available none unavailable low yes no
45 medium full none available available high no yes
46 low empty available available available high yes no
47 low full available none unavailable high yes no
48 medium full available none unavailable low no no
49 medium full available available unavailable high no no
50 medium full none available unavailable low yes no
51 medium empty available none unavailable low yes no
52 medium empty none none available high no no
53 empty full none none available low no no
54 low full available available available medium yes no
55 low full available none unavailable high no no
56 high full available none available medium no no
57 low full none available available medium no no
58 empty empty none available available high no no
59 low full none available unavailable low no no
60 high full none none unavailable high no no
61 medium full none none available high yes no
62 low empty none available available medium no no
63 empty empty none available unavailable low no no
64 empty full available none available low yes no
65 empty empty available available available medium no no
66 empty empty available none unavailable medium no no
67 empty empty none none unavailable high no no
68 medium empty available none unavailable high no no
69 empty empty available none available medium yes no
70 empty empty none none unavailable high yes no
71 high full available available unavailable low no no
72 high empty available available available high yes no
73 high empty available none available low no no
74 low empty none available unavailable medium no no
75 medium full none available unavailable low no no
76 medium empty none available available high yes no
77 medium empty available available available high no yes
78 high empty none available unavailable low yes no
79 low full available available available high no no
80 medium empty none available available high no no
81 medium empty available none available high no yes
82 empty full available available unavailable high no no
83 low empty none available available low no no
84 high full none available available low yes no
85 high empty none none available medium yes no
86 empty empty available none unavailable low no no
87 high full none available unavailable low yes no
88 empty full none available unavailable high no no
89 empty full available none available low no no
90 medium full none none available high no no
91 medium full available available unavailable low yes no
92 empty full available available unavailable low yes no
93 low empty none none unavailable medium no no
94 low full none none unavailable low no no
95 low full available available unavailable low yes no
96 low empty none available available low yes no
97 empty full available none unavailable high no no
98 low full available none available high no no
99 high full available available available medium yes no
100 empty full none available available medium yes no
101 low full none none available medium no no
102 empty full available available available low no no
103 medium full available none unavailable medium yes no
104 empty empty none none available medium no no
105 high full none available unavailable low no no
106 low empty available available available high no no
107 low empty none available available high yes no
108 high full none available available medium no yes
109 empty full available none available medium yes no
110 high full none none available low no no
111 low empty available available unavailable high no no
112 low full available none available medium yes no
113 high empty none none unavailable low no no
114 low full none none unavailable high yes no
115 high empty none available available low yes no
116 empty full available available unavailable low no no
117 low empty available available unavailable low no no
118 low full available none unavailable low yes no
119 empty empty available available unavailable high no no
120 medium full available none available medium yes no
121 high full available none available high no no
122 low full none available available medium yes no
123 low empty none available unavailable medium yes no
124 high full available available unavailable medium yes no
125 high full none none unavailable medium yes no
126 low full available available available low yes no
127 low full available available unavailable high no no
128 empty full none none available medium no no
129 empty empty available none available low yes no
130 high full available none unavailable high no no
131 high full none available unavailable high no no
132 low empty available available unavailable medium yes no
133 high empty available available available low yes no
134 empty full none none unavailable low no no
135 high full none available unavailable medium yes no
136 high empty available none unavailable medium no no
137 empty empty available none available high yes no
138 high empty available none unavailable medium yes no
139 empty empty none none unavailable medium no no
140 high empty none available available high no no
141 medium empty none none unavailable low yes no
142 medium full available none unavailable high no no
143 high full none none unavailable low no no
144 high empty none none unavailable medium no no
145 medium full available none available low no no
146 high empty none none available high yes no
147 empty full available available available high no no
148 medium full available available unavailable low no no
149 empty full available none available medium no no
150 empty full available available unavailable medium yes no
151 empty empty available none available high no no
152 low empty none none available high yes no
153 empty full none available unavailable medium yes no
154 medium full none available unavailable medium yes no
155 medium full available none available low yes no
156 medium full available none unavailable high yes no
157 medium full available available available high no yes
158 medium full none none available low no no
159 high full none available available high no yes
160 low empty available available unavailable low yes no
161 low full none available unavailable high yes no
162 medium full available available available high yes no
163 high full available available available low no no
164 medium full none none unavailable high yes no
165 medium full none available unavailable high no no
166 high empty none available unavailable high yes no
167 empty empty none available available medium no no
168 empty empty available none unavailable high no no
169 high empty available available unavailable high yes no
170 medium empty available available unavailable low yes no
171 medium full none none unavailable low no no
172 high empty none none available low no no
173 high full available none unavailable medium no no
174 high full available none unavailable low yes no
175 empty empty available available available low yes no
176 high empty none none unavailable low yes no
177 medium empty none none available low no no
178 low full none available unavailable medium no no
179 low full none available available high yes no
180 high full none available unavailable high yes no
181 medium full none available available medium yes no
182 empty empty none available unavailable high yes no
183 medium empty available none unavailable medium yes no
184 empty empty none available unavailable low yes no
185 high empty none available unavailable medium no no
186 medium empty available none available low yes no
187 medium full available available available medium no yes
188 high full available none unavailable medium yes no
189 high full available available unavailable medium no no
190 low full available none available medium no no
191 medium empty available none unavailable high yes no
192 medium empty available none available medium yes no
193 high empty none none available high no no
194 empty full available none unavailable high yes no
195 low empty available none unavailable low yes no
196 empty full available available available low yes no
197 medium empty available available unavailable medium no no
198 medium empty none none unavailable high no no
199 medium full available available unavailable medium no no
200 empty full available available available medium no no
201 low empty available none available low no no

View File

@ -0,0 +1,200 @@
3,1,0,0,1,0,1,0
1,1,0,0,0,1,1,0
3,1,0,0,0,1,0,0
2,0,0,0,0,0,0,0
3,1,0,0,1,1,0,0
1,1,0,1,0,1,1,0
2,0,0,1,0,2,1,0
2,1,0,1,1,0,1,0
2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 0
115 0 1 1 1 0 0 0 0
116 1 0 1 1 0 0 0 0
117 1 1 1 0 0 0 1 0
118 0 0 1 1 0 2 0 0
119 2 1 1 0 1 1 1 0
120 3 1 1 0 1 2 0 0
121 1 1 0 1 1 1 1 0
122 1 0 0 1 0 1 1 0
123 3 1 1 1 0 1 1 0
124 3 1 0 0 0 1 1 0
125 1 1 1 1 1 0 1 0
126 1 1 1 1 0 2 0 0
127 0 1 0 0 1 1 0 0
128 0 0 1 0 1 0 1 0
129 3 1 1 0 0 2 0 0
130 3 1 0 1 0 2 0 0
131 1 0 1 1 0 1 1 0
132 3 0 1 1 1 0 1 0
133 0 1 0 0 0 0 0 0
134 3 1 0 1 0 1 1 0
135 3 0 1 0 0 1 0 0
136 0 0 1 0 1 2 1 0
137 3 0 1 0 0 1 1 0
138 0 0 0 0 0 1 0 0
139 3 0 0 1 1 2 0 0
140 2 0 0 0 0 0 1 0
141 2 1 1 0 0 2 0 0
142 3 1 0 0 0 0 0 0
143 3 0 0 0 0 1 0 0
144 2 1 1 0 1 0 0 0
145 3 0 0 0 1 2 1 0
146 0 1 1 1 1 2 0 0
147 2 1 1 1 0 0 0 0
148 0 1 1 0 1 1 0 0
149 0 1 1 1 0 1 1 0
150 0 0 1 0 1 2 0 0
151 1 0 0 0 1 2 1 0
152 0 1 0 1 0 1 1 0
153 2 1 0 1 0 1 1 0
154 2 1 1 0 1 0 1 0
155 2 1 1 0 0 2 1 0
156 2 1 1 1 1 2 0 1
157 2 1 0 0 1 0 0 0
158 3 1 0 1 1 2 0 1
159 1 0 1 1 0 0 1 0
160 1 1 0 1 0 2 1 0
161 2 1 1 1 1 2 1 0
162 3 1 1 1 1 0 0 0
163 2 1 0 0 0 2 1 0
164 2 1 0 1 0 2 0 0
165 3 0 0 1 0 2 1 0
166 0 0 0 1 1 1 0 0
167 0 0 1 0 0 2 0 0
168 3 0 1 1 0 2 1 0
169 2 0 1 1 0 0 1 0
170 2 1 0 0 0 0 0 0
171 3 0 0 0 1 0 0 0
172 3 1 1 0 0 1 0 0
173 3 1 1 0 0 0 1 0
174 0 0 1 1 1 0 1 0
175 3 0 0 0 0 0 1 0
176 2 0 0 0 1 0 0 0
177 1 1 0 1 0 1 0 0
178 1 1 0 1 1 2 1 0
179 3 1 0 1 0 2 1 0
180 2 1 0 1 1 1 1 0
181 0 0 0 1 0 2 1 0
182 2 0 1 0 0 1 1 0
183 0 0 0 1 0 0 1 0
184 3 0 0 1 0 1 0 0
185 2 0 1 0 1 0 1 0
186 2 1 1 1 1 1 0 1
187 3 1 1 0 0 1 1 0
188 3 1 1 1 0 1 0 0
189 1 1 1 0 1 1 0 0
190 2 0 1 0 0 2 1 0
191 2 0 1 0 1 1 1 0
192 3 0 0 0 1 2 0 0
193 0 1 1 0 0 2 1 0
194 1 0 1 0 0 0 1 0
195 0 1 1 1 1 0 1 0
196 2 0 1 1 0 1 0 0
197 2 0 0 0 0 2 0 0
198 2 1 1 1 0 1 0 0
199 0 1 1 1 1 1 0 0
200 1 0 1 0 1 0 0 0

View File

@ -1,17 +1,15 @@
import csv
def convertDataset():
def convert_dataset(input_file, output_file):
attributes = {
1: ["low", "high"],
2: ["far", "close"],
3: ['bad', 'good', 'undefined'],
4: ["no", "yes"],
5: ["no", "yes"],
6: ["no", "yes"],
7: ["empty", "new order", "waiting for dish", "have a dish"],
8: ["no", "yes"],
9: ["high priority", "low priority", "return to kitchen"]
1: ["empty", "low", "medium", "high"],
2: ["empty", "full"],
3: ["none", "available"],
4: ["none", "available"],
5: ["unavailable", "available"],
6: ["low", "medium", "high"],
7: ["no", "yes"],
8: ["no", "yes"]
}
# Create a mapping dictionary for attribute values
@ -22,11 +20,10 @@ def convertDataset():
converted_dataset = []
# Read the input CSV file
with open("out/rawDataset.csv", "r") as csvfile:
with open(input_file, "r") as csvfile:
reader = csv.reader(csvfile)
header = next(reader) # Skip the header row
converted_dataset.append(header)
# Convert the data rows
for row in reader:
@ -43,9 +40,15 @@ def convertDataset():
converted_dataset.append(converted_row)
# Write the converted dataset to a new CSV file
with open("out/dataset.csv", "w", newline="") as csvfile:
with open(output_file, "w", newline="") as csvfile:
writer = csv.writer(csvfile)
# Write the header row
#writer.writerow(header)
# Write the converted data rows
for row in converted_dataset:
writer.writerow(row)
# Example usage:
convert_dataset("dataset/Dataset.csv", "dataset/converted_dataset.csv")

View File

@ -0,0 +1,57 @@
import random
import csv
attributes = {
1: ["empty", "low", "medium", "high"],
2: ["empty", "full"],
3: ["none", "available"],
4: ["none", "available"],
5: ["unavailable", "available"],
6: ["low", "medium", "high"],
7: ["no", "yes"],
8: ["no", "yes"]
}
dataset = []
while len(dataset) < 200:
data = {}
# Generate random values for attributes 1-7
for attr in range(1, 8):
data[attr] = random.choice(attributes[attr])
# Apply the rules to determine the value of attribute 8
if data[1] in ["empty", "low"]:
data[8] = "no"
elif data[2] == "full" and data[4] == "none":
data[8] = "no"
elif data[2] == "empty" and data[3] == "none":
data[8] = "no"
elif data[3] == "none" and data[4] == "none":
data[8] = "no"
elif data[5] == "unavailable":
data[8] = "no"
elif data[6] == "low":
data[8] = "no"
elif data[7] == "yes":
data[8] = "no"
else:
data[8] = "yes"
# Check if the generated data already exists in the dataset
if data not in dataset:
dataset.append(data)
# Print the generated dataset
for data in dataset:
print(data)
with open("dataset/Dataset.csv", "w", newline="") as csvfile:
writer = csv.writer(csvfile)
# Write the header row
writer.writerow(["Battery Charge", "Fullness", "Ready orders", "Waiting tables","Availability", "Cleanliness", "Error", "To go"])
# Write the data rows
for data in dataset:
row = [data[attr] for attr in range(1, 9)]
writer.writerow(row)

View File

@ -1,5 +1,2 @@
-i https://pypi.org/simple
pygame==2.3.0
pandas
scikit-learn
graphviz

View File

@ -1,24 +1,18 @@
import time
import pygame
from .obj.Goal import Goal
from .obj.Object import Object
from .obj.Waiter import Waiter
from .obj.Kitchen import Kitchen
from .UserController import UserController
from .StateController import StateController
from .decisionTree.TreeConcept import TreeEngine
from queue import PriorityQueue
class Engine:
def __init__(self, screen_size, square_size, kitchen: Kitchen, user: UserController, state: StateController):
def __init__(self, screen_size, square_size, user: UserController, state: StateController):
pygame.display.set_caption('Waiter Agent')
self.action_clock = 0
self.tree = TreeEngine()
self.kitchen: Kitchen = kitchen
self.user: Waiter = user
self.state: StateController = state
self.screen_size: list[int] = screen_size
@ -65,7 +59,6 @@ class Engine:
if self.goals:
self.state.graphsearch(self)
self.user.handler(self)
self.predict()
else:
# went path
@ -82,13 +75,8 @@ class Engine:
# waiter interaction
for o in self.objects:
if self.user.obj.chechNeighbor(o):
o.updateState(self.action_clock)
if o.compare_pos(self.user.obj.position):
o.action(self.user.obj, self.action_clock)
if self.kitchen.compare_pos(self.user.obj.position):
self.kitchen.action(self.user.obj, self.action_clock)
o.action(self.user.obj)
time.sleep(0.5)
@ -105,7 +93,6 @@ class Engine:
for o in self.objects:
o.blit(self.screen)
self.kitchen.blit(self.screen)
self.user.obj.blit(self.screen)
for f in self.state.fringe.queue:
@ -114,72 +101,7 @@ class Engine:
for s in self.state.path:
s.blit(self.screen)
if self.goals:
self.goals[-1].blit(self.screen)
pygame.display.flip()
def appendGoalPosition(self, position):
self.goals.append(Goal(position, self.square_size, self.screen_size))
def predict(self):
goal_queue = PriorityQueue()
for o in self.objects:
condition = o.agent_role in [
"table",
"order",
"wait",
"done"
]
if not condition or o.compare_pos(self.user.obj.position):
continue
medium_dist = (self.screen_size[0] // self.square_size) // 2
dataset = [
# battery
self.user.obj.battery_status(),
# high | low |
# distance between kitchen and object
0 if o.distance_to(self.kitchen.position) > medium_dist else 1,
# far | close |
# mood 
o.get_mood(self.action_clock),
# undefined | good | bad |
# basket is empty
1 if self.user.obj.basket_is_empty() else 0,
# yes | no |
# dish is ready
1 if o.dish_is_ready(self.action_clock) else 0,
# yes | no |
# dish in basket
1 if self.user.obj.dish_in_basket(o) else 0,
# yes | no |
# status
o.get_state_number(),
# empty | new order | waiting for dish | have a dish |
# is actual
1 if o.isActual() else 0,
# yes | no |
]
p = self.tree.make_predict(dataset)
goal_queue.put((p, o.position))
if goal_queue.queue:
priority, goal = goal_queue.queue[0]
if priority == 2:
self.appendGoalPosition(self.kitchen.position)
else:
self.appendGoalPosition(goal)
self.goals.append(position)

View File

@ -15,10 +15,9 @@ class StateController:
self.explored.clear()
self.fringe = PriorityQueue()
def build_path(self, goal_state, engine):
def build_path(self, goal_state):
total_cost = goal_state.cost
self.path.append(goal_state)
engine.goals.pop()
while self.path[-1].parent.agent_role not in ["blank", "waiter"]:
self.path.append(self.path[-1].parent)
total_cost += self.path[-1].cost
@ -29,7 +28,7 @@ class StateController:
def graphsearch(self, engine): # A*
print("Search path")
self.goal = list(engine.goals[-1].position)
self.goal = list(engine.goals.pop())
self.reset()
@ -37,10 +36,13 @@ class StateController:
self.fringe.put(start)
while self.fringe.queue and not self.path:
while self.fringe and not self.path:
self.explored.append(self.fringe.get())
if self.goal_test(engine):
return
if self.explored[-1].position == self.goal:
goal_state = self.explored[-1]
self.reset()
return self.build_path(goal_state)
self.succ(self.explored[-1].front(), engine)
self.succ(self.explored[-1].left(), engine)
@ -49,10 +51,6 @@ class StateController:
engine.redraw()
self.reset()
for o in engine.objects:
o.compare_pos(engine.goals[-1].position)
o.agent_role = "block"
engine.goals.pop()
print("Not found")
@ -92,19 +90,3 @@ class StateController:
if state.cost_so_far < fringe.cost_so_far:
fringe.replace(state)
def goal_test(self, engine) -> bool:
if self.explored[-1].position == self.goal:
self.__is_goal__(self.explored[-1], engine)
return True
for fringe in self.fringe.queue:
if fringe.position == self.goal:
self.__is_goal__(fringe, engine)
return True
return False
def __is_goal__(self, goal_state, engine):
self.reset()
self.build_path(goal_state, engine)

View File

@ -9,3 +9,11 @@ class UserController:
for event in pygame.event.get():
if event.type == pygame.QUIT:
engine.quit()
elif event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
pos = [pos[0] // engine.square_size,
pos[1] // engine.square_size]
# for o in engine.objects:
# if o.compare_pos(pos):
# o.set_order(engine.action_clock)
engine.appendGoalPosition(pos)

View File

@ -1,70 +0,0 @@
import time
from sklearn import tree
import numpy as np
import graphviz
from src.decisionTree.datasetGenerator import generateRawDataset
from src.decisionTree.datasetConverter import convertDataset
class TreeEngine():
def __init__(self):
generateRawDataset()
convertDataset()
# importing the dataset from the disk
train_data_m = np.genfromtxt(
"out/dataset.csv", delimiter=",", skip_header=1)
# Separate the attributes and labels
self.X_train = [data[:-1] for data in train_data_m]
self.y_train = [data[-1] for data in train_data_m]
# Create the decision tree classifier using the ID3 algorithm
self.clf = tree.DecisionTreeClassifier(
criterion='entropy', splitter="best")
# clf = tree.DecisionTreeClassifier(criterion='gini')
# Train the decision tree on the training data
self.clf.fit(self.X_train, self.y_train)
self.exportText()
self.exportPdf()
def exportText(self):
# Visualize the trained decision tree
tree_text = tree.export_text(self.clf, feature_names=[
"Battery level",
"Distance between kitchen and table",
"Customers mood",
"Basket is empty",
"Dish is ready",
"Dish in basket",
"Table status",
"Is actual",
])
with open('out/decision_tree.txt', 'w') as f:
f.write(tree_text) # Save the visualization as a text file
def exportPdf(self):
dot_data = tree.export_graphviz(self.clf, out_file=None, feature_names=[
"Battery level",
"Distance between kitchen and table",
"Customers mood",
"Basket is empty",
"Dish is ready",
"Dish in basket",
"Table status",
"Is actual",
], class_names=[
'High priority',
'Low priority',
'Return to kitchen',
], filled=True, rounded=True)
graph = graphviz.Source(dot_data)
# Save the visualization as a PDF file
graph.render("out/decision_tree")
def make_predict(self, dataset):
return self.clf.predict([dataset])

View File

@ -1,111 +0,0 @@
import csv
from pathlib import Path
def generateRawDataset():
battery_values = ['high', 'low']
distance_values = ['far', 'close']
mood_values = ['undefined', 'good', 'bad']
status_values = ['empty', 'new order', 'waiting for dish', 'have a dish']
other = ['no', 'yes']
training_data = []
training_data.append([
"Battery level",
"Distance between kitchen and table",
"Customers mood",
"Basket is empty",
"Dish is ready",
"Dish in basket",
"Table status",
"Is actual",
"Priority"
])
for battery in battery_values:
for distance in distance_values:
for mood in mood_values:
for basket in other:
for ready in other:
for dish in other:
for status in status_values:
for actual in other:
dataset = buildDataset(
battery,
distance,
mood,
basket,
ready,
dish,
status,
actual
)
training_data.append(dataset)
Path("out/").mkdir(parents=True, exist_ok=True)
with open('out/rawDataset.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(training_data)
def buildDataset(b, d, m, e, r, i, s, a) -> list:
dataset = [
b, # battery
d, # distance
m, # mood
e, # basket is empty
r, # ready
i, # dish in basket
s, # status
a, # actual
]
dataset.append(getPriority(dataset))
return dataset
def getPriority(dataset) -> str:
PRIORITY = {
'high': 'high priority',
'low': 'low priority',
'kitchen': 'return to kitchen'
}
BATTERY_LEVEL = dataset[0]
DISTANCE_TO_OBJECT = dataset[1]
MOOD = dataset[2]
BASKET_IS_EMPTY = dataset[3]
DISH_IS_READY = dataset[4]
DISH_IN_BASKET = dataset[5]
STATUS_OF_TABLE = dataset[6]
IS_ACTUAL = dataset[7]
def mood_and_distance() -> str:
if MOOD == "undefined":
return PRIORITY['kitchen']
elif MOOD == "good":
return PRIORITY['low']
elif DISTANCE_TO_OBJECT == "far":
return PRIORITY['high']
else:
return PRIORITY['low']
if BATTERY_LEVEL == "low":
return PRIORITY['kitchen']
elif IS_ACTUAL == "no":
return PRIORITY['high']
elif STATUS_OF_TABLE == "empty" or STATUS_OF_TABLE == "have a dish":
return PRIORITY['kitchen']
elif STATUS_OF_TABLE == "new order":
return mood_and_distance()
elif BASKET_IS_EMPTY == "yes":
return PRIORITY['kitchen']
elif DISH_IS_READY == "no":
return PRIORITY['kitchen']
elif DISH_IN_BASKET == "no":
return PRIORITY['kitchen']
else:
return mood_and_distance()

View File

@ -0,0 +1,33 @@
import csv
import random
battery_values = ['high', 'medium', 'low']
distance_values = ['far', 'medium', 'close']
mood_values = ['good', 'medium', 'bad']
other = ['yes', 'no']
training_data = []
for _ in range(200):
battery = random.choice(battery_values)
distance = random.choice(distance_values)
mood = random.choice(mood_values)
memory = random.randint(0,4)
dishes_held = random.randint(0,4)
"""empty_basket = random.choice(other)
if empty_basket == 'yes':
dish_in_basket = 'no'
else:
dish_in_basket = random.choice(other)
dish_in_basket = random.choice(other)"""
waiting_for_order = random.choice(other)
waiting_for_dish = random.choice(other)
example = [battery, distance, mood, memory, dishes_held, waiting_for_order, waiting_for_dish]
training_data.append(example)
with open('data.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(training_data)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

View File

@ -1,9 +0,0 @@
from src.obj.Object import Object
class Goal(Object):
def __init__(self, position, square_size, screen_size):
super().__init__("goal", position, 0, square_size, screen_size)
def collide_test(self, waiter: Object) -> bool:
return waiter.position == self.position

View File

@ -5,6 +5,6 @@ class Kitchen(Object):
def __init__(self, position, orientation, square_size, screen_size):
super().__init__("kitchen", position, orientation, square_size, screen_size)
def action(self, waiter, current_time):
waiter.combine_orders(current_time)
def action(self, waiter):
waiter.combine_orders()
waiter.recharge()

View File

@ -57,6 +57,3 @@ class Object:
def action(self, obj):
pass
def updateState(self, current_time):
pass

View File

@ -4,59 +4,29 @@ from src.obj.Object import Object
class Table(Object):
def __init__(self, position, orientation, square_size, screen_size):
super().__init__("table", position, orientation, square_size, screen_size)
self.waiting_time = 0
self.cooking_time = 0
self.is_actual = False
super().__init__("order", position, orientation, square_size, screen_size)
self.order_time = 0
self.customers = 0
# roles = ["table", "order", "wait", "done"]
def isActual(self):
return self.is_actual
def updateState(self, current_time):
if self.is_actual:
return
self.is_actual = True
# here must be neural network choise
new_role = random.choice(["table", "order", "wait", "done"])
self.change_role(new_role, current_time)
if self.agent_role == "table":
return
elif self.agent_role == "wait":
self.cooking_time = random.randint(0, 300)
def dish_is_ready(self, current_time):
return current_time - self.waiting_time > self.cooking_time
def get_state_number(self) -> int:
roles = {
"table": 0,
"order": 1,
"wait": 2,
"done": 3
}
return roles[self.agent_role]
def change_role(self, new_role, current_time):
self.waiting_time = current_time
return super().change_role(new_role)
def reset(self, current_time):
self.is_actual = False
self.change_role("table", current_time)
def reset(self):
self.change_role("table")
self.order_time = 0
self.customers = 0
def set_order(self, current_time):
if self.agent_role == "table":
self.change_role("order", current_time)
self.change_role("order")
self.customers = random.randint(1, 6)
self.order_time = current_time
def set_wait(self, current_time):
def set_wait(self):
if self.agent_role == "order":
self.change_role("wait", current_time)
self.change_role("wait")
def set_done(self, current_time):
def set_done(self):
if self.agent_role == "wait":
self.change_role("done", current_time)
self.change_role("done")
def is_order(self):
return self.agent_role == "order"
@ -67,18 +37,26 @@ class Table(Object):
def is_done(self):
return self.agent_role == "done"
def waiting_for_dish(self):
return self.agent_role in ["wait", "done"]
def get_customers_count(self) -> int:
return self.customers
def get_mood(self, current_time) -> int: # перапісаць
def get_mood(self, current_time) -> str:
if self.agent_role == "table":
return 2 # undefined
return None
diff = current_time - self.waiting_time
return 0 if diff >= 300 else 1 # 0 - bad; 1 - good
diff = current_time - self.order_time
if diff < 200:
return "good"
elif diff < 400:
return "medium"
else:
return "bad"
def action(self, waiter, current_time):
def action(self, waiter):
if self.is_order():
waiter.collect_order(self, current_time)
waiter.collect_order(self)
elif self.is_done():
waiter.deliver_dish(self, current_time)
waiter.deliver_dish(self)

View File

@ -18,28 +18,106 @@ class Waiter(Object):
self.orientation = copy.copy(state.orientation)
self.basket = copy.copy(state.basket)
self.battery -= state.cost
# self.calcTree()
return state
def dish_in_basket(self, table) -> bool:
return table in self.basket
'''
def calcTree(self):
from sklearn import tree
import pandas as pd # for manipulating the csv data
import numpy as np
import os
# importing the dataset from the disk
train_data_m = np.genfromtxt(
"dataset/converted_dataset.csv", delimiter=",", skip_header=1)
X_train = [data[:-1] for data in train_data_m]
y_train = [data[-1] for data in train_data_m]
# Create the decision tree classifier using the ID3 algorithm
clf = tree.DecisionTreeClassifier(criterion='entropy')
# Train the decision tree on the training data
clf.fit(X_train, y_train)
# Visualize the trained decision tree
tree_text = tree.export_text(clf, feature_names=[
'Battery Charge', 'Fullness', 'Ready orders', 'Waiting tables', 'Availability', 'Cleanliness', 'Error'])
with open('decision_tree.txt', 'w') as f:
f.write(tree_text) # Save the visualization as a text file
# Test the decision tree with a new example
# Battery Charge,Fullness,Ready orders,Waiting tables,Availability,Cleanliness,Error
new_example = [self.battery, 0, self.orderReadiness,
self.waitingTables, self.availability, self.cleanliness, self.error]
predicted_label = clf.predict([new_example])
if predicted_label[0] > 0:
result = "YES"
else:
result = "NO"
print("Predicted Label:", result)
def calcTreePDF(self):
from sklearn import tree
import pandas as pd # for manipulating the csv data
import numpy as np
import graphviz
import os
os.environ["PATH"] += os.pathsep + \
'C:/Program Files (x86)/Graphviz/bin/'
# importing the dataset from the disk
train_data_m = np.genfromtxt(
"dataset/converted_dataset.csv", delimiter=",", skip_header=1)
X_train = [data[:-1] for data in train_data_m]
y_train = [data[-1] for data in train_data_m]
# Create the decision tree classifier using the ID3 algorithm
clf = tree.DecisionTreeClassifier(criterion='entropy')
# Train the decision tree on the training data
clf.fit(X_train, y_train)
# Visualize the trained decision tree
tree_text = tree.export_text(clf, feature_names=[
'Battery Charge', 'Fullness', 'Ready orders', 'Waiting tables', 'Availability', 'Cleanliness', 'Error'])
with open('decision_tree.txt', 'w') as f:
f.write(tree_text) # Save the visualization as a text file
dot_data = tree.export_graphviz(clf, out_file=None, feature_names=[
'Battery Charge', 'Fullness', 'Ready orders', 'Waiting tables', 'Availability', 'Cleanliness', 'Error'], class_names=['NO', 'YES'], filled=True, rounded=True)
graph = graphviz.Source(dot_data)
graph.render("decision_tree") # Save the visualization as a PDF file
# Test the decision tree with a new example
# Battery Charge,Fullness,Ready orders,Waiting tables,Availability,Cleanliness,Error
new_example = [self.battery, 0, self.orderReadiness,
self.waitingTables, self.availability, self.cleanliness, self.error]
predicted_label = clf.predict([new_example])
if predicted_label[0] > 0:
result = "YES"
else:
result = "NO"
print("Predicted Label:", result)
'''
def basket_is_full(self) -> bool:
return self.basket_size == 0
def basket_is_empty(self) -> bool:
return self.basket_size == 4
def combine_orders(self, current_time):
def combine_orders(self):
while not self.basket_is_full() and not self.memory_is_empty():
dish = self.memory.pop()
dish.set_done(current_time)
dish.set_done()
self.basket.append(dish)
self.basket_size -= 1
self.memory_size += 1
def deliver_dish(self, table, current_time):
def deliver_dish(self, table):
if table in self.basket:
table.reset(current_time)
table.reset()
self.basket.remove(table)
self.basket_size += 1
@ -52,16 +130,21 @@ class Waiter(Object):
def memory_is_full(self) -> bool:
return self.memory_size == 0
def collect_order(self, table, current_time):
def collect_order(self, table):
if self.memory_is_full():
return
if table.agent_role == "order":
table.set_wait(current_time)
table.set_wait()
self.memory.append(table)
self.memory_size -= 1
def battery_status(self) -> int:
return 1 if self.battery >= 100 else 0
def battary_status(self) -> str:
if self.battery >= 200:
return "hight"
elif self.battery >= 100:
return "medium"
else:
return "low"
def recharge(self):
self.battery = 300
@ -77,10 +160,3 @@ class Waiter(Object):
self.position[0] += self.orientation - 2 # x (-1 or +1)
else: # y (0 or 2)
self.position[1] += self.orientation - 1 # y (-1 or +1)
def chechNeighbor(self, n, r=1):
cond_x = abs(self.position[0] - n.position[0]) <= r
cond_y = abs(self.position[1] - n.position[1]) <= r
return cond_x and cond_y