diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 13566b8..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/.idea/SI-projekt-smieciarka2.iml b/.idea/SI-projekt-smieciarka2.iml
deleted file mode 100644
index d0876a7..0000000
--- a/.idea/SI-projekt-smieciarka2.iml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
deleted file mode 100644
index 105ce2d..0000000
--- a/.idea/inspectionProfiles/profiles_settings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index d56657a..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 085e946..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/snn/snn.py b/snn/snn.py
index 190dbd5..df01f83 100644
--- a/snn/snn.py
+++ b/snn/snn.py
@@ -4,10 +4,10 @@ import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath
-DATASET_PATH = Path('../dataset')
+DATASET_PATH = pathlib.Path('../dataset')
learn = load_learner(DATASET_PATH/'export.pkl')
-path = Path(DATASET_PATH/'glass/glass1.jpg')
+path = pathlib.Path(DATASET_PATH / 'others/trash1.jpg')
def getPredict(learner, path):
prediction = learner.predict(path)
diff --git a/src/__pycache__/astar.cpython-39.pyc b/src/__pycache__/astar.cpython-39.pyc
new file mode 100644
index 0000000..4e33298
Binary files /dev/null and b/src/__pycache__/astar.cpython-39.pyc differ
diff --git a/src/__pycache__/snn.cpython-39.pyc b/src/__pycache__/snn.cpython-39.pyc
new file mode 100644
index 0000000..0360b74
Binary files /dev/null and b/src/__pycache__/snn.cpython-39.pyc differ
diff --git a/src/astar.py b/src/astar.py
index b50b2e2..e09edd0 100644
--- a/src/astar.py
+++ b/src/astar.py
@@ -1,51 +1,58 @@
from queue import PriorityQueue
+import numpy as np
+
def heuristic(xy1, xy2):
return abs(xy1[0] - xy2[0]) + abs(xy1[1] - xy2[1])
-def neighbours(point):
- x, y = point
- list=((x+1,y), (x,y+1), (x,y-1), (x-1,y))
- return list
-#determining the cost of a specific field in the grid
+def neighbours(point, collisionsMap):
+ x, y = point
+ list = [(x + 1, y), (x, y + 1), (x, y - 1), (x - 1, y)]
+ return [(x, y) for x, y in list if 0 <= x <= 14 and 0 <= y <= 14 and not collisionsMap[x][y]]
+
+
+# determining the cost of a specific field in the grid
def checkCost(grid, xy):
x, y = xy
cost = grid[x][y]
return cost
-def aStar(grid, start, goal):
+
+def aStar(grid, collisionsMap, start, goal):
openlist = PriorityQueue()
openlist.put(start, 0)
fScore = {}
+ gScore = {}
origin = {start: None}
- fScore[start] = 0
- closedlist=[]
+ fScore[start] = heuristic(start, goal)
+ gScore[start] = 0
- while openlist!= {} :
+ while not openlist.empty():
current = openlist.get()
if current == goal:
path = []
- #following from the succesors to the root our starting point
- while current != start:
+ # following from the succesors to the root our starting point
+ while current is not None:
path.append(current)
current = origin[current]
path.reverse()
- break
+ return path
# successor function
- for succ in neighbours(current):
- #checking if didn't go out of the maze
- if(succ[0] < 0 or succ[1] < 0 or succ[0] > 14 or succ[1] > 14):
- continue
+ for succ in neighbours(current, collisionsMap):
+ # checking if didn't go out of the maze
+ if succ[0] < 0 or succ[1] < 0 or succ[0] > 14 or succ[1] > 14:
+ continue
- gScore = fScore[current[0],current[1]] + checkCost(grid, current)
- if succ not in closedlist or gScore < fScore[succ[0],succ[1]]:
- closedlist.append(succ)
- origin[succ[0],succ[1]] = current
- fScore[succ[0],succ[1]] = gScore
- priority = gScore + heuristic(goal, succ)
+ tentiative_gScore = gScore.get(current, np.inf) + checkCost(grid, succ)
+ if tentiative_gScore < gScore.get(succ, np.inf):
+ origin[succ] = current
+ priority = tentiative_gScore + heuristic(goal, succ)
+ fScore[succ] = priority
+ gScore[succ] = tentiative_gScore
openlist.put(succ, priority)
- return path
\ No newline at end of file
+
+ raise RuntimeError("No path found")
diff --git a/src/board.py b/src/board.py
index edc84e6..4261d97 100644
--- a/src/board.py
+++ b/src/board.py
@@ -1,10 +1,32 @@
+from pathlib import Path
+
+import numpy as np
+
import astar
import pygame
+import snn
+import joblib
+import os
screen = []
objectArray = []
collisionsMap = []
+decision_tree = joblib.load(Path('../tree/decisionTreeClassifier'))
+
+type_map = {
+ 'glass': 2,
+ 'others': 0,
+ 'paper': 4,
+ 'plastic': 3
+}
+testset_path = Path('../testset')
+testset = [Path(f'{testset_path}/{file}') for file in os.listdir(testset_path)]
+
+season = 2
+truck_full = 0
+truck_working = 0
+
weightsMap = ([1, 2, 1, 4, 5, 2, 7, 8, 5, 4, 15, 3, 4, 5, 8],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 1],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 5, 3],
@@ -65,10 +87,8 @@ class Agent(Object):
truck = pygame.transform.scale(truck, (square, square))
screen.blit(truck, (circleX, circleY))
- def move(self, gridLength, path):
- for (x, y) in path:
- newPos = self.pos.get_moved(x, y)
- self.move_if_possible(newPos, gridLength)
+ def move(self, newPos):
+ self.pos = newPos
def move_if_possible(self, newPos, gridLength):
if movement_allowed(newPos, gridLength):
@@ -76,13 +96,13 @@ class Agent(Object):
class House(Object):
- def __init__(self, name, pos):
+ def __init__(self, name, pos, **kwargs):
super().__init__(name, pos)
- self.trash_cans = {
- "paper": False,
- "glass": False,
- "plastic": False,
- "others": False
+ self.trash_can = {
+ "type": kwargs.get('type', np.random.choice(testset)),
+ 'animal': kwargs.get('animal', np.random.randint(0, 2)),
+ 'quantity': kwargs.get('quantity', np.random.random() * 0.7 + 0.3),
+ 'time': kwargs.get('time', np.random.randint(0, 6))
}
def draw(self, square):
@@ -167,7 +187,8 @@ if __name__ == '__main__':
(7, 4), (3, 10), (8, 10), (4, 5), (1, 2), (10, 4), (13, 14), (6, 9)
]])]
holes = [Hole(f'dziura-{i}', pos) for i, pos in enumerate([Position(x, y) for x, y in [
- (4, 9), (5, 11), (11, 7), (13, 8)
+ (4, 9), (5, 11), (11, 7), (13, 8), (0, 1), (1, 1), (2, 1), (14, 13),
+ (13, 13), (4, 8), (5, 9), (7, 9), (6, 8), (3, 5), (4, 6), (5, 5)
]])]
objectArray.append(agent)
objectArray.append(junkyard)
@@ -175,7 +196,7 @@ if __name__ == '__main__':
objectArray += holes
collisionsMap = [[False] * gridSize for _ in range(gridSize)]
- for object in objectArray[1:]:
+ for object in holes:
collisionsMap[object.pos.x][object.pos.y] = True
width = 610
@@ -184,12 +205,51 @@ if __name__ == '__main__':
startPos = (0, 0)
finalPos = (14, 14)
- astarPath = astar.aStar(weightsMap, startPos, finalPos)
+ astarPath = astar.aStar(weightsMap, collisionsMap, startPos, finalPos)
+ checkpoints = [startPos]
+ for house in houses:
+ checkpoints.append((house.pos.x, house.pos.y))
+ checkpoints.append(finalPos)
+ astarPath = []
+ for i in range(len(checkpoints) - 1):
+ path = astar.aStar(weightsMap, collisionsMap, checkpoints[i], checkpoints[i + 1])
+ if i == 0:
+ astarPath += path
+ else:
+ astarPath += path[1:]
+
print(astarPath)
+ pathPos = 0
+ nextCheckpoint = 1
while True:
+ agent_x, agent_y = astarPath[pathPos]
+ checkpoint_x, checkpoint_y = checkpoints[nextCheckpoint]
+ agent.pos = Position(agent_x, agent_y)
+ for house in houses:
+ if house.pos.x == agent_x and house.pos.y == agent_y \
+ and agent_x == checkpoint_x and agent_y == checkpoint_y:
+ nextCheckpoint += 1
+ house.trash_can['evaluated_type'] = type_map[snn.getPredict(house.trash_can['type'])[0]]
+ print('House:', house.name, 'pos:', astarPath[pathPos], 'type:', house.trash_can['type'],
+ 'evaluated_type:', house.trash_can['evaluated_type'])
+ tree_input = np.array([
+ house.trash_can['evaluated_type'],
+ season,
+ house.trash_can['animal'],
+ truck_full,
+ house.trash_can['quantity'],
+ house.trash_can['time'],
+ truck_working
+ ]).reshape(1, -1)
+ should_get = decision_tree.predict(tree_input)
+ print('Desicion tree input:', tree_input, 'result:', should_get)
+ pathPos = pathPos + 1 if pathPos < len(astarPath) - 1 else pathPos
c = (255, 255, 255) # tymczasowy kolor tła - do usunięcia, jak już będzie zdjęcie
screen.fill(c)
draw(gridSize, objectArray)
kb_listen(objectArray, gridSize, astarPath)
- pygame.display.update() # by krata pojawiła się w okienku - update powierzc
\ No newline at end of file
+ pygame.display.update() # by krata pojawiła się w okienku - update powierzc
+ pygame.time.wait(100)
+
+
diff --git a/src/snn.py b/src/snn.py
new file mode 100644
index 0000000..6e2dea5
--- /dev/null
+++ b/src/snn.py
@@ -0,0 +1,16 @@
+from fastai.vision.all import *
+import pathlib
+
+temp = pathlib.PosixPath
+pathlib.PosixPath = pathlib.WindowsPath
+
+DATASET_PATH = pathlib.Path('../dataset')
+
+learn = load_learner(DATASET_PATH/'export.pkl')
+path = pathlib.Path(DATASET_PATH / 'others/trash1.jpg')
+
+def getPredict(path):
+ prediction = learn.predict(path)
+ predictionName = learn.predict(path)[0]
+ # print(prediction, '\n\n','prediction:', predictionName, 'path:', path)
+ return prediction
\ No newline at end of file
diff --git a/testset/glass0.jpg b/testset/glass0.jpg
new file mode 100644
index 0000000..d1a48ee
Binary files /dev/null and b/testset/glass0.jpg differ
diff --git a/testset/glass1.jpg b/testset/glass1.jpg
new file mode 100644
index 0000000..e102ab8
Binary files /dev/null and b/testset/glass1.jpg differ
diff --git a/testset/glass2.jpg b/testset/glass2.jpg
new file mode 100644
index 0000000..a4cbd74
Binary files /dev/null and b/testset/glass2.jpg differ
diff --git a/testset/others0.jpg b/testset/others0.jpg
new file mode 100644
index 0000000..d8bc698
Binary files /dev/null and b/testset/others0.jpg differ
diff --git a/testset/others1.jpg b/testset/others1.jpg
new file mode 100644
index 0000000..131345b
Binary files /dev/null and b/testset/others1.jpg differ
diff --git a/testset/others2.jpg b/testset/others2.jpg
new file mode 100644
index 0000000..d78aacf
Binary files /dev/null and b/testset/others2.jpg differ
diff --git a/testset/paper0.jpg b/testset/paper0.jpg
new file mode 100644
index 0000000..2bf663b
Binary files /dev/null and b/testset/paper0.jpg differ
diff --git a/testset/paper1.jpg b/testset/paper1.jpg
new file mode 100644
index 0000000..64d9865
Binary files /dev/null and b/testset/paper1.jpg differ
diff --git a/testset/plastic0.jpg b/testset/plastic0.jpg
new file mode 100644
index 0000000..41ff945
Binary files /dev/null and b/testset/plastic0.jpg differ
diff --git a/testset/plastic1.jpg b/testset/plastic1.jpg
new file mode 100644
index 0000000..9864983
Binary files /dev/null and b/testset/plastic1.jpg differ
diff --git a/testset/plastic2.jpg b/testset/plastic2.jpg
new file mode 100644
index 0000000..1db3d6c
Binary files /dev/null and b/testset/plastic2.jpg differ
diff --git a/tree/decisionTreeClassifier b/tree/decisionTreeClassifier
new file mode 100644
index 0000000..95bd970
Binary files /dev/null and b/tree/decisionTreeClassifier differ
diff --git a/tree/main.py b/tree/main.py
index 62cf72d..71b4cd0 100644
--- a/tree/main.py
+++ b/tree/main.py
@@ -1,5 +1,6 @@
import pandas as pd
from sklearn import tree
+import joblib
df = pd.read_csv('data.csv')
print(df.head())
@@ -19,6 +20,8 @@ print(pred)
print('Jedynki: ', len(df[df['Y'] == 1]))
print('Zera: ', len(df[df['Y'] == 0]))
+joblib.dump(clf, 'decisionTreeClassifier')
+
#Legenda
#czy wywiezc zmieci 1 tak 0 nie