tree complete
Signed-off-by: Neerka <kuba.markil0220@gmail.com>
This commit is contained in:
parent
a2590ed657
commit
8c37aaea5d
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
10
.idea/Madra_smieciarka.iml
Normal file
10
.idea/Madra_smieciarka.iml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.10 (Madra_smieciarka)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
16
.idea/csv-editor.xml
Normal file
16
.idea/csv-editor.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CsvFileAttributes">
|
||||||
|
<option name="attributeMap">
|
||||||
|
<map>
|
||||||
|
<entry key="\classes\data.csv">
|
||||||
|
<value>
|
||||||
|
<Attribute>
|
||||||
|
<option name="separator" value="," />
|
||||||
|
</Attribute>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
7
.idea/misc.xml
Normal file
7
.idea/misc.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.10 (Madra_smieciarka)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (Madra_smieciarka)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Madra_smieciarka.iml" filepath="$PROJECT_DIR$/.idea/Madra_smieciarka.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -6,6 +6,7 @@ from sklearn.preprocessing import LabelEncoder
|
|||||||
from sklearn.tree import plot_tree
|
from sklearn.tree import plot_tree
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from sklearn.tree import export_text
|
from sklearn.tree import export_text
|
||||||
|
from joblib import dump
|
||||||
|
|
||||||
data = pd.read_csv("data.csv")
|
data = pd.read_csv("data.csv")
|
||||||
|
|
||||||
@ -28,18 +29,24 @@ treeclf.fit(x_train, y_train)
|
|||||||
|
|
||||||
y_pred = treeclf.predict(x_test)
|
y_pred = treeclf.predict(x_test)
|
||||||
|
|
||||||
#print("Przewidywane etykiety dla danych testowych:")
|
|
||||||
#print(y_pred)
|
|
||||||
|
|
||||||
accuracy = accuracy_score(y_test, y_pred)
|
accuracy = accuracy_score(y_test, y_pred)
|
||||||
print("Dokładność:", accuracy)
|
print("Dokładność:", accuracy)
|
||||||
|
|
||||||
|
# Zapisanie modelu do pliku
|
||||||
|
dump(treeclf, 'drzewo.joblib')
|
||||||
|
|
||||||
class_names = [str(class_label) for class_label in labels['decyzja'].classes_]
|
class_names = [str(class_label) for class_label in labels['decyzja'].classes_]
|
||||||
plt.figure(figsize=(25,20))
|
plt.figure(figsize=(25,20))
|
||||||
plot_tree(treeclf, feature_names=x.columns, class_names=class_names, filled=True)
|
plot_tree(treeclf, feature_names=x.columns, class_names=class_names, filled=True)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
for (column, encoder) in labels.items():
|
||||||
|
if column == 'decyzja':
|
||||||
|
continue
|
||||||
|
print(f"{column}:")
|
||||||
|
for (i, label) in enumerate(encoder.classes_):
|
||||||
|
print(f"{i}: {label}")
|
||||||
|
|
||||||
tree_text = export_text(treeclf, feature_names=list(x.columns))
|
tree_text = export_text(treeclf, feature_names=list(x.columns))
|
||||||
tree_file_path = "wyuczone_drzewo.txt"
|
tree_file_path = "wyuczone_drzewo.txt"
|
||||||
with open(tree_file_path, "w") as tree_file:
|
with open(tree_file_path, "w") as tree_file:
|
||||||
|
@ -4,16 +4,20 @@ from classes.Trash import *
|
|||||||
|
|
||||||
class Garbage:
|
class Garbage:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.full = random.randint(0, 2)
|
||||||
self.content = []
|
self.content = []
|
||||||
self.predict = []
|
self.known = []
|
||||||
self.prob: float = 0.3
|
self.prob: float = 0.3
|
||||||
self.generatePredict()
|
self.generateKnown()
|
||||||
self.generateContent()
|
self.generateContent()
|
||||||
self.predict = tuple(self.predict)
|
self.known = tuple(self.known)
|
||||||
|
|
||||||
def getContent(self):
|
def getContent(self):
|
||||||
return self.content
|
return self.content
|
||||||
|
|
||||||
|
def getFull(self):
|
||||||
|
return self.full
|
||||||
|
|
||||||
def setContent(self, content):
|
def setContent(self, content):
|
||||||
self.content = content
|
self.content = content
|
||||||
return self
|
return self
|
||||||
@ -23,17 +27,17 @@ class Garbage:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def removeContent(self, item: int):
|
def removeContent(self, item: int):
|
||||||
return self.content.pop(item)
|
return self.content.remove(item)
|
||||||
|
|
||||||
def getPredict(self):
|
def getKnown(self):
|
||||||
return self.predict
|
return self.known
|
||||||
|
|
||||||
def setPredict(self, predict):
|
def setKnown(self, predict):
|
||||||
self.predict = predict
|
self.known = predict
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def addPredict(self, item):
|
def addKnown(self, item):
|
||||||
self.predict.append(item)
|
self.known.append(item)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def getProb(self):
|
def getProb(self):
|
||||||
@ -43,20 +47,20 @@ class Garbage:
|
|||||||
self.prob = prob
|
self.prob = prob
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def generatePredict(self, i=random.choice([2, 3])):
|
def generateKnown(self, i=random.choice([2, 3])):
|
||||||
if i < 0:
|
if i < 0:
|
||||||
self.predict.pop(i)
|
self.known.pop(i)
|
||||||
else:
|
else:
|
||||||
for _ in range(i):
|
for _ in range(i):
|
||||||
possible = [Papier(), MetalPlastik(), Szklo(), Mixed(), Bio()]
|
possible = [Papier(), MetalPlastik(), Szklo(), Mixed(), Bio()]
|
||||||
traf = random.choice(possible)
|
traf = random.choice(possible)
|
||||||
self.predict.append(traf)
|
self.known.append(traf)
|
||||||
for bruh in possible:
|
for bruh in possible:
|
||||||
if bruh != traf:
|
if bruh != traf:
|
||||||
del bruh
|
del bruh
|
||||||
|
|
||||||
def generateContent(self):
|
def generateContent(self):
|
||||||
self.setContent(self.predict[:])
|
self.setContent(self.known[:])
|
||||||
if random.random() < self.prob:
|
if random.random() < self.prob:
|
||||||
mod = random.choice([1, -1])
|
mod = random.choice([1, -1])
|
||||||
self.generatePredict(mod)
|
self.generateKnown(mod)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
import heapq
|
import heapq
|
||||||
|
from joblib import load
|
||||||
import pygame
|
import pygame
|
||||||
from classes.Household import *
|
from classes.Household import *
|
||||||
from classes.Node import *
|
from classes.Node import *
|
||||||
@ -12,6 +12,11 @@ class Garbagetruck:
|
|||||||
|
|
||||||
def __init__(self, mult):
|
def __init__(self, mult):
|
||||||
self.mult = mult
|
self.mult = mult
|
||||||
|
self.weather = random.randint(0, 2)
|
||||||
|
self.season = random.randint(0, 3)
|
||||||
|
self.daytime = random.randint(0, 3)
|
||||||
|
self.zapelnienie: int = 1
|
||||||
|
self.knowledge = [self.season, self.daytime, -1, -1, self.zapelnienie, -1, -1, self.weather]
|
||||||
self.capacity: int = 20
|
self.capacity: int = 20
|
||||||
self.trash: list = []
|
self.trash: list = []
|
||||||
self.trashweight: int = 0
|
self.trashweight: int = 0
|
||||||
@ -29,11 +34,45 @@ class Garbagetruck:
|
|||||||
self.route = None
|
self.route = None
|
||||||
self.scanner = None
|
self.scanner = None
|
||||||
self.planner = None
|
self.planner = None
|
||||||
self.driver = None
|
self.driver = load("./classes/drzewo.joblib")
|
||||||
self.orientation = 3 # Niech numery będą tak: N - 0, W - 1, S - 2, E - 3 -- po prostu odwrotnie do zegara
|
self.orientation = 3 # Niech numery będą tak: N - 0, W - 1, S - 2, E - 3 -- po prostu odwrotnie do zegara
|
||||||
self.runningtime = 0
|
self.runningtime = 0
|
||||||
self.movesequence = []
|
self.movesequence = []
|
||||||
self.target = None
|
self.target = None
|
||||||
|
self.analising = False
|
||||||
|
|
||||||
|
def getAnalising(self):
|
||||||
|
return self.analising
|
||||||
|
|
||||||
|
def switchAnalising(self):
|
||||||
|
self.analising = False if self.analising else True
|
||||||
|
return self
|
||||||
|
|
||||||
|
def decision(self, house, trash, can):
|
||||||
|
knowledge = self.knowledge[:]
|
||||||
|
knowledge[2] = trash.getTreetype()
|
||||||
|
knowledge[3] = can.getFull()
|
||||||
|
knowledge[5] = house.getPaid()
|
||||||
|
knowledge[6] = house.getLastTaken()
|
||||||
|
print(knowledge)
|
||||||
|
|
||||||
|
if -1 not in knowledge:
|
||||||
|
return self.driver.predict([knowledge])
|
||||||
|
else:
|
||||||
|
print("NIE WIEM, BRAK DANYCH")
|
||||||
|
|
||||||
|
def pickTrash(self):
|
||||||
|
house = self.getState()
|
||||||
|
can = house.getGarbage()
|
||||||
|
trashlist = can.getContent()
|
||||||
|
for trash in trashlist:
|
||||||
|
if self.trashweight + trash.getWaga() <= self.capacity:
|
||||||
|
decision = self.decision(house, trash, can)
|
||||||
|
print(f"{trash.getTtype()} - decyzja: {decision}")
|
||||||
|
if decision:
|
||||||
|
self.addTrash(trash)
|
||||||
|
can.removeContent(trash)
|
||||||
|
self.switchAnalising()
|
||||||
|
|
||||||
def getState(self):
|
def getState(self):
|
||||||
return self.state
|
return self.state
|
||||||
@ -99,14 +138,24 @@ class Garbagetruck:
|
|||||||
self.trash.append(trash)
|
self.trash.append(trash)
|
||||||
self.addTrashweight(trash.getWaga())
|
self.addTrashweight(trash.getWaga())
|
||||||
|
|
||||||
|
def changeZapelnienie(self) -> None:
|
||||||
|
if self.trashweight < 0.25*self.capacity:
|
||||||
|
self.zapelnienie = 1
|
||||||
|
elif self.trashweight < self.capacity:
|
||||||
|
self.zapelnienie = 2
|
||||||
|
else:
|
||||||
|
self.zapelnienie = 0
|
||||||
|
|
||||||
def getTrashweight(self) -> int:
|
def getTrashweight(self) -> int:
|
||||||
return self.trashweight
|
return self.trashweight
|
||||||
|
|
||||||
def setTrashweight(self, weight: int) -> None:
|
def setTrashweight(self, weight: int) -> None:
|
||||||
self.trashweight = weight
|
self.trashweight = weight
|
||||||
|
self.changeZapelnienie()
|
||||||
|
|
||||||
def addTrashweight(self, weight: int) -> None:
|
def addTrashweight(self, weight: int) -> None:
|
||||||
self.trashweight += weight
|
self.trashweight += weight
|
||||||
|
self.changeZapelnienie()
|
||||||
|
|
||||||
def getImage(self) -> object:
|
def getImage(self) -> object:
|
||||||
return self.image
|
return self.image
|
||||||
@ -121,7 +170,7 @@ class Garbagetruck:
|
|||||||
self.position = position
|
self.position = position
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def modPosiotion(self, modX, modY):
|
def modPosition(self, modX, modY):
|
||||||
x = self.getPosition()[0] + modX
|
x = self.getPosition()[0] + modX
|
||||||
y = self.getPosition()[1] + modY
|
y = self.getPosition()[1] + modY
|
||||||
position = [x, y]
|
position = [x, y]
|
||||||
@ -211,11 +260,12 @@ class Garbagetruck:
|
|||||||
stepY = 1
|
stepY = 1
|
||||||
elif ort == 3 and x != 30:
|
elif ort == 3 and x != 30:
|
||||||
stepX = 1
|
stepX = 1
|
||||||
self.modPosiotion(stepX, stepY)
|
self.modPosition(stepX, stepY)
|
||||||
|
|
||||||
def graphsearch(self):
|
def graphsearch(self):
|
||||||
house_positions = [house.getPosition() for house in self.houses]
|
house_positions = [house.getPosition() for house in self.houses]
|
||||||
cans_positions = [can.getPosition() for can in self.trashcans]
|
cans_positions = [can.getPosition() for can in self.trashcans]
|
||||||
|
|
||||||
def succ(elem):
|
def succ(elem):
|
||||||
def virtRotateLeft(state):
|
def virtRotateLeft(state):
|
||||||
ort = (state[-1] + 1) % 4
|
ort = (state[-1] + 1) % 4
|
||||||
@ -246,7 +296,6 @@ class Garbagetruck:
|
|||||||
result = [x, y, ort]
|
result = [x, y, ort]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
op = elem.getState()
|
op = elem.getState()
|
||||||
forward = {"result": virtMoveForward(op), "action": "F"}
|
forward = {"result": virtMoveForward(op), "action": "F"}
|
||||||
left = {"result": virtRotateLeft(op), "action": "L"}
|
left = {"result": virtRotateLeft(op), "action": "L"}
|
||||||
@ -263,7 +312,7 @@ class Garbagetruck:
|
|||||||
x, y, _ = state
|
x, y, _ = state
|
||||||
if (x, y) in house_positions:
|
if (x, y) in house_positions:
|
||||||
return 10
|
return 10
|
||||||
elif (x,y) in cans_positions:
|
elif (x, y) in cans_positions:
|
||||||
return 5
|
return 5
|
||||||
else:
|
else:
|
||||||
return 1
|
return 1
|
||||||
@ -274,7 +323,6 @@ class Garbagetruck:
|
|||||||
temp = self.getPosition()[:]
|
temp = self.getPosition()[:]
|
||||||
temp.append(self.getOrientation())
|
temp.append(self.getOrientation())
|
||||||
initial = Node(temp)
|
initial = Node(temp)
|
||||||
initial.setCost(0)
|
|
||||||
fringe.append((0, initial)) # (priority, node)
|
fringe.append((0, initial)) # (priority, node)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -300,11 +348,12 @@ class Garbagetruck:
|
|||||||
explored.append(elem)
|
explored.append(elem)
|
||||||
suc = succ(elem)
|
suc = succ(elem)
|
||||||
for wynik in suc:
|
for wynik in suc:
|
||||||
if wynik['result'] not in [item[1].getState() for item in fringe] and wynik['result'] not in [item.getState() for item in explored]:
|
if (wynik['result'] not in [item[1].getState() for item in fringe]
|
||||||
x = Node(wynik["result"])
|
and wynik['result'] not in [item.getState() for item in explored]):
|
||||||
x.setParent(elem)
|
x = (Node(wynik["result"])
|
||||||
x.setAction(wynik["action"])
|
.setParent(elem)
|
||||||
x.setCost(elem.getCost() + cost(x.getState()))
|
.setAction(wynik["action"]))
|
||||||
|
x.setCost(x.getParent().getCost() + cost(x.getState()))
|
||||||
priority = x.getCost() + heuristic(x.getState())
|
priority = x.getCost() + heuristic(x.getState())
|
||||||
heapq.heappush(fringe, (priority, x))
|
heapq.heappush(fringe, (priority, x))
|
||||||
|
|
||||||
@ -318,15 +367,18 @@ class Garbagetruck:
|
|||||||
self.moveForward()
|
self.moveForward()
|
||||||
|
|
||||||
def randomTarget(self):
|
def randomTarget(self):
|
||||||
wybor1 = random.choice([1,2])
|
# wybor1 = random.random()
|
||||||
if wybor1 == 1:
|
# if wybor1 < 0.75:
|
||||||
|
wybor2 = random.choice(self.houses)
|
||||||
|
while not wybor2.getGarbage().getContent():
|
||||||
wybor2 = random.choice(self.houses)
|
wybor2 = random.choice(self.houses)
|
||||||
else:
|
# else:
|
||||||
wybor2 = random.choice(self.trashcans)
|
# wybor2 = random.choice(self.trashcans)
|
||||||
wybor2.switchFinal()
|
wybor2.switchFinal()
|
||||||
# print(wybor2)
|
# print(wybor2)
|
||||||
|
|
||||||
def classifyTrash(self):
|
def classifyTrash(self):
|
||||||
pass
|
pass
|
||||||
# Tutaj jest plan żeby dopiero napisać funkcję jak już będzie klasyfikator
|
# Tutaj jest plan żeby dopiero napisać funkcję jak już będzie klasyfikator
|
||||||
# ogólnie to myślałem żeby po prostu zklasyfikować śmieć i zmienić mu trashtype na rozpoznany, żeby śmieciarka go tak posegreowała
|
# ogólnie to myślałem żeby po prostu zklasyfikować śmieć i zmienić mu trashtype na rozpoznany,
|
||||||
|
# żeby śmieciarka go tak posegreowała
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
from classes.Garbage import *
|
from classes.Garbage import *
|
||||||
|
|
||||||
|
|
||||||
class Household:
|
class Household:
|
||||||
def __init__(self, mult):
|
def __init__(self, mult):
|
||||||
|
self.paid = random.randint(0, 1)
|
||||||
|
self.lastTaken = random.randint(0, 30)
|
||||||
self.mult = mult
|
self.mult = mult
|
||||||
self.id: int = 0
|
self.id: int = 0
|
||||||
self.image: object = None
|
self.image: object = None
|
||||||
@ -13,6 +17,12 @@ class Household:
|
|||||||
def getFinal(self):
|
def getFinal(self):
|
||||||
return self.final
|
return self.final
|
||||||
|
|
||||||
|
def getPaid(self):
|
||||||
|
return self.paid
|
||||||
|
|
||||||
|
def getLastTaken(self):
|
||||||
|
return self.lastTaken
|
||||||
|
|
||||||
def switchFinal(self):
|
def switchFinal(self):
|
||||||
self.final = False if self.final else True
|
self.final = False if self.final else True
|
||||||
return self
|
return self
|
||||||
|
@ -27,6 +27,7 @@ class Node:
|
|||||||
|
|
||||||
def setCost(self, cost):
|
def setCost(self, cost):
|
||||||
self.cost = cost
|
self.cost = cost
|
||||||
|
return self
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return self.getState() < other.getState()
|
return self.getState() < other.getState()
|
@ -3,6 +3,13 @@ typelist = ["paper", "metals_and_plastics", "mixed", "bio_waste", "glass"]
|
|||||||
|
|
||||||
class Trash:
|
class Trash:
|
||||||
|
|
||||||
|
def getTreetype(self):
|
||||||
|
return self.treetype
|
||||||
|
|
||||||
|
def setTreetype(self, treetype):
|
||||||
|
self.treetype = id
|
||||||
|
return self
|
||||||
|
|
||||||
def getTtype(self):
|
def getTtype(self):
|
||||||
return self.ttype
|
return self.ttype
|
||||||
|
|
||||||
@ -27,6 +34,7 @@ class Trash:
|
|||||||
|
|
||||||
class Papier(Trash):
|
class Papier(Trash):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.treetype = 1
|
||||||
self.ttype = "Papier"
|
self.ttype = "Papier"
|
||||||
self.waga = 2
|
self.waga = 2
|
||||||
self.image = None
|
self.image = None
|
||||||
@ -34,6 +42,7 @@ class Papier(Trash):
|
|||||||
|
|
||||||
class MetalPlastik(Trash):
|
class MetalPlastik(Trash):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.treetype = 2
|
||||||
self.ttype = "MetalPlastik"
|
self.ttype = "MetalPlastik"
|
||||||
self.waga = 3
|
self.waga = 3
|
||||||
self.image = None
|
self.image = None
|
||||||
@ -41,6 +50,7 @@ class MetalPlastik(Trash):
|
|||||||
|
|
||||||
class Mixed(Trash):
|
class Mixed(Trash):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.treetype = 4
|
||||||
self.ttype = "Mixed"
|
self.ttype = "Mixed"
|
||||||
self.waga = 1
|
self.waga = 1
|
||||||
self.image = None
|
self.image = None
|
||||||
@ -48,6 +58,7 @@ class Mixed(Trash):
|
|||||||
|
|
||||||
class Bio(Trash):
|
class Bio(Trash):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.treetype = 0
|
||||||
self.ttype = "Bio"
|
self.ttype = "Bio"
|
||||||
self.waga = 2
|
self.waga = 2
|
||||||
self.image = None
|
self.image = None
|
||||||
@ -55,6 +66,7 @@ class Bio(Trash):
|
|||||||
|
|
||||||
class Szklo(Trash):
|
class Szklo(Trash):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.treetype = 3
|
||||||
self.ttype = "Szklo"
|
self.ttype = "Szklo"
|
||||||
self.waga = 5
|
self.waga = 5
|
||||||
self.image = None
|
self.image = None
|
||||||
|
BIN
classes/drzewo.joblib
Normal file
BIN
classes/drzewo.joblib
Normal file
Binary file not shown.
67
classes/wyuczone_drzewo.txt
Normal file
67
classes/wyuczone_drzewo.txt
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
|--- zapelnienie_kosza <= 0.50
|
||||||
|
| |--- czy_zaplacone <= 0.50
|
||||||
|
| | |--- class: 0
|
||||||
|
| |--- czy_zaplacone > 0.50
|
||||||
|
| | |--- pora_dnia <= 1.50
|
||||||
|
| | | |--- dni_od_ostatniego_wywozu <= 15.00
|
||||||
|
| | | | |--- typ_smieci <= 1.00
|
||||||
|
| | | | | |--- class: 1
|
||||||
|
| | | | |--- typ_smieci > 1.00
|
||||||
|
| | | | | |--- pora_dnia <= 0.50
|
||||||
|
| | | | | | |--- class: 0
|
||||||
|
| | | | | |--- pora_dnia > 0.50
|
||||||
|
| | | | | | |--- dni_od_ostatniego_wywozu <= 9.50
|
||||||
|
| | | | | | | |--- zapelnienie_smieciarki <= 0.50
|
||||||
|
| | | | | | | | |--- class: 0
|
||||||
|
| | | | | | | |--- zapelnienie_smieciarki > 0.50
|
||||||
|
| | | | | | | | |--- pora_roku <= 2.00
|
||||||
|
| | | | | | | | | |--- class: 0
|
||||||
|
| | | | | | | | |--- pora_roku > 2.00
|
||||||
|
| | | | | | | | | |--- class: 1
|
||||||
|
| | | | | | |--- dni_od_ostatniego_wywozu > 9.50
|
||||||
|
| | | | | | | |--- class: 1
|
||||||
|
| | | |--- dni_od_ostatniego_wywozu > 15.00
|
||||||
|
| | | | |--- dni_od_ostatniego_wywozu <= 26.50
|
||||||
|
| | | | | |--- class: 1
|
||||||
|
| | | | |--- dni_od_ostatniego_wywozu > 26.50
|
||||||
|
| | | | | |--- class: 0
|
||||||
|
| | |--- pora_dnia > 1.50
|
||||||
|
| | | |--- class: 1
|
||||||
|
|--- zapelnienie_kosza > 0.50
|
||||||
|
| |--- zapelnienie_kosza <= 1.50
|
||||||
|
| | |--- class: 0
|
||||||
|
| |--- zapelnienie_kosza > 1.50
|
||||||
|
| | |--- zapelnienie_smieciarki <= 0.50
|
||||||
|
| | | |--- pora_dnia <= 0.50
|
||||||
|
| | | | |--- class: 0
|
||||||
|
| | | |--- pora_dnia > 0.50
|
||||||
|
| | | | |--- pora_dnia <= 1.50
|
||||||
|
| | | | | |--- class: 1
|
||||||
|
| | | | |--- pora_dnia > 1.50
|
||||||
|
| | | | | |--- dni_od_ostatniego_wywozu <= 29.50
|
||||||
|
| | | | | | |--- class: 0
|
||||||
|
| | | | | |--- dni_od_ostatniego_wywozu > 29.50
|
||||||
|
| | | | | | |--- class: 1
|
||||||
|
| | |--- zapelnienie_smieciarki > 0.50
|
||||||
|
| | | |--- pora_dnia <= 0.50
|
||||||
|
| | | | |--- warunki_pogodowe <= 0.50
|
||||||
|
| | | | | |--- class: 0
|
||||||
|
| | | | |--- warunki_pogodowe > 0.50
|
||||||
|
| | | | | |--- dni_od_ostatniego_wywozu <= 5.50
|
||||||
|
| | | | | | |--- class: 0
|
||||||
|
| | | | | |--- dni_od_ostatniego_wywozu > 5.50
|
||||||
|
| | | | | | |--- class: 1
|
||||||
|
| | | |--- pora_dnia > 0.50
|
||||||
|
| | | | |--- warunki_pogodowe <= 1.50
|
||||||
|
| | | | | |--- class: 1
|
||||||
|
| | | | |--- warunki_pogodowe > 1.50
|
||||||
|
| | | | | |--- pora_roku <= 2.50
|
||||||
|
| | | | | | |--- dni_od_ostatniego_wywozu <= 23.00
|
||||||
|
| | | | | | | |--- class: 1
|
||||||
|
| | | | | | |--- dni_od_ostatniego_wywozu > 23.00
|
||||||
|
| | | | | | | |--- dni_od_ostatniego_wywozu <= 29.50
|
||||||
|
| | | | | | | | |--- class: 0
|
||||||
|
| | | | | | | |--- dni_od_ostatniego_wywozu > 29.50
|
||||||
|
| | | | | | | | |--- class: 1
|
||||||
|
| | | | | |--- pora_roku > 2.50
|
||||||
|
| | | | | | |--- class: 0
|
@ -36,9 +36,18 @@ def trashcanGenerator(mult) -> list:
|
|||||||
|
|
||||||
def householdGenerator(mult):
|
def householdGenerator(mult):
|
||||||
new_house_size = (mult, mult)
|
new_house_size = (mult, mult)
|
||||||
house_positions = [(15, 5), (17, 5), (19, 5), (21, 5), (15, 8), (17, 8), (19, 8), (21, 8)]
|
temp = []
|
||||||
|
for i in range(1, 29):
|
||||||
|
if i % 2 == 1:
|
||||||
|
temp.append((i, 6))
|
||||||
|
temp.append((i, 12))
|
||||||
|
elif i % 2 == 0:
|
||||||
|
temp.append((i, 9))
|
||||||
|
if i % 2 == 1 and i % 4 != 1:
|
||||||
|
temp.append((i, 10))
|
||||||
|
house_positions = temp
|
||||||
houses = []
|
houses = []
|
||||||
for i in range(8):
|
for i in range(len(house_positions)):
|
||||||
house_image = pygame.image.load(f'sprites/domek.png')
|
house_image = pygame.image.load(f'sprites/domek.png')
|
||||||
house_image = pygame.transform.scale(house_image, new_house_size)
|
house_image = pygame.transform.scale(house_image, new_house_size)
|
||||||
house = generateHousehold(mult, i, house_image, house_positions[i])
|
house = generateHousehold(mult, i, house_image, house_positions[i])
|
||||||
|
14
main.py
14
main.py
@ -9,7 +9,7 @@ MULT = 50
|
|||||||
SIZE = (MULT*W, MULT*H)
|
SIZE = (MULT*W, MULT*H)
|
||||||
pygame.init()
|
pygame.init()
|
||||||
screen = pygame.display.set_mode(SIZE)
|
screen = pygame.display.set_mode(SIZE)
|
||||||
tilemap = Tilemap(Tileset("sprites/TIles/1Tiles/FieldsTile_38.png", mult=MULT), mult=MULT, size=(W, H))
|
tilemap = Tilemap(Tileset("sprites/TIles/1 Tiles/FieldsTile_38.png", mult=MULT), mult=MULT, size=(W, H))
|
||||||
targimage = pygame.image.load("sprites/X.png").convert_alpha()
|
targimage = pygame.image.load("sprites/X.png").convert_alpha()
|
||||||
targimage = pygame.transform.scale(targimage, (MULT, MULT))
|
targimage = pygame.transform.scale(targimage, (MULT, MULT))
|
||||||
|
|
||||||
@ -17,13 +17,16 @@ trashcans = trashcanGenerator(MULT)
|
|||||||
houses = householdGenerator(MULT)
|
houses = householdGenerator(MULT)
|
||||||
garbagetruck = Garbagetruck(MULT).setHouses(houses).setTrashcans(trashcans)
|
garbagetruck = Garbagetruck(MULT).setHouses(houses).setTrashcans(trashcans)
|
||||||
|
|
||||||
|
print("Kolejność danych do drzewa:")
|
||||||
|
print("Pora roku - Pora dnia - Typ śmieci - Zapełnienie kosza - Zapełnienie śmieciarki - Zapłacone - Ostatnio zabrane "
|
||||||
|
"- Pogoda")
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
while running:
|
while running:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
running = False
|
running = False
|
||||||
|
|
||||||
print(garbagetruck.movesequence)
|
|
||||||
garbagetruck.setTarget()
|
garbagetruck.setTarget()
|
||||||
garbagetruck.executeMovement()
|
garbagetruck.executeMovement()
|
||||||
screen.fill((0, 0, 0))
|
screen.fill((0, 0, 0))
|
||||||
@ -33,7 +36,6 @@ while running:
|
|||||||
screen.blit(i.getImage(), i.printme())
|
screen.blit(i.getImage(), i.printme())
|
||||||
for h in houses:
|
for h in houses:
|
||||||
screen.blit(h.getImage(), h.printme())
|
screen.blit(h.getImage(), h.printme())
|
||||||
print(garbagetruck.getPosition())
|
|
||||||
bruh = garbagetruck.target.getPosition()
|
bruh = garbagetruck.target.getPosition()
|
||||||
bruhlist = [i*MULT for i in bruh]
|
bruhlist = [i*MULT for i in bruh]
|
||||||
screen.blit(targimage, bruhlist)
|
screen.blit(targimage, bruhlist)
|
||||||
@ -41,15 +43,19 @@ while running:
|
|||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
garbagetruck.scanTile()
|
garbagetruck.scanTile()
|
||||||
state = garbagetruck.getState()
|
state = garbagetruck.getState()
|
||||||
|
while garbagetruck.getAnalising():
|
||||||
|
garbagetruck.pickTrash()
|
||||||
if not garbagetruck.movesequence:
|
if not garbagetruck.movesequence:
|
||||||
moves = garbagetruck.graphsearch()
|
moves = garbagetruck.graphsearch()
|
||||||
garbagetruck.setMovesequence(moves)
|
garbagetruck.setMovesequence(moves)
|
||||||
if state:
|
if state:
|
||||||
if state.getFinal():
|
if state.getFinal():
|
||||||
|
print([trash.getTtype() for trash in state.getGarbage().getContent()])
|
||||||
|
garbagetruck.switchAnalising()
|
||||||
garbagetruck.getState().switchFinal()
|
garbagetruck.getState().switchFinal()
|
||||||
elif not garbagetruck.movesequence:
|
elif not garbagetruck.movesequence:
|
||||||
garbagetruck.randomTarget()
|
garbagetruck.randomTarget()
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
37
słownik_danych.txt
Normal file
37
słownik_danych.txt
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
pora_roku:
|
||||||
|
0: jesien
|
||||||
|
1: lato
|
||||||
|
2: wiosna
|
||||||
|
3: zima
|
||||||
|
|
||||||
|
pora_dnia:
|
||||||
|
0: noc
|
||||||
|
1: popoludnie
|
||||||
|
2: rano
|
||||||
|
3: wieczor
|
||||||
|
|
||||||
|
typ_smieci:
|
||||||
|
0: bio odpady
|
||||||
|
1: papier
|
||||||
|
2: plastik i metale
|
||||||
|
3: szklo
|
||||||
|
4: zmieszane
|
||||||
|
|
||||||
|
zapelnienie_kosza:
|
||||||
|
0: pelny
|
||||||
|
1: pusty
|
||||||
|
2: srednio zapelniony
|
||||||
|
|
||||||
|
zapelnienie_smieciarki:
|
||||||
|
0: pelna
|
||||||
|
1: pusta
|
||||||
|
2: srednio zapelniona
|
||||||
|
|
||||||
|
czy_zaplacone:
|
||||||
|
0: nie
|
||||||
|
1: tak
|
||||||
|
|
||||||
|
warunki_pogodowe:
|
||||||
|
0: dobre
|
||||||
|
1: umiarkowane
|
||||||
|
2: zle
|
Loading…
Reference in New Issue
Block a user