changes in common part
This commit is contained in:
parent
76ec19cde0
commit
2e672e9a6a
66
Main.py
66
Main.py
@ -9,8 +9,8 @@ from models.Garbagetruck import GarbageTruck
|
||||
import numbering
|
||||
from sklearn.datasets import load_digits
|
||||
import garbageDumpSorting as gds
|
||||
import time
|
||||
from models.garbageDump import Dump
|
||||
import sys
|
||||
|
||||
#heuristics for finding the closest dumpster
|
||||
def closest(GT, D):
|
||||
@ -19,29 +19,26 @@ def closest(GT, D):
|
||||
return sorted_list[0][1:]
|
||||
|
||||
|
||||
def display(grid, GT, a):
|
||||
def display(grid, GT, a, lena, dump):
|
||||
#find closest dumpster and the path
|
||||
ZZ = closest(list(GT.coor), a)
|
||||
b = alg.aStar(grid, tuple(GT.coor), tuple(ZZ))
|
||||
|
||||
# go through the route to the closest dumpster
|
||||
for i in b:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
done = True
|
||||
GT.turn(i)
|
||||
GT.move()
|
||||
|
||||
# "Speed" of the Garbage Truck
|
||||
clock.tick(4)
|
||||
clock.tick(20)
|
||||
|
||||
grid=drawGrid(grid, 20, lena, dump)
|
||||
|
||||
grid=drawGrid(grid, 20)
|
||||
screen.blit(GT.picture, ((WIDTH) * GT.coor[0], (HEIGHT) *GT.coor[1]))
|
||||
pygame.display.flip()
|
||||
return ZZ
|
||||
|
||||
|
||||
|
||||
#creating dumpsters
|
||||
def createDumpstersAndDump(size,number):
|
||||
points=[]
|
||||
@ -53,7 +50,7 @@ def createDumpstersAndDump(size,number):
|
||||
return (wol)
|
||||
|
||||
|
||||
def drawGrid(grid, size):
|
||||
def drawGrid(grid, size, a, dump):
|
||||
for row in range(size):
|
||||
for column in range(size):
|
||||
#colouring dumpsters
|
||||
@ -76,14 +73,36 @@ def drawGrid(grid, size):
|
||||
elif row == dump.coor[:,0] and column == dump.coor[:,1]:
|
||||
grid[row][column] = 0
|
||||
img = recycImg
|
||||
|
||||
screen.blit(img, ((WIDTH) * row, (HEIGHT) * column))
|
||||
|
||||
if a != 0:
|
||||
texts = [" In garbage truck: ", "- Plastic: %s "%(GT.plastic), "- Paper: %s "%(GT.paper), "- Glass: %s "%(GT.glass), "- Cardboard: %s "%(GT.cardboard), "- Metal: %s "%(GT.metal)]
|
||||
else:
|
||||
texts = ["In garbage dump: ", "- Plastic: %s "%(dump.plastic), "- Paper: %s "%(dump.paper), "- Glass: %s "%(dump.glass), "- Cardboard: %s "%(dump.cardboard), "- Metal: %s "%(dump.metal)]
|
||||
|
||||
y=350
|
||||
|
||||
for i in range(0,7):
|
||||
if i == 6:
|
||||
tex = font.render(" Dumpsters left: %s "%a, True, green, blue)
|
||||
y+=100
|
||||
else:
|
||||
tex = font.render(texts[i], True, green, blue)
|
||||
|
||||
textRec = tex.get_rect()
|
||||
textRec.center = (800, y)
|
||||
y+=30
|
||||
screen.blit(tex, textRec)
|
||||
return grid
|
||||
|
||||
|
||||
|
||||
# 700:20=35
|
||||
WIDTH = 35
|
||||
HEIGHT = 35
|
||||
|
||||
|
||||
# Creation of a two dimensional grid
|
||||
grid = []
|
||||
for row in range(20):
|
||||
@ -107,7 +126,6 @@ gds.createSets()
|
||||
# gds.processTrainData()
|
||||
# gds.processTestData()
|
||||
clf = gds.trainAndTest()
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
|
||||
@ -148,7 +166,17 @@ pygame.init()
|
||||
winsize=700
|
||||
WINDOW_SIZE = [winsize, winsize]
|
||||
screen = pygame.display.set_mode(WINDOW_SIZE)
|
||||
WINDOW_SIZE1 = [900, 700]
|
||||
screen2 = pygame.display.set_mode(WINDOW_SIZE1)
|
||||
|
||||
green = (0, 255, 0)
|
||||
blue = (0, 0, 0)
|
||||
font = pygame.font.SysFont('calibri', 20)
|
||||
|
||||
pygame.display.set_caption("Intelligent Garbage Truck")
|
||||
background = pygame.Surface(screen2.get_size()) # Create empty pygame surface
|
||||
background.fill((0,0,0)) # Fill the background white color (red,green,blue)
|
||||
background = background.convert()
|
||||
|
||||
# Loop until user clicks close
|
||||
done = False
|
||||
@ -169,13 +197,13 @@ all = a
|
||||
while not done:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
done = True
|
||||
pygame.display.quit(), sys.exit()
|
||||
|
||||
# Draw the grid
|
||||
grid=drawGrid(grid, 20)
|
||||
grid=drawGrid(grid, 20, len(a), dump)
|
||||
|
||||
#move and display
|
||||
ZZ = display(grid, GT, a)
|
||||
ZZ = display(grid, GT, a, len(a), dump)
|
||||
|
||||
|
||||
for x in all:
|
||||
@ -197,13 +225,12 @@ while not done:
|
||||
|
||||
# remove visited dumpster
|
||||
a = a[~((a[:,0] ==ZZ[0]) & (a[:,1] ==ZZ[1]))]
|
||||
print("Dumpsters left: ",len(a))
|
||||
#print("Dumpsters left: ",len(a))
|
||||
|
||||
# visit Garbage Dump at the end
|
||||
if len(a) == 0:
|
||||
print("Going to the Garbage Dump")
|
||||
display(grid, GT, dump.coor)
|
||||
done = True
|
||||
display(grid, GT, dump.coor, len(a), dump)
|
||||
print("Checking garbage inside the truck: ")
|
||||
gds.sortDump(GT.plastic, GT.paper, GT.metal, GT.cardboard, GT.glass, clf, GT, dump)
|
||||
print("Garbage sorted: ")
|
||||
@ -212,7 +239,10 @@ while not done:
|
||||
print("Metal: " + str(dump.metal))
|
||||
print("Plastic: " + str(dump.plastic))
|
||||
print("Glass: " + str(dump.glass))
|
||||
done = True
|
||||
|
||||
|
||||
|
||||
drawGrid(grid, 20, len(a), dump)
|
||||
screen.blit(GT.picture, ((WIDTH) * GT.coor[0], (HEIGHT) *GT.coor[1]))
|
||||
pygame.display.flip()
|
||||
time.sleep(6)
|
||||
pygame.quit()
|
||||
|
Loading…
Reference in New Issue
Block a user