poprawienie karmienia

This commit is contained in:
Franciszka Jedraszak 2024-05-12 21:07:31 +02:00
parent 8fcb368258
commit d1501c1ddc
5 changed files with 24 additions and 13 deletions

View File

@ -3,7 +3,7 @@ import random
from constants import Constants
from state_space_search import is_border, is_obstacle
from night import draw_night
from decision_tree import add_data
from decision_tree import feed_decision
from constants import Constants
class Agent:
@ -76,15 +76,15 @@ def feed_animal(self, animals, goal,const):
else:
activity_time = False
guests = random.randint(1, 15)
feed_decision = add_data(animal.adult, activity_time, animal.ill, const.season, guests, animal._feed, self._dryfood, self._wetfood)
if feed_decision != 1:
if feed_decision == 2:
decision = feed_decision(animal.adult, activity_time, animal.ill, const.season, guests, animal._feed, self._dryfood, self._wetfood)
if decision != [1]:
if decision == [2]:
if animal.getting_hungry(const=Constants()) < self._wetfood :
self._wetfood -= animal._feed
animal._feed = 0
else:
animal._feed -= self._wetfood
self._food = 0
self._wetfood = 0
print(animal.name, "fed with wet food")
else:
if animal.getting_hungry(const=Constants()) < self._dryfood :

View File

@ -92,6 +92,7 @@ True,False,True,spring,14,5.12387,44.44585,8.35502,3
True,True,False,autumn,10,4.90335,43.27857,27.22901,1
True,False,False,winter,11,5.89082,28.91495,15.58095,1
True,False,True,autumn,3,7.39589,21.53402,44.50694,3
True,False,True,autumn,3,7.39589,21.53402,0.00000,2
True,False,False,summer,12,5.68671,49.18777,22.53807,3
False,False,False,winter,0,0.86765,41.28704,33.77284,1
False,False,True,summer,10,5.97643,36.23669,48.32615,2
@ -128,11 +129,13 @@ True,True,False,summer,11,4.65313,3.44791,3.96313,3
True,False,True,summer,2,2.56716,10.85536,49.88738,1
False,False,True,autumn,4,8.19265,5.43942,48.74041,3
False,True,False,autumn,5,5.6574,9.75738,25.96888,3
False,True,False,autumn,5,5.6574,9.75738,0.00000,2
False,True,False,winter,14,4.87066,33.40134,18.98246,2
True,True,True,winter,6,8.2623,37.47298,33.76759,2
True,True,True,spring,10,2.20409,13.6178,5.80078,2
True,False,True,autumn,7,9.06057,37.8724,23.62209,2
False,False,True,autumn,3,6.69861,37.07336,16.87187,2
False,False,True,autumn,3,6.69861,0.00000,16.87187,3
True,False,True,autumn,13,4.96475,46.87852,3.1412,1
True,False,True,autumn,9,2.65212,19.06994,37.33364,1
True,True,False,summer,15,3.47148,35.84529,0.00000,1
@ -284,6 +287,11 @@ True,False,True,autumn,7,3.96302,39.84093,47.0172,1
True,False,False,summer,1,0.65085,20.20581,14.96995,1
True,False,False,winter,2,9.24331,26.34543,30.5147,2
True,False,False,summer,3,2.86309,15.56342,1.04324,1
True,True,True,autumn,8,5.71809,24.41045,48.78273,2
True,True,True,autumn,8,5.71809,24.41045,48.78273,2
True,True,True,winter,8,5.71809,0.99999,48.78273,3
True,True,True,winter,8,5.71809,1.98675,48.79993,3
True,True,False,winter,8,7.71809,1.02345,38.78273,3
True,False,False,summer,1,4.03947,33.84073,6.48891,1
True,False,False,winter,4,2.46471,24.07929,17.77792,1
False,False,False,winter,9,3.66415,23.68306,24.43865,1
@ -298,4 +306,8 @@ False,False,False,autumn,1,2.5607,26.85209,47.10784,1
True,True,True,winter,14,1.56638,18.02703,7.05011,1
False,False,False,winter,13,3.86632,28.9884,20.1928,1
True,False,False,summer,13,6.37654,34.3833,34.53892,3
True,True,False,summer,5,8.10422,7.6617,23.41017,3
True,False,False,summer,13,6.37654,34.3833,34.53892,3
True,False,False,spring,11,8.35634,0.00000,34.53892,3
True,False,True,summer,13,9.37654,34.3833,0.00000,2
True,False,False,winter,13,7.77754,34.3833,0.00000,2
True,True,True,summer,5,8.10422,7.6617,23.41017,3
1 adult active_time ill season guests hunger wet_food dry_food decision
92 True True False autumn 10 4.90335 43.27857 27.22901 1
93 True False False winter 11 5.89082 28.91495 15.58095 1
94 True False True autumn 3 7.39589 21.53402 44.50694 3
95 True False True autumn 3 7.39589 21.53402 0.00000 2
96 True False False summer 12 5.68671 49.18777 22.53807 3
97 False False False winter 0 0.86765 41.28704 33.77284 1
98 False False True summer 10 5.97643 36.23669 48.32615 2
129 True False True summer 2 2.56716 10.85536 49.88738 1
130 False False True autumn 4 8.19265 5.43942 48.74041 3
131 False True False autumn 5 5.6574 9.75738 25.96888 3
132 False True False autumn 5 5.6574 9.75738 0.00000 2
133 False True False winter 14 4.87066 33.40134 18.98246 2
134 True True True winter 6 8.2623 37.47298 33.76759 2
135 True True True spring 10 2.20409 13.6178 5.80078 2
136 True False True autumn 7 9.06057 37.8724 23.62209 2
137 False False True autumn 3 6.69861 37.07336 16.87187 2
138 False False True autumn 3 6.69861 0.00000 16.87187 3
139 True False True autumn 13 4.96475 46.87852 3.1412 1
140 True False True autumn 9 2.65212 19.06994 37.33364 1
141 True True False summer 15 3.47148 35.84529 0.00000 1
287 True False False summer 1 0.65085 20.20581 14.96995 1
288 True False False winter 2 9.24331 26.34543 30.5147 2
289 True False False summer 3 2.86309 15.56342 1.04324 1
290 True True True autumn 8 5.71809 24.41045 48.78273 2
291 True True True autumn 8 5.71809 24.41045 48.78273 2
292 True True True winter 8 5.71809 0.99999 48.78273 3
293 True True True winter 8 5.71809 1.98675 48.79993 3
294 True True False winter 8 7.71809 1.02345 38.78273 3
295 True False False summer 1 4.03947 33.84073 6.48891 1
296 True False False winter 4 2.46471 24.07929 17.77792 1
297 False False False winter 9 3.66415 23.68306 24.43865 1
306 True True True winter 14 1.56638 18.02703 7.05011 1
307 False False False winter 13 3.86632 28.9884 20.1928 1
308 True False False summer 13 6.37654 34.3833 34.53892 3
309 True True False False summer 5 13 8.10422 6.37654 7.6617 34.3833 23.41017 34.53892 3
310 True False False spring 11 8.35634 0.00000 34.53892 3
311 True False True summer 13 9.37654 34.3833 0.00000 2
312 True False False winter 13 7.77754 34.3833 0.00000 2
313 True True True summer 5 8.10422 7.6617 23.41017 3

