Poprawienie dobierania jedzenia przez agenta i spowolnienie głodu

This commit is contained in:
Franciszka Jedraszak 2024-05-12 23:38:23 +02:00
parent d86809f940
commit ad6fd4bc1b
8 changed files with 14 additions and 13 deletions

View File

@ -16,7 +16,7 @@ class Bat(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 30*5
minutes_passed = delta.total_seconds() / 35*5
self._starttime = checktime
if const.IS_NIGHT and self._feed < 10:

View File

@ -17,7 +17,7 @@ class Giraffe(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 30*5
minutes_passed = delta.total_seconds() / 35*5
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 10:

View File

@ -16,7 +16,7 @@ class Owl(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 25*5
minutes_passed = delta.total_seconds() / 30*5
self._starttime = checktime
if const.IS_NIGHT and self._feed < 10:

View File

@ -17,7 +17,7 @@ class Parrot(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 20*5
minutes_passed = delta.total_seconds() / 25*5
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 10:

View File

@ -17,7 +17,7 @@ class Penguin(Animal):
def getting_hungry(self, const):
checktime = datetime.now()
delta = checktime - self._starttime
minutes_passed = delta.total_seconds() / 15*5
minutes_passed = delta.total_seconds() / 20*5
self._starttime = checktime
if not const.IS_NIGHT and self._feed < 10:

View File

@ -103,7 +103,7 @@ def take_food(self):
house_x = 3
house_y = 1
if self.x == house_x and self.y == house_y:
if self._dryfood == 0 or self._wetfood == 0:
if self._dryfood < 1 or self._wetfood < 1:
self._dryfood = 50
self._wetfood = 50
print("Agent took food and current food level is", self._dryfood, self._wetfood)

View File

@ -6,25 +6,26 @@ import matplotlib.pyplot as plt
headers = ['adult','active_time','ill','season','guests','hunger','wet_food','dry_food']
# Wczytanie danych
data = pd.read_csv('dane.csv', header=0)
X = data[['adult','active_time','ill','season','guests','hunger','wet_food','dry_food']]
X = data[headers]
Y = data['decision']
X = pd.get_dummies(data=X, columns=['season'])
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, train_size=0.8)
clf = DecisionTreeClassifier(random_state=0, min_samples_leaf = 4, min_samples_split=2)
clf = clf.fit(X,Y)
#skuteczność drzewa
'''
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, train_size=0.8)
clf = clf.fit(X_train, Y_train)
Y_pred = clf.predict(X_test)
accuracy = accuracy_score(Y_test, Y_pred)
print("Dokładność:", accuracy)
'''
#zapisanie drzewa do pliku
plt.figure(figsize=(50,30))
plot_tree(clf, filled=True, feature_names=X.columns, class_names=['nie karmi', 'karmi mokrą karmą', 'karmi suchą karmą']) # filled=True koloruje węzły
plt.savefig('tree.png')
plot_tree(clf, filled=True, feature_names=X.columns, class_names=['nie karmi', 'karmi mokrą karmą', 'karmi suchą karmą'])
# Nowe dane
# dane do decyzji
def feed_decision(adult,active_time,ill,season,guests,hunger,dry_food,wet_food):
X_new = pd.DataFrame({
'adult': [adult],

BIN
tree.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 669 KiB

After

Width:  |  Height:  |  Size: 655 KiB