Compare commits

..

2 Commits

Author SHA1 Message Date
83d0918595 obiekty+kolizja 2022-03-24 22:53:16 +01:00
95a3ac8755 Wyświetlanie domów i wysypiska 2022-03-20 22:33:20 +01:00
1741 changed files with 38 additions and 760 deletions

View File

@ -1,47 +1,10 @@
from pathlib import Path
import numpy as np
import astar
import sys
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],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 3, 3, 8, 5, 4],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 9, 5, 2],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 12, 4, 5, 6],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 7, 3, 4, 5, 7],
[5, 2, 1, 4, 5, 2, 7, 8, 1, 4, 17, 14, 4, 5, 1],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 14, 3],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 14, 2],
[5, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 14, 6],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 13, 14, 15, 7],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 14, 4, 14, 1],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 15, 2],
[1, 2, 1, 4, 5, 2, 7, 8, 1, 4, 1, 3, 4, 15, 2])
class Position:
def __init__(self, x, y):
@ -83,12 +46,23 @@ class Agent(Object):
circleX = 52 + self.pos.x * square
circleY = 12 + self.pos.y * square
truck = pygame.image.load("../car.png").convert_alpha() # tu ścieżka do zdjęcia w tle
truck = pygame.image.load("car.png").convert_alpha() # tu ścieżka do zdjęcia w tle
truck = pygame.transform.scale(truck, (square, square))
screen.blit(truck, (circleX, circleY))
def move(self, newPos):
self.pos = newPos
def move(self, event, gridLength):
if event.key == pygame.K_LEFT:
newPos = self.pos.get_moved(-1, 0)
self.move_if_possible(newPos, gridLength)
if event.key == pygame.K_RIGHT:
newPos = self.pos.get_moved(1, 0)
self.move_if_possible(newPos, gridLength)
if event.key == pygame.K_UP:
newPos = self.pos.get_moved(0, -1)
self.move_if_possible(newPos, gridLength)
if event.key == pygame.K_DOWN:
newPos = self.pos.get_moved(0, 1)
self.move_if_possible(newPos, gridLength)
def move_if_possible(self, newPos, gridLength):
if movement_allowed(newPos, gridLength):
@ -96,20 +70,20 @@ class Agent(Object):
class House(Object):
def __init__(self, name, pos, **kwargs):
def __init__(self, name, pos):
super().__init__(name, pos)
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))
self.trash_cans = {
"paper": False,
"glass": False,
"plastic": False,
"bio": False
}
def draw(self, square):
x = 52 + self.pos.x * square
y = 12 + self.pos.y * square
house = pygame.image.load("../house.png").convert_alpha() # tu ścieżka do zdjęcia w tle
house = pygame.image.load("house.png").convert_alpha() # tu ścieżka do zdjęcia w tle
house = pygame.transform.scale(house, (square, square))
screen.blit(house, (x, y))
@ -121,14 +95,14 @@ class Junkyard(Object):
"paper": True,
"glass": True,
"plastic": True,
"others": True
"bio": True
}
def draw(self, square):
x = 52 + self.pos.x * square
y = 12 + self.pos.y * square
junkyard = pygame.image.load("../junkyard.png").convert_alpha() # tu ścieżka do zdjęcia w tle
junkyard = pygame.image.load("junkyard.png").convert_alpha() # tu ścieżka do zdjęcia w tle
junkyard = pygame.transform.scale(junkyard, (square, square))
screen.blit(junkyard, (x, y))
@ -141,7 +115,7 @@ class Hole(Object):
x = 52 + self.pos.x * square
y = 12 + self.pos.y * square
hole = pygame.image.load("../hole.png").convert_alpha() # tu ścieżka do zdjęcia w tle
hole = pygame.image.load("hole.png").convert_alpha() # tu ścieżka do zdjęcia w tle
hole = pygame.transform.scale(hole, (square, square))
screen.blit(hole, (x, y))
@ -172,9 +146,14 @@ def draw(square_num, objectArr):
(a + grid_size, b + grid_size), 2)
def kb_listen(objectArray, gridLength, path):
def kb_listen(objectArray, gridLength):
agent = objectArray[0]
#agent.move(gridLength, path)
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
agent.move(event, gridLength)
if event.type == pygame.QUIT:
sys.exit()
if __name__ == '__main__':
pygame.init() # inicjalizacja modułów, na razie niepotrzebna
@ -184,11 +163,10 @@ if __name__ == '__main__':
agent = Agent("smieciarka", Position(0, 0))
junkyard = Junkyard("wysypisko", Position(10, 10))
houses = [House(f'dom-{i}', pos) for i, pos in enumerate([Position(x, y) for x, y in [
(7, 4), (3, 10), (8, 10), (4, 5), (1, 2), (10, 4), (13, 14), (6, 9)
(7, 4), (3, 10), (8, 10), (4, 5), (1, 2), (10, 4), (14, 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), (0, 1), (1, 1), (2, 1), (14, 13),
(13, 13), (4, 8), (5, 9), (7, 9), (6, 8), (3, 5), (4, 6), (5, 5)
(4, 9), (5, 11), (11, 7), (13, 8)
]])]
objectArray.append(agent)
objectArray.append(junkyard)
@ -196,60 +174,16 @@ if __name__ == '__main__':
objectArray += holes
collisionsMap = [[False] * gridSize for _ in range(gridSize)]
for object in holes:
for object in objectArray[1:]:
collisionsMap[object.pos.x][object.pos.y] = True
width = 610
height = 530
screen = pygame.display.set_mode((width, height)) # ustalanie rozmiarów okna
startPos = (0, 0)
finalPos = (14, 14)
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
while 1:
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
pygame.time.wait(100)
kb_listen(objectArray, gridSize)
pygame.display.update() # by krata pojawiła się w okienku - update powierzchni

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

Some files were not shown because too many files have changed in this diff Show More