poprawione drzewo, wydluzone ttl, funkcja service
This commit is contained in:
parent
af19bec73e
commit
95dcef88cf
@ -2,7 +2,7 @@ from Plant import Plant
|
||||
|
||||
class Cucumber(Plant):
|
||||
is_alive = True
|
||||
ttl = 2000
|
||||
ttl = 10000
|
||||
hydration = 40
|
||||
soil_level = 40
|
||||
dehydration_ratio = 0.8
|
||||
|
@ -2,7 +2,7 @@ from Plant import Plant
|
||||
|
||||
class Tomato(Plant):
|
||||
is_alive = True
|
||||
ttl = 2000
|
||||
ttl = 12000
|
||||
hydration = 41
|
||||
soil_level = 41
|
||||
dehydration_ratio = 0.7
|
||||
|
18
Tree.py
18
Tree.py
@ -2,6 +2,7 @@ from sklearn import tree
|
||||
import collections
|
||||
import subprocess
|
||||
|
||||
class TreeClass:
|
||||
#file = open("probne.pl", 'r').read()
|
||||
#text = ""
|
||||
#for line in file:
|
||||
@ -22,6 +23,10 @@ import subprocess
|
||||
#features.update({"key5": "text"})
|
||||
|
||||
#symbol, is_alive, ttl, hydration, soil_level, ready
|
||||
|
||||
#print(com)
|
||||
|
||||
def make_tree(self, plant, pl_stats):
|
||||
features = [["Tomato", True, 60, 90, 95],
|
||||
["Tomato", True, 60, 84, 88],
|
||||
["Tomato", True, 50, 78, 77],
|
||||
@ -61,20 +66,19 @@ features = [["Tomato", True, 60, 90, 95],
|
||||
|
||||
labels = [0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 2, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 2, 3, 3, 3, 3, 3, 3]
|
||||
|
||||
#print(com)
|
||||
|
||||
#utwórz drzewo decyzyjne
|
||||
tree = tree.DecisionTreeClassifier()
|
||||
t = tree.DecisionTreeClassifier()
|
||||
|
||||
#znajdź wzór na podstawie danych
|
||||
tree = tree.fit(features, labels)#jakieś cechy w środku i decyzje jakie ma podjąć
|
||||
t = tree.fit(features, labels)#jakieś cechy w środku i decyzje jakie ma podjąć
|
||||
|
||||
#użyj modelu aby dopasować(podjąć decyzję)
|
||||
p = tree.predict([["Cucumber", True, 38, 26, 51]])
|
||||
#p = tree.predict([["Cucumber", True, 38, 26, 51]])
|
||||
p = t.predict([pl_stats[0], pl_stats[1]], pl_stats[2], pl_stats[3], pl_stats[4])
|
||||
|
||||
if p == 0:
|
||||
print("Ready to cut")
|
||||
Harvest()
|
||||
t.Harvest()
|
||||
elif p == 1:
|
||||
plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
|
||||
elif p == 2:
|
||||
@ -85,7 +89,7 @@ elif p == 3:
|
||||
|
||||
#wyświetlamy dopasowaną wartość
|
||||
print(p)
|
||||
|
||||
pass
|
||||
"""
|
||||
is_life = bool
|
||||
type = "POop"
|
||||
|
50
tractor.py
50
tractor.py
@ -4,8 +4,11 @@ import time
|
||||
from Graph import Graph
|
||||
from Cucumber import Cucumber
|
||||
from Tomato import Tomato
|
||||
from sklearn import tree
|
||||
from Tree import TreeClass
|
||||
|
||||
class Tractor:
|
||||
|
||||
class Tractor(TreeClass):
|
||||
sleep_time = 0.1
|
||||
graph = Graph()
|
||||
moved_flag = False
|
||||
@ -21,6 +24,11 @@ class Tractor:
|
||||
(x2, y2) = b
|
||||
return abs(x1 - x2) + abs(y1 - y2)
|
||||
|
||||
# def look_at_plats(field, location):
|
||||
|
||||
|
||||
|
||||
|
||||
async def rotate(self, direction):
|
||||
reader, writer = await asyncio.open_connection('127.0.0.1', 8888)
|
||||
writer.write(("rotate " + direction + "\n").encode())
|
||||
@ -28,12 +36,20 @@ class Tractor:
|
||||
time.sleep(self.sleep_time)
|
||||
writer.close()
|
||||
|
||||
async def look_at_plants(self, direction):
|
||||
async def look_at_plants(self, location):
|
||||
reader, writer = await asyncio.open_connection('127.0.0.1', 8888)
|
||||
writer.write(("rotate " + direction + "\n").encode())
|
||||
# writer.write(("rotate " + direction + "\n").encode())
|
||||
await reader.readline()
|
||||
time.sleep(self.sleep_time)
|
||||
wsp = [
|
||||
(location[0] + 1, location[1]),
|
||||
(location[0] - 1, location[1]),
|
||||
(location[0], location[1] - 1),
|
||||
(location[0], location[1] + 1)
|
||||
]
|
||||
writer.close()
|
||||
return wsp
|
||||
|
||||
|
||||
|
||||
async def try_move(self):
|
||||
@ -189,27 +205,7 @@ class Tractor:
|
||||
|
||||
await self.move_tractor(start_position)
|
||||
|
||||
def hydration(self, plant):
|
||||
if type(plant) == Tomato:
|
||||
if plant.hydration < 50:
|
||||
plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
|
||||
|
||||
elif type(plant) == Cucumber:
|
||||
if plant.hydration < 40:
|
||||
plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
|
||||
|
||||
def fertilization(self, plant):
|
||||
if type(plant) == Tomato:
|
||||
if plant.soil_level < 50:
|
||||
plant.increase_soillevel(plant.max_soil_lvl - plant.soil_level)
|
||||
|
||||
elif type(plant) == Cucumber:
|
||||
if plant.soil_level < 40:
|
||||
plant.increase_soillevel(plant.max_soil_lvl - plant.soil_level)
|
||||
|
||||
async def service(self):
|
||||
"tutaj trzeba zapytac env z jakimi roslinami sie styka traktor i je obsłuzyc"
|
||||
pass
|
||||
|
||||
async def get_stats(self, location):
|
||||
reader, writer = await asyncio.open_connection('127.0.0.1', 8888)
|
||||
@ -221,10 +217,18 @@ class Tractor:
|
||||
return {"ttl": int(parsed_data[0]), "is_alive": int(parsed_data[1]), "hydration": int(parsed_data[2]), "soil_level": int(parsed_data[3]),
|
||||
"ready": int(parsed_data[4])}
|
||||
|
||||
async def service(self):
|
||||
plant_location = self.look_at_plants(self.current_location)
|
||||
plant_stats = self.get_stats(plant_location)
|
||||
TreeClass.make_tree(self, plant_location, plant_stats)
|
||||
|
||||
"tutaj trzeba zapytac env z jakimi roslinami sie styka traktor i je obsłuzyc"
|
||||
|
||||
pass
|
||||
if __name__ == "__main__":
|
||||
start = (0,0)
|
||||
goal = (10,6)
|
||||
tractor = Tractor((0,0), 'N')
|
||||
# asyncio.run(tractor.move_tractor(start, goal))
|
||||
asyncio.run(tractor.run())
|
||||
asyncio.service(tractor.service())
|
||||
|
Loading…
Reference in New Issue
Block a user