diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6d0694e..d69a6f3 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,13 +2,12 @@
-
+
-
-
+
@@ -17,13 +16,16 @@
+
+
+
-
+
-
-
+
+
@@ -31,14 +33,20 @@
-
-
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
@@ -46,8 +54,8 @@
-
-
+
+
@@ -58,8 +66,8 @@
-
-
+
+
@@ -68,19 +76,13 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
@@ -88,8 +90,17 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
@@ -105,7 +116,6 @@
- whereDecisio
toVisit
dra
neuro
@@ -120,15 +130,29 @@
regalsik
#
put
- random
randomB
+ search
+ sear
+ rando
+ chi
+ genera
+ return
+ occupied
+ astarstate
+ grid
+ whereDecision
+ genMa
+ random
+ mapfor
+ tmp
+ global
@@ -143,21 +167,24 @@
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
@@ -320,13 +347,16 @@
+
-
+
+
+
@@ -353,19 +383,19 @@
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
@@ -374,19 +404,19 @@
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
@@ -399,9 +429,9 @@
- file://$PROJECT_DIR$/AStar.py
- 17
-
+ file://$PROJECT_DIR$/program.py
+ 98
+
@@ -417,6 +447,10 @@
+
+
+
+
@@ -469,33 +503,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -512,37 +519,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -550,48 +526,128 @@
-
-
-
-
+
-
-
-
-
-
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AStar.py b/AStar.py
index 169af59..d0ecf9c 100644
--- a/AStar.py
+++ b/AStar.py
@@ -2,7 +2,7 @@ import numpy
from AStarState import AStarState
class AStar:
- def returnPath(self, currentNode, grid, flaga):
+ def returnPath(self, currentNode, grid):
path = []
noRows, noColumns = numpy.shape(grid)
result = [[-1 for i in range(noColumns)] for j in range(noRows)]
@@ -41,10 +41,14 @@ class AStar:
if item.gmax and flaga == 0: #podprojekt genetyczne
+ return current.g
if iterations>max:
return self.returnPath(current, grid)
visited.append(current)
toVisit.pop(currentIndeks)
+ if current==endNode and flaga == 0:
+ return current.g
if current==endNode:
return self.returnPath(current, grid) #zwracanie wagi przejscia
children = []
@@ -56,6 +60,11 @@ class AStar:
positions[1] > (noColumns - 1) or
positions[1] < 0):
continue
+ """ podprojekt genetyczne"""
+ if grid[positions[0]][positions[1]] == 2 and flaga == 0:
+ children.append(AStarState(current, positions))
+ continue
+
if grid[positions[0]][positions[1]]!=0:
continue
@@ -76,3 +85,7 @@ class AStar:
continue
toVisit.append(child)
+
+
+
+
diff --git a/Mapa/__pycache__/generate.cpython-37.pyc b/Mapa/__pycache__/generate.cpython-37.pyc
index 8d190dc..685a68a 100644
Binary files a/Mapa/__pycache__/generate.cpython-37.pyc and b/Mapa/__pycache__/generate.cpython-37.pyc differ
diff --git a/Mapa/generate.py b/Mapa/generate.py
index 3dcfbbc..397b7f2 100644
--- a/Mapa/generate.py
+++ b/Mapa/generate.py
@@ -172,6 +172,7 @@ class Generate:
all[wysokosc-2][szerokosc-3] = 2
all[wysokosc-1][szerokosc-3] = 23
all[wysokosc-2][szerokosc-4] = 1
+
""" Drugi wyjazd
all[wysokosc-2][2] = 2
all[wysokosc-1][2] = 23
diff --git a/__pycache__/AStar.cpython-37.pyc b/__pycache__/AStar.cpython-37.pyc
index 369e1c7..c85f72f 100644
Binary files a/__pycache__/AStar.cpython-37.pyc and b/__pycache__/AStar.cpython-37.pyc differ
diff --git a/__pycache__/program.cpython-37.pyc b/__pycache__/program.cpython-37.pyc
index 94f94bb..49cf25b 100644
Binary files a/__pycache__/program.cpython-37.pyc and b/__pycache__/program.cpython-37.pyc differ
diff --git a/genetyczny/Data.py b/genetyczny/Data.py
index 9c450dc..2281ecc 100644
--- a/genetyczny/Data.py
+++ b/genetyczny/Data.py
@@ -4,5 +4,15 @@
class Data:
def __init__(self):
- self.zajeteRegaly = []
+ self.zajeteRegaly = [] #krotka (x,y)
+ self.mapa = []
+ self.unbox = []
+ self.astarMap = []
+
+ def genMap(self, mapa):
+ tmpMap =[]
+ tmpMap = mapa.copy()
+ for regal in self.zajeteRegaly:
+ tmpMap[regal[0]][regal[1]] = 2
+ return tmpMap
diff --git a/genetyczny/Gene.py b/genetyczny/Gene.py
new file mode 100644
index 0000000..075688e
--- /dev/null
+++ b/genetyczny/Gene.py
@@ -0,0 +1,8 @@
+
+
+class Gene:
+ def __init__(self, poczatkowa, koncowa, name):
+ self.poczatkowa = poczatkowa
+ self.koncowa = koncowa
+ self.koszt = 0
+ self.name = name
diff --git a/genetyczny/__pycache__/Data.cpython-37.pyc b/genetyczny/__pycache__/Data.cpython-37.pyc
index 571bb41..f2082c6 100644
Binary files a/genetyczny/__pycache__/Data.cpython-37.pyc and b/genetyczny/__pycache__/Data.cpython-37.pyc differ
diff --git a/genetyczny/__pycache__/funkcje.cpython-37.pyc b/genetyczny/__pycache__/funkcje.cpython-37.pyc
new file mode 100644
index 0000000..0efff03
Binary files /dev/null and b/genetyczny/__pycache__/funkcje.cpython-37.pyc differ
diff --git a/genetyczny/__pycache__/randomBox.cpython-37.pyc b/genetyczny/__pycache__/randomBox.cpython-37.pyc
deleted file mode 100644
index 21e8d17..0000000
Binary files a/genetyczny/__pycache__/randomBox.cpython-37.pyc and /dev/null differ
diff --git a/genetyczny/funkcje.py b/genetyczny/funkcje.py
new file mode 100644
index 0000000..e860f53
--- /dev/null
+++ b/genetyczny/funkcje.py
@@ -0,0 +1,86 @@
+from Mapa.unboxOnTheFloor import UnboxOnTheFloor
+from genetyczny.Gene import Gene
+from Mapa.box import Box
+from AStar import AStar
+import random
+
+
+def znajdzUnbox(data,mapa):
+ unboxy = []
+ iterator = 0
+ ostatniWiersz = len(mapa) -1
+ for x in mapa[ostatniWiersz]:
+ if (isinstance(x, UnboxOnTheFloor)):
+ unboxy.append((ostatniWiersz, iterator))
+ iterator += 1
+
+ data.unbox = unboxy
+def wybierzUnbox(data):
+ return random.choice(data.unbox)
+
+
+def policzCost(mapaBoxy, poczatek, koniec):
+ astar = AStar()
+ koszt = astar.search(poczatek, koniec, mapaBoxy, 1, 0)
+ return koszt
+
+def generateChromosome(data, mapaBoxy, wheelxy):
+ chromosome = []
+ regaly = data.zajeteRegaly
+ random.shuffle(regaly)
+
+
+ for r in regaly:
+ gen0 = Gene(wheelxy,r,"poczatek-regal")
+ gen0.koszt = policzCost(mapaBoxy, wheelxy, r)
+ chromosome.append(gen0)
+
+ unbox = wybierzUnbox(data)
+ gen1 = Gene(r,unbox,"regal-unbox")
+ gen1.koszt = policzCost(mapaBoxy, r, unbox)
+ chromosome.append(gen1)
+
+ return chromosome
+
+def generatePopulation(data, mapaBoxy, wheelxy, ileWPopulacji):
+ populacja = []
+ for i in range(ileWPopulacji):
+ populacja.append(generateChromosome(data, mapaBoxy, wheelxy))
+
+ return populacja
+
+def randomBox(mapa, regals, ile):
+
+ regals = regals
+ mapa = mapa
+ tupleList = []
+ ileRegalow = len(regals)
+ iteration = 0
+
+ while iteration < ileRegalow and iteration < ile:
+ regal = random.choice(regals)
+ if regal in tupleList:
+ continue
+ else:
+ tupleList.append(regal)
+ iteration+=1
+
+ for (i,j,x) in tupleList:
+ box = Box()
+ mapa[i][j].put(box)
+ """
+ for t in tupleList:
+ listaRegalow.append((t[0],t[1]))
+ data.zajeteRegaly = listaRegalow
+ """
+ return mapa
+
+def znajdzBox(mapa, regals):
+ zajeteRegaly = []
+
+ for (x,y,z) in regals:
+ shelf = mapa[x][y]
+ tmp = shelf.occupied
+ if(tmp == True):
+ zajeteRegaly.append((x,y))
+ return zajeteRegaly
diff --git a/genetyczny/randomBox.py b/genetyczny/randomBox.py
deleted file mode 100644
index c281046..0000000
--- a/genetyczny/randomBox.py
+++ /dev/null
@@ -1,26 +0,0 @@
-from Mapa.shelf import Shelf
-from wheel import Wheel
-from Mapa.box import Box
-import random
-
-def randomBox(data, mapa_, regals_, ile):
-
- regals = regals_
- mapa = mapa_
- tupleList = []
- ileRegalow = len(regals)
- iteration = 0
- while iteration < ileRegalow and iteration < ile:
- regal = random.choice(regals)
- if regal in tupleList:
- continue
- else:
- tupleList.append(regal)
- iteration+=1
-
- for (i,j,x) in tupleList:
- box = Box()
- mapa[i][j].put(box)
- data.zajeteRegaly = tupleList
-
- return mapa
diff --git a/program.py b/program.py
index be8a90d..8008cd5 100644
--- a/program.py
+++ b/program.py
@@ -4,7 +4,7 @@ from Mapa.generate import Generate
from Mapa.floor import Floor
from Mapa.wall import Wall
from Mapa.shelf import Shelf
-from genetyczny.randomBox import *
+from genetyczny.funkcje import *
from wheel import Wheel
from Mapa.boxOnTheFloor import BoxOnTheFloor
from Mapa.box import Box
@@ -25,6 +25,7 @@ class MainWindow:
pygame.display.set_caption('Inteligentny wózek widłowy')
self.clock = pygame.time.Clock()
self.ticks = 0
+ self.data = Data()
self.moves = []
self.regals = []
self.map = Generate.generate(szerokosc+2, wysokosc+2, kruche, latwopalne, radioaktywne, niebezpieczne)
@@ -35,7 +36,7 @@ class MainWindow:
#create
self.wheel = Wheel(self.screen, self.cell)
###
- self.data = Data()
+
#przekladanie wartosci liczbowych z tablicy na mapę obiektow
@@ -49,7 +50,7 @@ class MainWindow:
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
+ self.mapForAStar[i][j] = 0
else:
#regals (kordy i,j oraz rodzaj regału)
@@ -57,7 +58,14 @@ class MainWindow:
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
- self.map = randomBox(self.data, self.map, self.regals, 10)
+ self.map = randomBox(self.map, self.regals, 10)
+ self.data.mapa = self.map
+ znajdzUnbox(self.data,self.map)
+ self.data.zajeteRegaly = znajdzBox(self.map, self.regals)
+ tmp = self.mapForAStar[:]
+ self.data.astarMap = self.data.genMap(tmp)
+
+
#################################################
#loop
while True:
@@ -82,7 +90,12 @@ class MainWindow:
for event in pygame.event.get():
if(event.type==pygame.QUIT):
sys.exit()
+ """
+ elif(event.type == pygame.K_p):
+ print("eee")
+ """
elif(event.type==pygame.KEYDOWN):
+ populacja = generatePopulation(self.data, self.data.astarMap, [self.wheel.ns, self.wheel.we], 100)
if len(self.moves)==0:
self.wheel.move(event, self.map)
elif(event.type==pygame.MOUSEBUTTONDOWN):
@@ -92,7 +105,7 @@ class MainWindow:
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)
+ path = star.search([self.wheel.ns, self.wheel.we], [0, 2], self.mapForAStar, 1, 1)
cns = self.wheel.ns
cwe = self.wheel.we
value = path[cns][cwe]
@@ -121,7 +134,7 @@ class MainWindow:
self.mapForAStar[where[0]][where[1]] = 0
# wyszukiwanie ścieżki z miejsca podjęcia paczki do regału
# zmienna path posiada macierz oraz kroki podjęte przez wózek
- path = star.search([0, 2], where, self.mapForAStar, 1)
+ path = star.search([0, 2], where, self.mapForAStar, 1, 1)
self.mapForAStar[where[0]][where[1]] = 1
value = path[cns][cwe]
while True:
@@ -146,6 +159,7 @@ class MainWindow:
value=value+1
continue
break
+ self.data.zajeteRegaly = znajdzBox(self.map, self.regals)
def draw(self):
self.screen.fill((33,69,108))
for i in range(len(self.map)):