Upload files to ''
This commit is contained in:
parent
4e18cd852b
commit
668201933e
10
floor.py
Normal file
10
floor.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import pygame
|
||||||
|
|
||||||
|
class Floor:
|
||||||
|
def __init__(self, screen, cell, we, ns):
|
||||||
|
self.cell = cell
|
||||||
|
self.ns = ns
|
||||||
|
self.we = we
|
||||||
|
self.screen = screen
|
||||||
|
def draw(self):
|
||||||
|
pass
|
174
generate.py
Normal file
174
generate.py
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
class Generate:
|
||||||
|
@staticmethod
|
||||||
|
def generate(szerokosc, wysokosc, kruche, latwopalne, radioaktywne, niebezpieczne):
|
||||||
|
# 1 - sciana
|
||||||
|
# 2 - podłoga
|
||||||
|
# 3 - regał od dołu (zwykly)
|
||||||
|
# 4 - regał od gory (zwykly)
|
||||||
|
# 5 - regał od lewej (zwykly)
|
||||||
|
# 6 - regał od prawej (zwykly)
|
||||||
|
# 7 - regał od dołu (kruche)
|
||||||
|
# 8 - regał od gory (kruche)
|
||||||
|
# 9 - regał od lewej (kruche)
|
||||||
|
# 10 - regał od prawej (kruche)
|
||||||
|
# 11 - regał od dołu (latwopalne)
|
||||||
|
# 12 - regał od gory (latwopalne)
|
||||||
|
# 13 - regał od lewej (latwopalne)
|
||||||
|
# 14 - regał od prawej (latwopalne)
|
||||||
|
# 15 - regał od dołu (radioaktywne)
|
||||||
|
# 16 - regał od gory (radioaktywne)
|
||||||
|
# 17 - regał od lewej (radioaktywne)
|
||||||
|
# 18 - regał od prawej (radioaktywne)
|
||||||
|
# 19 - regał od dołu (niebezpieczne)
|
||||||
|
# 20 - regał od gory (niebezpieczne)
|
||||||
|
# 21 - regał od lewej (niebezpieczne)
|
||||||
|
# 22 - regał od prawej (niebezpieczne)
|
||||||
|
# 23 - unboxOnTheFloor
|
||||||
|
all = []
|
||||||
|
tmp = []
|
||||||
|
for i in range(0, wysokosc):
|
||||||
|
for j in range(0, szerokosc):
|
||||||
|
tmp.append(2)
|
||||||
|
all.append(tmp)
|
||||||
|
tmp = []
|
||||||
|
for i in range(0, szerokosc):
|
||||||
|
all[0][i] = 1
|
||||||
|
all[wysokosc-1][i] = 1
|
||||||
|
for i in range(0, wysokosc):
|
||||||
|
all[i][0] = 1
|
||||||
|
all[i][szerokosc-1] = 1
|
||||||
|
if (kruche>0):
|
||||||
|
for i in range(2, szerokosc-2):
|
||||||
|
all[1][i] = 7
|
||||||
|
kruche-=1
|
||||||
|
elif (latwopalne>0):
|
||||||
|
for i in range(2, szerokosc-2):
|
||||||
|
all[1][i] = 11
|
||||||
|
latwopalne-=1
|
||||||
|
elif (radioaktywne>0):
|
||||||
|
for i in range(2, szerokosc-2):
|
||||||
|
all[1][i] = 15
|
||||||
|
radioaktywne-=1
|
||||||
|
elif (niebezpieczne>0):
|
||||||
|
for i in range(2, szerokosc-2):
|
||||||
|
all[1][i] = 19
|
||||||
|
niebezpieczne-=1
|
||||||
|
else:
|
||||||
|
for i in range(2, szerokosc-2):
|
||||||
|
all[1][i] = 3
|
||||||
|
if (kruche>0):
|
||||||
|
for i in range(2, wysokosc-2):
|
||||||
|
all[i][szerokosc-2] = 9
|
||||||
|
kruche-=1
|
||||||
|
elif (latwopalne>0):
|
||||||
|
for i in range(2, wysokosc-2):
|
||||||
|
all[i][szerokosc-2] = 13
|
||||||
|
latwopalne-=1
|
||||||
|
elif (radioaktywne>0):
|
||||||
|
for i in range(2, wysokosc-2):
|
||||||
|
all[i][szerokosc-2] = 17
|
||||||
|
radioaktywne-=1
|
||||||
|
elif (niebezpieczne>0):
|
||||||
|
for i in range(2, wysokosc-2):
|
||||||
|
all[i][szerokosc-2] = 21
|
||||||
|
niebezpieczne-=1
|
||||||
|
else:
|
||||||
|
for i in range(2, wysokosc-2):
|
||||||
|
all[i][szerokosc-2] = 5
|
||||||
|
if (kruche>0):
|
||||||
|
for i in range(2, szerokosc-2):
|
||||||
|
all[wysokosc-2][i] = 8
|
||||||
|
kruche-=1
|
||||||
|
elif (latwopalne>0):
|
||||||
|
for i in range(2, szerokosc-2):
|
||||||
|
all[wysokosc-2][i] = 12
|
||||||
|
latwopalne-=1
|
||||||
|
elif (radioaktywne>0):
|
||||||
|
for i in range(2, szerokosc-2):
|
||||||
|
all[wysokosc-2][i] = 16
|
||||||
|
radioaktywne-=1
|
||||||
|
elif (niebezpieczne>0):
|
||||||
|
for i in range(2, szerokosc-2):
|
||||||
|
all[wysokosc-2][i] = 20
|
||||||
|
niebezpieczne-=1
|
||||||
|
else:
|
||||||
|
for i in range(2, szerokosc-2):
|
||||||
|
all[wysokosc-2][i] = 4
|
||||||
|
if (kruche>0):
|
||||||
|
for i in range(2, wysokosc-2):
|
||||||
|
all[i][1] = 10
|
||||||
|
kruche-=1
|
||||||
|
elif (latwopalne>0):
|
||||||
|
for i in range(2, wysokosc-2):
|
||||||
|
all[i][1] = 14
|
||||||
|
latwopalne-=1
|
||||||
|
elif (radioaktywne>0):
|
||||||
|
for i in range(2, wysokosc-2):
|
||||||
|
all[i][1] = 18
|
||||||
|
radioaktywne-=1
|
||||||
|
elif (niebezpieczne>0):
|
||||||
|
for i in range(2, wysokosc-2):
|
||||||
|
all[i][1] = 22
|
||||||
|
niebezpieczne-=1
|
||||||
|
else:
|
||||||
|
for i in range(2, wysokosc-2):
|
||||||
|
all[i][1] = 6
|
||||||
|
for j in range(3, szerokosc-4, 3):
|
||||||
|
if (kruche > 0):
|
||||||
|
for i in range(3, wysokosc - 3):
|
||||||
|
all[i][j] = 9
|
||||||
|
kruche -= 1
|
||||||
|
elif (latwopalne > 0):
|
||||||
|
for i in range(3, wysokosc - 3):
|
||||||
|
all[i][j] = 13
|
||||||
|
latwopalne -= 1
|
||||||
|
elif (radioaktywne > 0):
|
||||||
|
for i in range(3, wysokosc - 3):
|
||||||
|
all[i][j] = 17
|
||||||
|
radioaktywne -= 1
|
||||||
|
elif (niebezpieczne > 0):
|
||||||
|
for i in range(3, wysokosc - 3):
|
||||||
|
all[i][j] = 21
|
||||||
|
niebezpieczne -= 1
|
||||||
|
else:
|
||||||
|
for i in range(3, wysokosc - 3):
|
||||||
|
all[i][j] = 5
|
||||||
|
if (kruche > 0):
|
||||||
|
for i in range(3, wysokosc - 3):
|
||||||
|
all[i][j+1] = 10
|
||||||
|
kruche -= 1
|
||||||
|
elif (latwopalne > 0):
|
||||||
|
for i in range(3, wysokosc - 3):
|
||||||
|
all[i][j+1] = 14
|
||||||
|
latwopalne -= 1
|
||||||
|
elif (radioaktywne > 0):
|
||||||
|
for i in range(3, wysokosc - 3):
|
||||||
|
all[i][j+1] = 18
|
||||||
|
radioaktywne -= 1
|
||||||
|
elif (niebezpieczne > 0):
|
||||||
|
for i in range(3, wysokosc - 3):
|
||||||
|
all[i][j+1] = 22
|
||||||
|
niebezpieczne -= 1
|
||||||
|
else:
|
||||||
|
for i in range(3, wysokosc - 3):
|
||||||
|
all[i][j+1] = 6
|
||||||
|
counter = 0
|
||||||
|
for i in range(3, szerokosc - 3):
|
||||||
|
counter+=1
|
||||||
|
if counter==3:
|
||||||
|
counter=0
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
all[3][i] = 1
|
||||||
|
all[wysokosc-4][i] = 1
|
||||||
|
all[1][1] = 1
|
||||||
|
all[1][3] = 1
|
||||||
|
all[1][szerokosc-2] = 1
|
||||||
|
all[wysokosc-2][1] = 1
|
||||||
|
all[wysokosc-2][szerokosc-2] = 1
|
||||||
|
all[0][2] = 2
|
||||||
|
all[1][2] = 2
|
||||||
|
all[wysokosc-2][szerokosc-3] = 2
|
||||||
|
all[wysokosc-1][szerokosc-3] = 23
|
||||||
|
all[wysokosc-2][szerokosc-4] = 1
|
||||||
|
return all
|
36
main.py
Normal file
36
main.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from easygui import *
|
||||||
|
from program import MainWindow
|
||||||
|
import os;
|
||||||
|
|
||||||
|
def main():
|
||||||
|
good = False
|
||||||
|
while (True):
|
||||||
|
good = True
|
||||||
|
fieldValues = multenterbox("Wprowadź warunki początkowe", "Start programu", ["Szerekość kraty (>=6)", "Wysokość kraty (>=7)", "Ilość regałów kruchych", "Ilość regałów łatwopalnych", "Ilość regałów radioaktywnych", "Ilość regałów niebezpiecznych"])
|
||||||
|
if(fieldValues[0].isnumeric() and (fieldValues[0]!="")):
|
||||||
|
if(int(fieldValues[0])<=5):
|
||||||
|
msgbox("Szerokość kraty jest zbyt mała, aby można było uruchomić program", "Błąd")
|
||||||
|
good = False
|
||||||
|
elif(good==True):
|
||||||
|
msgbox("Wartość nie jest liczbą", "Błąd")
|
||||||
|
good = False
|
||||||
|
if(fieldValues[1].isnumeric() and (fieldValues[0]!="")):
|
||||||
|
if((int(fieldValues[1])<=6) and (good==True)):
|
||||||
|
msgbox("Wysokość kraty jest zbyt mała, aby można było uruchomić program", "Błąd")
|
||||||
|
good = False
|
||||||
|
elif (good == True):
|
||||||
|
msgbox("Wartość nie jest liczbą", "Błąd")
|
||||||
|
good = False
|
||||||
|
if ((fieldValues[2].isnumeric()) and (fieldValues[3].isnumeric()) and (fieldValues[4].isnumeric()) and (fieldValues[5].isnumeric()) and (fieldValues[2]!="") and (fieldValues[3]!="") and (fieldValues[4]!="") and (fieldValues[5]!="") and (good==True)):
|
||||||
|
sum = int(fieldValues[2])+int(fieldValues[3])+int(fieldValues[4])+int(fieldValues[5])
|
||||||
|
allow = 6+(((int(fieldValues[0])-6)//3)*2)
|
||||||
|
if(sum>allow):
|
||||||
|
msgbox("Magazyn zbyt mały co by pomieścił tyle regałów", "Błąd")
|
||||||
|
good = False
|
||||||
|
elif (good == True):
|
||||||
|
msgbox("Wartość nie jest liczbą", "Błąd")
|
||||||
|
good = False
|
||||||
|
if good:
|
||||||
|
window = MainWindow(int(fieldValues[0]), int(fieldValues[1]), int(fieldValues[2]), int(fieldValues[3]), int(fieldValues[4]), int(fieldValues[5]));
|
||||||
|
break
|
||||||
|
main()
|
44
neurons.py
Normal file
44
neurons.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import numpy
|
||||||
|
import cv2
|
||||||
|
import argparse
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
class Neurons:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
def get_output_layers(self, net):
|
||||||
|
layer_names = net.getLayerNames()
|
||||||
|
output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
|
||||||
|
return output_layers
|
||||||
|
def whatIsIt(self, path):
|
||||||
|
image = cv2.imread(path)
|
||||||
|
scale = 0.00392
|
||||||
|
classes = None
|
||||||
|
with open("yolov3.txt", 'r') as f:
|
||||||
|
classes = [line.strip() for line in f.readlines()]
|
||||||
|
net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg")
|
||||||
|
blob = cv2.dnn.blobFromImage(image, scale, (416, 416), (0, 0, 0), True, crop=False)
|
||||||
|
net.setInput(blob)
|
||||||
|
outs = net.forward(self.get_output_layers(net))
|
||||||
|
class_ids = []
|
||||||
|
for out in outs:
|
||||||
|
for detection in out:
|
||||||
|
scores = detection[5:]
|
||||||
|
class_id = np.argmax(scores)
|
||||||
|
confidence = scores[class_id]
|
||||||
|
if confidence > 0.5:
|
||||||
|
class_ids.append(class_id)
|
||||||
|
print([classes[ids] for ids in class_ids])
|
||||||
|
x = [1, 0, 0, 0, 0]
|
||||||
|
numpy.random.shuffle(x)
|
||||||
|
if x[0]==1:
|
||||||
|
print("Zwykła")
|
||||||
|
elif x[1]==1:
|
||||||
|
print("Kruchy")
|
||||||
|
elif x[2]==1:
|
||||||
|
print("Łatwopalny")
|
||||||
|
elif x[3]==1:
|
||||||
|
print("Radioaktywny")
|
||||||
|
elif x[4]==1:
|
||||||
|
print("Niebezpieczny")
|
||||||
|
return [list(x)]
|
146
program.py
Normal file
146
program.py
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
import pygame
|
||||||
|
from os import sys
|
||||||
|
from generate import Generate
|
||||||
|
from floor import Floor
|
||||||
|
from wall import Wall
|
||||||
|
from shelf import Shelf
|
||||||
|
from wheel import Wheel
|
||||||
|
from boxOnTheFloor import BoxOnTheFloor
|
||||||
|
from box import Box
|
||||||
|
from unboxOnTheFloor import UnboxOnTheFloor
|
||||||
|
from AStar import AStar
|
||||||
|
import numpy
|
||||||
|
import easygui
|
||||||
|
from neurons import Neurons
|
||||||
|
from whereDecision import WhereDecision
|
||||||
|
from Evencik import Evencik
|
||||||
|
|
||||||
|
class MainWindow:
|
||||||
|
def __init__(self, szerokosc, wysokosc, kruche, latwopalne, radioaktywne, niebezpieczne):
|
||||||
|
#config
|
||||||
|
self.cell = 50
|
||||||
|
#init
|
||||||
|
pygame.init()
|
||||||
|
pygame.display.set_caption('Inteligentny wózek widłowy')
|
||||||
|
self.clock = pygame.time.Clock()
|
||||||
|
self.ticks = 0
|
||||||
|
self.moves = []
|
||||||
|
self.regals = []
|
||||||
|
self.map = Generate.generate(szerokosc+2, wysokosc+2, kruche, latwopalne, radioaktywne, niebezpieczne)
|
||||||
|
self.mapForAStar = Generate.generate(szerokosc+2, wysokosc+2, kruche, latwopalne, radioaktywne, niebezpieczne)
|
||||||
|
self.screen = pygame.display.set_mode((((szerokosc+2)*self.cell), ((wysokosc+2)*self.cell)))
|
||||||
|
self.neurons = Neurons()
|
||||||
|
self.whereDecision = WhereDecision()
|
||||||
|
#create
|
||||||
|
self.wheel = Wheel(self.screen, self.cell);
|
||||||
|
for i in range(len(self.map)):
|
||||||
|
for j in range(len(self.map[i])):
|
||||||
|
if (self.map[i][j]==1):
|
||||||
|
self.map[i][j] = Wall(self.screen, self.cell, i, j)
|
||||||
|
self.mapForAStar[i][j] = 1
|
||||||
|
elif (self.map[i][j]==2):
|
||||||
|
self.map[i][j] = Floor(self.screen, self.cell, i, j)
|
||||||
|
self.mapForAStar[i][j] = 0
|
||||||
|
elif (self.map[i][j]==23):
|
||||||
|
self.map[i][j] = UnboxOnTheFloor(self.screen, self.cell, i, j)
|
||||||
|
self.mapForAStar[i][j] = 1
|
||||||
|
else:
|
||||||
|
self.regals.append((i, j, (self.map[i][j]-3)//4))
|
||||||
|
self.map[i][j] = Shelf(self.screen, self.cell, i, j, (self.map[i][j]-3)%4, (self.map[i][j]-3)//4)
|
||||||
|
self.mapForAStar[i][j] = 1
|
||||||
|
#loop
|
||||||
|
while True:
|
||||||
|
self.events()
|
||||||
|
self.draw()
|
||||||
|
self.clock.tick(40)
|
||||||
|
self.ticks+=1
|
||||||
|
if self.ticks>10:
|
||||||
|
self.ticks=0
|
||||||
|
if len(self.moves)>0:
|
||||||
|
if(self.moves[0]==1):
|
||||||
|
self.wheel.move(Evencik(pygame.K_UP), self.map)
|
||||||
|
elif (self.moves[0]==2):
|
||||||
|
self.wheel.move(Evencik(pygame.K_DOWN), self.map)
|
||||||
|
elif (self.moves[0]==3):
|
||||||
|
self.wheel.move(Evencik(pygame.K_LEFT), self.map)
|
||||||
|
elif (self.moves[0]==4):
|
||||||
|
self.wheel.move(Evencik(pygame.K_RIGHT), self.map)
|
||||||
|
self.moves.pop(0)
|
||||||
|
def events(self):
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if(event.type==pygame.QUIT):
|
||||||
|
sys.exit()
|
||||||
|
elif(event.type==pygame.KEYDOWN):
|
||||||
|
if len(self.moves)==0:
|
||||||
|
self.wheel.move(event, self.map)
|
||||||
|
elif(event.type==pygame.MOUSEBUTTONDOWN):
|
||||||
|
if (type(self.map[0][2]) == Floor):
|
||||||
|
whatIsIt = self.neurons.whatIsIt(easygui.fileopenbox("Wybierz zdjęcie paczki", "Wybierz zdjęcie paczki", filetypes = [["*.jpg", "*.jpeg", "*.png", "Pliki graficzne"]]))
|
||||||
|
where = self.whereDecision.recognize(whatIsIt, self.regalsik())
|
||||||
|
self.map[0][2] = BoxOnTheFloor(self.screen, self.cell, 0, 2, Box())
|
||||||
|
star = AStar()
|
||||||
|
path = star.search([self.wheel.ns, self.wheel.we], [0, 2], self.mapForAStar, 1)
|
||||||
|
cns = self.wheel.ns
|
||||||
|
cwe = self.wheel.we
|
||||||
|
value = path[cns][cwe]
|
||||||
|
while True:
|
||||||
|
if cns>0 and path[cns-1][cwe]==(value+1):
|
||||||
|
cns=cns-1
|
||||||
|
self.moves.append(1)
|
||||||
|
value=value+1
|
||||||
|
continue
|
||||||
|
if cns<(len(self.mapForAStar)-1) and path[cns+1][cwe]==(value+1):
|
||||||
|
cns=cns+1
|
||||||
|
self.moves.append(2)
|
||||||
|
value=value+1
|
||||||
|
continue
|
||||||
|
if cwe>0 and path[cns][cwe-1]==(value+1):
|
||||||
|
cwe=cwe-1
|
||||||
|
self.moves.append(3)
|
||||||
|
value=value+1
|
||||||
|
continue
|
||||||
|
if cwe<(len(self.mapForAStar[0])-1) and path[cns][cwe+1]==(value+1):
|
||||||
|
cns=cns+1
|
||||||
|
self.moves.append(4)
|
||||||
|
value=value+1
|
||||||
|
continue
|
||||||
|
break
|
||||||
|
self.mapForAStar[where[0]][where[1]] = 0
|
||||||
|
path = star.search([0, 2], where, self.mapForAStar, 1)
|
||||||
|
self.mapForAStar[where[0]][where[1]] = 1
|
||||||
|
value = path[cns][cwe]
|
||||||
|
while True:
|
||||||
|
if cns>0 and path[cns-1][cwe]==(value+1):
|
||||||
|
cns=cns-1
|
||||||
|
self.moves.append(1)
|
||||||
|
value=value+1
|
||||||
|
continue
|
||||||
|
if cns<(len(self.mapForAStar)-1) and path[cns+1][cwe]==(value+1):
|
||||||
|
cns=cns+1
|
||||||
|
self.moves.append(2)
|
||||||
|
value=value+1
|
||||||
|
continue
|
||||||
|
if cwe>0 and path[cns][cwe-1]==(value+1):
|
||||||
|
cwe=cwe-1
|
||||||
|
self.moves.append(3)
|
||||||
|
value=value+1
|
||||||
|
continue
|
||||||
|
if cwe<(len(self.mapForAStar[0])-1) and path[cns][cwe+1]==(value+1):
|
||||||
|
cwe=cwe+1
|
||||||
|
self.moves.append(4)
|
||||||
|
value=value+1
|
||||||
|
continue
|
||||||
|
break
|
||||||
|
def draw(self):
|
||||||
|
self.screen.fill((33,69,108))
|
||||||
|
for i in range(len(self.map)):
|
||||||
|
for j in range(len(self.map[i])):
|
||||||
|
self.map[i][j].draw()
|
||||||
|
self.wheel.draw()
|
||||||
|
pygame.display.flip()
|
||||||
|
def regalsik(self):
|
||||||
|
tmp = []
|
||||||
|
for regal in self.regals:
|
||||||
|
if self.map[regal[0]][regal[1]].isOccupied()==False:
|
||||||
|
tmp.append(regal)
|
||||||
|
return tmp
|
Loading…
Reference in New Issue
Block a user