diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6c26ce9..72c409c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,12 +2,12 @@ - + + - - + - regals - isOccupied - print - regal - whee - returnPath 10 regalsik # @@ -154,6 +139,12 @@ cop jakLiczycKoszt jakLiczyc + eve + doW + self + moves + gen + wybierz fitness @@ -178,19 +169,20 @@ - + + + + - + - - - @@ -391,17 +383,16 @@ - - + - + - + @@ -438,10 +429,20 @@ + + file://$PROJECT_DIR$/genetyczny/eee.py + 24 + file://$PROJECT_DIR$/genetyczny/funkcje.py - 145 - + + file://$PROJECT_DIR$/genetyczny/funkcje.py + 40 + @@ -485,13 +486,6 @@ - - - - - - - @@ -500,9 +494,6 @@ - - - @@ -536,13 +527,6 @@ - - - - - - - @@ -570,20 +554,6 @@ - - - - - - - - - - - - - - @@ -591,34 +561,27 @@ - - - - - - - - - - - - - + + - - + + - + - - - - - + + + + + + + + + @@ -629,40 +592,81 @@ - + - - - - - + + - + - - + + + + + + + + + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Mapa/__pycache__/generate.cpython-37.pyc b/Mapa/__pycache__/generate.cpython-37.pyc index b301ded..5fcef5c 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 397b7f2..46f2e55 100644 --- a/Mapa/generate.py +++ b/Mapa/generate.py @@ -173,10 +173,10 @@ class Generate: all[wysokosc-1][szerokosc-3] = 23 all[wysokosc-2][szerokosc-4] = 1 - """ Drugi wyjazd + all[wysokosc-2][2] = 2 all[wysokosc-1][2] = 23 all[wysokosc-2][3] = 1 - """ + return all diff --git a/__pycache__/program.cpython-37.pyc b/__pycache__/program.cpython-37.pyc index 48eff3b..dd8f3c3 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 ce68143..010ee7d 100644 --- a/genetyczny/Data.py +++ b/genetyczny/Data.py @@ -13,6 +13,7 @@ class Data: self.jakLiczycKoszt = None self.best = None self.histZmian = [] + self.doWykresu = [] def genMap(self, mapa): tmpMap =[] diff --git a/genetyczny/__pycache__/Data.cpython-37.pyc b/genetyczny/__pycache__/Data.cpython-37.pyc index 0fce18f..241a7b5 100644 Binary files a/genetyczny/__pycache__/Data.cpython-37.pyc and b/genetyczny/__pycache__/Data.cpython-37.pyc differ diff --git a/genetyczny/__pycache__/eee.cpython-37.pyc b/genetyczny/__pycache__/eee.cpython-37.pyc new file mode 100644 index 0000000..1e7516d Binary files /dev/null and b/genetyczny/__pycache__/eee.cpython-37.pyc differ diff --git a/genetyczny/__pycache__/funkcje.cpython-37.pyc b/genetyczny/__pycache__/funkcje.cpython-37.pyc index 74e2f21..9e69849 100644 Binary files a/genetyczny/__pycache__/funkcje.cpython-37.pyc and b/genetyczny/__pycache__/funkcje.cpython-37.pyc differ diff --git a/genetyczny/eee.py b/genetyczny/eee.py new file mode 100644 index 0000000..481f1eb --- /dev/null +++ b/genetyczny/eee.py @@ -0,0 +1,142 @@ +from genetyczny.funkcje import * +from easygui import * +from genetyczny.Data import Data +import matplotlib.pyplot as plt +import numpy as np +import matplotlib.animation as animation + +def start(data, wheel): + + ileGeneracji = 200 + ileWPopulacji = 16 + fragment = 0.2 + mutacja = 0.05 + unbox = 3 + + + data.kordyWozka = (wheel.ns, wheel.we) + data.jakLiczycKoszt = unbox + + randomPopulation = genRandomPopulation(data, ileWPopulacji) + for i in range(ileGeneracji): + if i == 0: + best2 = dwieNajlepsze(randomPopulation, data) + else: + x = genPopulacje(best2[0], best2[1], ileWPopulacji, fragment, mutacja) + best2 = dwieNajlepsze(x, data) + data.histZmian.append(data.best[1]) + break + #rysujWykres(data, ileGeneracji, 1000, 2000) + + + +def ruszWozek(gen,data, moves, wheel): + regalKordy = gen.kordy + unbox = data.unbox[gen.ktoryUnbox] + star = AStar() + mapForAStar = data.astarMap[:] + mapForAStar[regalKordy[0]][regalKordy[1]] = 0 + path = star.search([wheel.ns, wheel.we], regalKordy, mapForAStar, 1, 1) + cns = wheel.ns + cwe = wheel.we + value = path[cns][cwe] + while True: + if cns > 0 and path[cns - 1][cwe] == (value + 1): + cns = cns - 1 + moves.append(1) + value = value + 1 + continue + if cns < (len(mapForAStar) - 1) and path[cns + 1][cwe] == (value + 1): + cns = cns + 1 + moves.append(2) + value = value + 1 + continue + if cwe > 0 and path[cns][cwe - 1] == (value + 1): + cwe = cwe - 1 + moves.append(3) + value = value + 1 + continue + if cwe < (len(mapForAStar[0]) - 1) and path[cns][cwe + 1] == (value + 1): + cns = cns + 1 + moves.append(4) + value = value + 1 + continue + break + mapForAStar[regalKordy[0]][regalKordy[1]] = 1 + # 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([regalKordy[0], regalKordy[1]], unbox, mapForAStar, 1, 1) + #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 + moves.append(1) + value = value + 1 + continue + if cns < (len(mapForAStar) - 1) and path[cns + 1][cwe] == (value + 1): + cns = cns + 1 + moves.append(2) + value = value + 1 + continue + if cwe > 0 and path[cns][cwe - 1] == (value + 1): + cwe = cwe - 1 + moves.append(3) + value = value + 1 + continue + if cwe < (len(mapForAStar[0]) - 1) and path[cns][cwe + 1] == (value + 1): + cwe = cwe + 1 + moves.append(4) + value = value + 1 + continue + break + +def rysujWykres(data, x, yStart, yEnd): + + plt.axis([0, x,yStart, yEnd]) + + for i in range(0, len(data.doWykresu) - 1): + y = data.doWykresu[i] + x = i + plt.scatter(x, y) + plt.pause(0.0001) + + plt.show() + + +def okno(): + good = True + fieldValues = multenterbox("Wprowadź warunki początkowe", "Start algorytmu genetycznego", ["Ile chrom. w generacji", "Wielkosc dziedziczonego fragmentu (x>0 and x<1)", "Wartosc mutacji (x>0 and x<1)", "Unbox: (0or 1 or 2 or 2)", "Ile generacji"]) + if(fieldValues[0].isnumeric() and (fieldValues[0]!="")): + good = False + elif(good==True): + msgbox("Wartość nie jest liczbą", "Błąd") + good = False + if(fieldValues[1].isnumeric() and (fieldValues[1]!="")): + if((int(fieldValues[1])<=0) and (good==True) and (int(fieldValues[1])>= 1)): + msgbox("Zla wartosc fragmentu") + good = False + elif (good == True): + msgbox("Wartość nie jest liczbą", "Błąd") + good = False + if(fieldValues[2].isnumeric() and (fieldValues[2]!="")): + if((int(fieldValues[1])<=0) and (good==True) and (int(fieldValues[1])>= 1)): + msgbox("Zla wartosc mutacji") + good = False + elif (good == True): + msgbox("Wartość nie jest liczbą", "Błąd") + good = False + if(fieldValues[3].isnumeric() and (fieldValues[3]!="")): + if(((int(fieldValues[3]) != 0) or (int(fieldValues[3]) != 1) or (int(fieldValues[3]) != 2) or (int(fieldValues[3]) != 3)) and (good==True)): + msgbox("Zla wartosc unboxa") + good = False + elif (good == True): + msgbox("Wartość nie jest liczbą", "Błąd") + good = False + if(fieldValues[4].isnumeric() and (fieldValues[4]!="")): + pass + else: + msgbox("Wartość nie jest liczbą", "Błąd") + good = False + if(good == True): + return [fieldValues[0], fieldValues[1], fieldValues[2],fieldValues[3]] diff --git a/genetyczny/funkcje.py b/genetyczny/funkcje.py index bccff64..fd0d297 100644 --- a/genetyczny/funkcje.py +++ b/genetyczny/funkcje.py @@ -150,6 +150,7 @@ def dwieNajlepsze(populacja, data): data.best = (pierwsza[:],bestValue) elif(data.best[1] > bestValue): data.best = (pierwsza[:],bestValue) + data.doWykresu.append(bestValue) tmpPopulacja.pop(bestChromIndex) chromFitness.pop(bestChromIndex) diff --git a/genetyczny/genetyczny.py b/genetyczny/genetyczny.py deleted file mode 100644 index 8b13789..0000000 --- a/genetyczny/genetyczny.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/program.py b/program.py index 92c030c..12859b6 100644 --- a/program.py +++ b/program.py @@ -15,6 +15,7 @@ from neurons import Neurons from whereDecision import WhereDecision from Evencik import Evencik from genetyczny.Data import Data +from genetyczny.eee import * class MainWindow: def __init__(self, szerokosc, wysokosc, kruche, latwopalne, radioaktywne, niebezpieczne): @@ -58,7 +59,7 @@ 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.map, self.regals, 25) + self.map = randomBox(self.map, self.regals, 5) updateMap(self.data, self.map, self.mapForAStar, self.regals) generateGeny(self.data) @@ -81,31 +82,22 @@ class MainWindow: 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.K_p): - print("eee") - """ + elif(event.type==pygame.KEYDOWN): - - self.data.kordyWozka = (self.wheel.ns, self.wheel.we) - self.data.jakLiczycKoszt = 1 - - randomPopulation = genRandomPopulation(self.data, 5) - for i in range(100): - if i == 0: - best2 = dwieNajlepsze(randomPopulation, self.data) - else: - x = genPopulacje(best2[0], best2[1], 5, 0.2, 0.3) - best2 = dwieNajlepsze(x, self.data) - self.data.histZmian.append(self.data.best[1]) - if len(self.moves)==0: + if event.key == pygame.K_g: + start(self.data,self.wheel) + for gen in self.data.best[0]: + ruszWozek(gen,self.data, self.moves, self.wheel) + elif 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"]]))