Merge old branches to refactor due to merge it with master #22

Merged
s481825 merged 20 commits from tree into refactor 2024-06-04 11:36:14 +02:00
5 changed files with 40 additions and 9 deletions
Showing only changes of commit f8a3156678 - Show all commits

13
App.py
View File

@ -11,6 +11,7 @@ import BFS
import AStar
import random
import Condition
import Drzewo
bfs1_flag=False
bfs2_flag=False #Change this lines to show different bfs implementation
@ -19,7 +20,7 @@ Astar = False
Astar2 = False
if bfs3_flag or Astar or Astar2:
Pole.stoneFlag = True
TreeFlag=True
pygame.init()
show_console=True
@ -36,7 +37,7 @@ ui=Ui.Ui(screen)
traktor_slot = pole.get_slot_from_cord((0, 0))
traktor = Tractor.Tractor(traktor_slot, screen, Osprzet.opryskiwacz,clock,bfs2_flag)
condition=Condition.Condition()
drzewo=Drzewo.Drzewo()
def init_demo(): #Demo purpose
old_info=""
@ -115,10 +116,14 @@ def init_demo(): #Demo purpose
else:
print_to_console("Nie można znaleźć ścieżki A*") # Wyświetl komunikat, jeśli nie znaleziono ścieżki
if(TreeFlag):
drzewo.treeLearn()
drzewo.plotTree()
print("Decyzja to: ",drzewo.makeDecision([[10,60,0,1,0,20,1,20]]))
#do moves and condtion cycles
start_flag=False
# demo_move()
condition.cycle()
condition.cycle() #powinno zostac wrzucone razem z getCondition do ruchu traktora. Aktualnie tutaj by zobaczyc czy dziala
condition.getCondition()
old_info=get_info(old_info)
for event in pygame.event.get():

3
Data/dataTree.csv Normal file
View File

@ -0,0 +1,3 @@
plant_water_lever,tractor_water_lever,weather,season,current_time,growth,disease,fertility,action
80,60,0,1,0,20,1,20,0
20,60,0,1,0,20,1,20,1
1 plant_water_lever tractor_water_lever weather season current_time growth disease fertility action
2 80 60 0 1 0 20 1 20 0
3 20 60 0 1 0 20 1 20 1

25
Drzewo.py Normal file
View File

@ -0,0 +1,25 @@
from sklearn import tree as skltree
import pandas,os
import matplotlib.pyplot as plt
atributes=['plant_water_lever','tractor_water_lever','weather','season','current_time','growth','disease','fertility'] #Columns in CSV file should be in the same order
class Drzewo:
def __init__(self):
self.tree=self.treeLearn()
def treeLearn(self):
csvdata=pandas.read_csv('Data/dataTree.csv')
x=csvdata[atributes]
decision=csvdata['action']
self.tree=skltree.DecisionTreeClassifier()
self.tree=self.tree.fit(x,decision)
def plotTree(self):
plt.figure()
skltree.plot_tree(self.tree,filled=True,feature_names=atributes)
plt.title("Drzewo decyzyjne wytrenowane na przygotowanych danych")
plt.show()
def makeDecision(self,values):
action=self.tree.predict(values) #0- nie podlewac, 1-podlewac
return action

View File

@ -1,3 +0,0 @@
class Tree:
def __init__(self) -> None:
pass

View File

@ -1,6 +1,7 @@
Required packages:
pygame,matplotlib,sklearn
pygame,matplotlib,sklearn,pandas
How to install:
pip install pygame
pip install matplotlib
pip install scikit-learn
pip install scikit-learn
pip install pandas