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):
|
class Cucumber(Plant):
|
||||||
is_alive = True
|
is_alive = True
|
||||||
ttl = 2000
|
ttl = 10000
|
||||||
hydration = 40
|
hydration = 40
|
||||||
soil_level = 40
|
soil_level = 40
|
||||||
dehydration_ratio = 0.8
|
dehydration_ratio = 0.8
|
||||||
|
@ -2,7 +2,7 @@ from Plant import Plant
|
|||||||
|
|
||||||
class Tomato(Plant):
|
class Tomato(Plant):
|
||||||
is_alive = True
|
is_alive = True
|
||||||
ttl = 2000
|
ttl = 12000
|
||||||
hydration = 41
|
hydration = 41
|
||||||
soil_level = 41
|
soil_level = 41
|
||||||
dehydration_ratio = 0.7
|
dehydration_ratio = 0.7
|
||||||
|
110
Tree.py
110
Tree.py
@ -2,6 +2,7 @@ from sklearn import tree
|
|||||||
import collections
|
import collections
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
class TreeClass:
|
||||||
#file = open("probne.pl", 'r').read()
|
#file = open("probne.pl", 'r').read()
|
||||||
#text = ""
|
#text = ""
|
||||||
#for line in file:
|
#for line in file:
|
||||||
@ -22,70 +23,73 @@ import subprocess
|
|||||||
#features.update({"key5": "text"})
|
#features.update({"key5": "text"})
|
||||||
|
|
||||||
#symbol, is_alive, ttl, hydration, soil_level, ready
|
#symbol, is_alive, ttl, hydration, soil_level, ready
|
||||||
features = [["Tomato", True, 60, 90, 95],
|
|
||||||
["Tomato", True, 60, 84, 88],
|
|
||||||
["Tomato", True, 50, 78, 77],
|
|
||||||
["Tomato", True, 45, 63, 68],
|
|
||||||
["Tomato", True, 37, 54, 59],
|
|
||||||
["Tomato", True, 20, 31, 62],
|
|
||||||
["Tomato", True, 18, 75, 39],
|
|
||||||
["Tomato", True, 19, 24, 74],
|
|
||||||
["Tomato", True, 24, 69, 25],
|
|
||||||
["Tomato", True, 15, 45, 85],
|
|
||||||
["Tomato", True, 23, 85, 48],
|
|
||||||
["Tomato", True, 26, 41, 45],
|
|
||||||
["Tomato", True, 21, 35, 32],
|
|
||||||
["Tomato", True, 49, 24, 28],
|
|
||||||
["Tomato", True, 64, 15, 14],
|
|
||||||
["Tomato", True, 84, 4, 8],
|
|
||||||
|
|
||||||
["Cucumber", True, 55, 89, 84],
|
|
||||||
["Cucumber", True, 76, 91, 95],
|
|
||||||
["Cucumber", True, 45, 72, 71],
|
|
||||||
["Cucumber", True, 37, 64, 68],
|
|
||||||
["Cucumber", True, 26, 54, 59],
|
|
||||||
["Cucumber", True, 58, 42, 46],
|
|
||||||
["Cucumber", True, 20, 31, 62],
|
|
||||||
["Cucumber", True, 18, 75, 39],
|
|
||||||
["Cucumber", True, 19, 24, 74],
|
|
||||||
["Cucumber", True, 24, 69, 25],
|
|
||||||
["Cucumber", True, 15, 12, 85],
|
|
||||||
["Cucumber", True, 23, 85, 18],
|
|
||||||
["Cucumber", True, 34, 38, 36],
|
|
||||||
["Cucumber", True, 41, 24, 22],
|
|
||||||
["Cucumber", True, 34, 38, 36],
|
|
||||||
["Cucumber", True, 74, 26, 23],
|
|
||||||
["Cucumber", True, 84, 14, 19],
|
|
||||||
["Cucumber", True, 95, 7, 4]
|
|
||||||
]
|
|
||||||
|
|
||||||
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)
|
#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],
|
||||||
|
["Tomato", True, 45, 63, 68],
|
||||||
|
["Tomato", True, 37, 54, 59],
|
||||||
|
["Tomato", True, 20, 31, 62],
|
||||||
|
["Tomato", True, 18, 75, 39],
|
||||||
|
["Tomato", True, 19, 24, 74],
|
||||||
|
["Tomato", True, 24, 69, 25],
|
||||||
|
["Tomato", True, 15, 45, 85],
|
||||||
|
["Tomato", True, 23, 85, 48],
|
||||||
|
["Tomato", True, 26, 41, 45],
|
||||||
|
["Tomato", True, 21, 35, 32],
|
||||||
|
["Tomato", True, 49, 24, 28],
|
||||||
|
["Tomato", True, 64, 15, 14],
|
||||||
|
["Tomato", True, 84, 4, 8],
|
||||||
|
|
||||||
|
["Cucumber", True, 55, 89, 84],
|
||||||
|
["Cucumber", True, 76, 91, 95],
|
||||||
|
["Cucumber", True, 45, 72, 71],
|
||||||
|
["Cucumber", True, 37, 64, 68],
|
||||||
|
["Cucumber", True, 26, 54, 59],
|
||||||
|
["Cucumber", True, 58, 42, 46],
|
||||||
|
["Cucumber", True, 20, 31, 62],
|
||||||
|
["Cucumber", True, 18, 75, 39],
|
||||||
|
["Cucumber", True, 19, 24, 74],
|
||||||
|
["Cucumber", True, 24, 69, 25],
|
||||||
|
["Cucumber", True, 15, 12, 85],
|
||||||
|
["Cucumber", True, 23, 85, 18],
|
||||||
|
["Cucumber", True, 34, 38, 36],
|
||||||
|
["Cucumber", True, 41, 24, 22],
|
||||||
|
["Cucumber", True, 34, 38, 36],
|
||||||
|
["Cucumber", True, 74, 26, 23],
|
||||||
|
["Cucumber", True, 84, 14, 19],
|
||||||
|
["Cucumber", True, 95, 7, 4]
|
||||||
|
]
|
||||||
|
|
||||||
|
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]
|
||||||
|
|
||||||
#utwórz drzewo decyzyjne
|
#utwórz drzewo decyzyjne
|
||||||
tree = tree.DecisionTreeClassifier()
|
t = tree.DecisionTreeClassifier()
|
||||||
|
|
||||||
#znajdź wzór na podstawie danych
|
#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ę)
|
#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:
|
if p == 0:
|
||||||
print("Ready to cut")
|
print("Ready to cut")
|
||||||
Harvest()
|
t.Harvest()
|
||||||
elif p == 1:
|
elif p == 1:
|
||||||
plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
|
plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
|
||||||
elif p == 2:
|
elif p == 2:
|
||||||
plant.increase_soillevel(plant.max_soil_lvl - plant.soil_level)
|
plant.increase_soillevel(plant.max_soil_lvl - plant.soil_level)
|
||||||
elif p == 3:
|
elif p == 3:
|
||||||
plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
|
plant.increase_hydration(plant.max_hydration_lvl - plant.hydration)
|
||||||
plant.increase_soillevel(plant.max_soil_lvl - plant.soil_level)
|
plant.increase_soillevel(plant.max_soil_lvl - plant.soil_level)
|
||||||
|
|
||||||
#wyświetlamy dopasowaną wartość
|
#wyświetlamy dopasowaną wartość
|
||||||
print(p)
|
print(p)
|
||||||
|
pass
|
||||||
"""
|
"""
|
||||||
is_life = bool
|
is_life = bool
|
||||||
type = "POop"
|
type = "POop"
|
||||||
|
50
tractor.py
50
tractor.py
@ -4,8 +4,11 @@ import time
|
|||||||
from Graph import Graph
|
from Graph import Graph
|
||||||
from Cucumber import Cucumber
|
from Cucumber import Cucumber
|
||||||
from Tomato import Tomato
|
from Tomato import Tomato
|
||||||
|
from sklearn import tree
|
||||||
|
from Tree import TreeClass
|
||||||
|
|
||||||
class Tractor:
|
|
||||||
|
class Tractor(TreeClass):
|
||||||
sleep_time = 0.1
|
sleep_time = 0.1
|
||||||
graph = Graph()
|
graph = Graph()
|
||||||
moved_flag = False
|
moved_flag = False
|
||||||
@ -21,6 +24,11 @@ class Tractor:
|
|||||||
(x2, y2) = b
|
(x2, y2) = b
|
||||||
return abs(x1 - x2) + abs(y1 - y2)
|
return abs(x1 - x2) + abs(y1 - y2)
|
||||||
|
|
||||||
|
# def look_at_plats(field, location):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def rotate(self, direction):
|
async def rotate(self, direction):
|
||||||
reader, writer = await asyncio.open_connection('127.0.0.1', 8888)
|
reader, writer = await asyncio.open_connection('127.0.0.1', 8888)
|
||||||
writer.write(("rotate " + direction + "\n").encode())
|
writer.write(("rotate " + direction + "\n").encode())
|
||||||
@ -28,12 +36,20 @@ class Tractor:
|
|||||||
time.sleep(self.sleep_time)
|
time.sleep(self.sleep_time)
|
||||||
writer.close()
|
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)
|
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()
|
await reader.readline()
|
||||||
time.sleep(self.sleep_time)
|
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()
|
writer.close()
|
||||||
|
return wsp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def try_move(self):
|
async def try_move(self):
|
||||||
@ -189,27 +205,7 @@ class Tractor:
|
|||||||
|
|
||||||
await self.move_tractor(start_position)
|
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):
|
async def get_stats(self, location):
|
||||||
reader, writer = await asyncio.open_connection('127.0.0.1', 8888)
|
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]),
|
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])}
|
"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__":
|
if __name__ == "__main__":
|
||||||
start = (0,0)
|
start = (0,0)
|
||||||
goal = (10,6)
|
goal = (10,6)
|
||||||
tractor = Tractor((0,0), 'N')
|
tractor = Tractor((0,0), 'N')
|
||||||
# asyncio.run(tractor.move_tractor(start, goal))
|
# asyncio.run(tractor.move_tractor(start, goal))
|
||||||
asyncio.run(tractor.run())
|
asyncio.run(tractor.run())
|
||||||
|
asyncio.service(tractor.service())
|
||||||
|
Loading…
Reference in New Issue
Block a user