View File

@ -25,7 +25,7 @@ plot_tree(clf, filled=True, feature_names=X.columns, class_names=['nie karmi', '
plt.savefig('tree.png')
# Nowe dane
def add_data(adult,active_time,ill,season,guests,hunger,wet_food,dry_food):
def feed_decision(adult,active_time,ill,season,guests,hunger,dry_food,wet_food):
X_new = pd.DataFrame({
'adult': [adult],
'active_time': [active_time],
@ -36,13 +36,13 @@ def add_data(adult,active_time,ill,season,guests,hunger,wet_food,dry_food):
'wet_food': [wet_food],
'dry_food': [dry_food]
})
X_new_encoded = pd.get_dummies(X_new)
missing_columns = set(X.columns) - set(X_new.columns)
X_new = pd.get_dummies(X_new)
missing_columns = set(X.columns) - set(X_new)
for col in missing_columns:
X_new_encoded[col] = 0
X_new_encoded = X_new_encoded.reindex(columns=X.columns, fill_value=0)
X_new[col] = False
X_new = X_new.reindex(columns=X.columns, fill_value=0)
print("Atrybuty zwierzęcia:", adult,active_time,ill,season,guests,hunger,wet_food,dry_food)
return (clf.predict(X_new_encoded))
return (clf.predict(X_new))

View File

@ -3,7 +3,6 @@ import pygame
import sys
sys.path.append('./Animals')
from decision_tree import add_data
from animals import create_animals, draw_Animals
from agent import Agent
from enclosure import create_enclosures, draw_enclosures, draw_gates

BIN
tree.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 764 KiB

After

Width:  |  Height:  |  Size: 662 KiB