działczy

This commit is contained in:
Tomasz Adamczyk 2021-06-18 12:07:34 +02:00
parent 007304c2ac
commit ef93291011
86 changed files with 86 additions and 121 deletions

View File

@ -4,8 +4,9 @@
<list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment=""> <list default="true" id="56453584-72bd-49f4-a39c-fccf91ab20c6" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/definitions.py" beforeDir="false" afterPath="$PROJECT_DIR$/definitions.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/definitions.py" beforeDir="false" afterPath="$PROJECT_DIR$/definitions.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/geneticalgorithm.py" beforeDir="false" afterPath="$PROJECT_DIR$/geneticalgorithm.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/plant.py" beforeDir="false" afterPath="$PROJECT_DIR$/plant.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/plant.py" beforeDir="false" afterPath="$PROJECT_DIR$/plant.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/py.py" beforeDir="false" afterPath="$PROJECT_DIR$/py.py" afterDir="false" /> <change beforePath="$PROJECT_DIR$/resources/genetic_algorithm/optimal.pkl" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_01.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_01.png" afterDir="false" /> <change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_01.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_01.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_02.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_02.png" afterDir="false" /> <change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_02.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_02.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_03.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_03.png" afterDir="false" /> <change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_03.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_01_03.png" afterDir="false" />
@ -81,6 +82,7 @@
<change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_08.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_08.png" afterDir="false" /> <change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_08.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_08.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_09.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_09.png" afterDir="false" /> <change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_09.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_09.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_10.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_10.png" afterDir="false" /> <change beforePath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_10.png" beforeDir="false" afterPath="$PROJECT_DIR$/resources/neural_network/tiles/tile_09_10.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/station.py" beforeDir="false" afterPath="$PROJECT_DIR$/station.py" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -257,6 +259,9 @@
<workItem from="1623575428375" duration="4887000" /> <workItem from="1623575428375" duration="4887000" />
<workItem from="1623582818543" duration="8926000" /> <workItem from="1623582818543" duration="8926000" />
<workItem from="1623594481441" duration="3000" /> <workItem from="1623594481441" duration="3000" />
<workItem from="1623946067787" duration="1589000" />
<workItem from="1624000494335" duration="2720000" />
<workItem from="1624004901146" duration="4577000" />
</task> </task>
<servers /> <servers />
</component> </component>
@ -273,30 +278,30 @@
</state> </state>
<state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623590970552" /> <state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623590970552" />
<state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1080@0.0.1920.1080" timestamp="1621109431051" /> <state x="628" y="343" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1080@0.0.1920.1080" timestamp="1621109431051" />
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1623591065954"> <state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1623946080134">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623591065954" /> <state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623946080134" />
<state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1621429221570" /> <state x="690" y="287" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1621429221570" />
<state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1623594478725"> <state width="1879" height="295" key="GridCell.Tab.0.bottom" timestamp="1624009514436">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623594478725" /> <state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1624009514436" />
<state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" /> <state width="1879" height="295" key="GridCell.Tab.0.bottom/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" />
<state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1623594478725"> <state width="1879" height="295" key="GridCell.Tab.0.center" timestamp="1624009514436">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623594478725" /> <state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1624009514436" />
<state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" /> <state width="1879" height="295" key="GridCell.Tab.0.center/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" />
<state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1623594478725"> <state width="1879" height="295" key="GridCell.Tab.0.left" timestamp="1624009514435">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623594478725" /> <state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1624009514435" />
<state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389326" /> <state width="1879" height="295" key="GridCell.Tab.0.left/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389326" />
<state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1623594478725"> <state width="1879" height="295" key="GridCell.Tab.0.right" timestamp="1624009514436">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623594478725" /> <state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1624009514436" />
<state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" /> <state width="1879" height="295" key="GridCell.Tab.0.right/0.0.1920.1080@0.0.1920.1080" timestamp="1621429389327" />
<state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1622903620068"> <state width="1879" height="364" key="GridCell.Tab.1.bottom" timestamp="1622903620068">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
@ -318,19 +323,19 @@
</state> </state>
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622903620068" /> <state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622903620068" />
<state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" /> <state width="1879" height="364" key="GridCell.Tab.1.right/0.0.1920.1080@0.0.1920.1080" timestamp="1619289752045" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1623582818117"> <state x="0" y="0" key="com.intellij.ide.util.TipDialog" timestamp="1624004901010">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623582818117" /> <state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1624004901010" />
<state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1621439087317" /> <state x="0" y="0" key="com.intellij.ide.util.TipDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1621439087317" />
<state x="615" y="209" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser" timestamp="1623589256933"> <state x="615" y="209" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser" timestamp="1623589256933">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="615" y="209" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623589256933" /> <state x="615" y="209" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1623589256933" />
<state x="623" y="235" width="672" height="678" key="search.everywhere.popup" timestamp="1622900746217"> <state x="623" y="235" width="672" height="678" key="search.everywhere.popup" timestamp="1624001082063">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="623" y="235" width="672" height="678" key="search.everywhere.popup/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1622900746217" /> <state x="623" y="235" width="672" height="678" key="search.everywhere.popup/0.0.1920.1080/-1920.0.1920.1080@0.0.1920.1080" timestamp="1624001082063" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
@ -347,6 +352,6 @@
<SUITE FILE_PATH="coverage/SmartCart$copy.coverage" NAME="copy Coverage Results" MODIFIED="1622503170538" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" /> <SUITE FILE_PATH="coverage/SmartCart$copy.coverage" NAME="copy Coverage Results" MODIFIED="1622503170538" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/SmartCart$glue.coverage" NAME="glue Coverage Results" MODIFIED="1622501306368" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" /> <SUITE FILE_PATH="coverage/SmartCart$glue.coverage" NAME="glue Coverage Results" MODIFIED="1622501306368" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1622469837941" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" /> <SUITE FILE_PATH="coverage/SmartTractor$py.coverage" NAME="py Coverage Results" MODIFIED="1622469837941" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/SmartCart$py.coverage" NAME="py Coverage Results" MODIFIED="1623592389826" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" /> <SUITE FILE_PATH="coverage/SmartCart$py.coverage" NAME="py Coverage Results" MODIFIED="1624009365702" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component> </component>
</project> </project>

Binary file not shown.

Binary file not shown.

View File

@ -65,7 +65,13 @@ FLOWER_DANDELION_MAXIMUM_STATE = 1
FONT_COLOR = (255, 255, 255) FONT_COLOR = (255, 255, 255)
FONT_SIZE = 23 FONT_SIZE = 23
FONT = pygame.font.Font(os.path.join('resources/font', 'Minecraft.ttf'), FONT_SIZE) FONT = pygame.font.Font(os.path.join('resources/font', 'Minecraft.ttf'), FONT_SIZE)
FPS = 10 FPS = 1
GENETIC_ALGORITHM_COSTS_AMOUNT = 13
GENETIC_ALGORITHM_NUMBER_OF_BEST_INDIVIDUALS = 4
GENETIC_ALGORITHM_NUMBER_OF_CART_MOVES = 1000
GENETIC_ALGORITHM_NUMBER_OF_GENERATIONS = 10
GENETIC_ALGORITHM_NUMBER_OF_INDIVIDUALS = 10
GENETIC_ALGORITHM_NUMBER_OF_INDIVIDUALS_ZERO = 10
HEIGHT_AMOUNT, WIDTH_AMOUNT = 10, 10 HEIGHT_AMOUNT, WIDTH_AMOUNT = 10, 10
HEIGHT_MAP, WIDTH_MAP = BLOCK_SIZE * HEIGHT_AMOUNT, BLOCK_SIZE * WIDTH_AMOUNT HEIGHT_MAP, WIDTH_MAP = BLOCK_SIZE * HEIGHT_AMOUNT, BLOCK_SIZE * WIDTH_AMOUNT
HEIGHT, WIDTH = HEIGHT_MAP + BLOCK_SIZE, WIDTH_MAP HEIGHT, WIDTH = HEIGHT_MAP + BLOCK_SIZE, WIDTH_MAP

View File

@ -11,8 +11,9 @@ import random
import station import station
import treelearn import treelearn
def create_genetic_algorithm(): def create_genetic_algorithm():
if os.path.exists("resources/genetic_algorithm/optimal.pkl"): #jeżeli drzewo jest zapisane w pliku to odczytaj if os.path.exists("resources/genetic_algorithm/optimalastar.pkl"): #jeżeli algorytm genetyczny utworzył plik wcześcniej to odczytaj
astar_costs = pickle.load(open(os.path.join('resources/genetic_algorithm', "optimal.pkl"), "rb")) astar_costs = pickle.load(open(os.path.join('resources/genetic_algorithm', "optimalastar.pkl"), "rb"))
#kolejność alfabetyczna
definitions.BEETROOTS_ADULT_COST = astar_costs[0] definitions.BEETROOTS_ADULT_COST = astar_costs[0]
definitions.BEETROOTS_GROW_COST = astar_costs[1] definitions.BEETROOTS_GROW_COST = astar_costs[1]
definitions.CARROTS_ADULT_COST = astar_costs[2] definitions.CARROTS_ADULT_COST = astar_costs[2]
@ -26,20 +27,58 @@ def create_genetic_algorithm():
definitions.STATION_COST = astar_costs[10] definitions.STATION_COST = astar_costs[10]
definitions.WHEAT_ADULT_COST = astar_costs[11] definitions.WHEAT_ADULT_COST = astar_costs[11]
definitions.WHEAT_GROW_COST = astar_costs[12] definitions.WHEAT_GROW_COST = astar_costs[12]
print(definitions.BEETROOTS_ADULT_COST) else: #w przeciwnym razie ucz algorytmem genetycznym
print(definitions.BEETROOTS_GROW_COST) astar_costs = [definitions.BEETROOTS_ADULT_COST, definitions.BEETROOTS_GROW_COST, definitions.CARROTS_ADULT_COST, definitions.CARROTS_GROW_COST, definitions.DIRT_COST, definitions.FARMLAND_DRY_COST, definitions.FARMLAND_WET_COST, definitions.FLOWER_DANDELION_COST, definitions.POTATOES_ADULT_COST, definitions.POTATOES_GROW_COST, definitions.STATION_COST, definitions.WHEAT_ADULT_COST, definitions.WHEAT_GROW_COST] #kolejność alfabetyczna
else: astar_costs = evolve(astar_costs)
astar_costs = [definitions.BEETROOTS_ADULT_COST, definitions.BEETROOTS_GROW_COST, definitions.CARROTS_ADULT_COST, definitions.CARROTS_GROW_COST, definitions.DIRT_COST, definitions.FARMLAND_DRY_COST, definitions.FARMLAND_WET_COST, definitions.FLOWER_DANDELION_COST, definitions.POTATOES_ADULT_COST, definitions.POTATOES_GROW_COST, definitions.STATION_COST, definitions.WHEAT_ADULT_COST, definitions.WHEAT_GROW_COST] pickle.dump(astar_costs, open(os.path.join('resources/genetic_algorithm', "optimalastar.pkl"), "wb"))
astar_costs = make_generations(astar_costs) def evolve(astar_costs):
pickle.dump(astar_costs, open(os.path.join('resources/genetic_algorithm', "optimal.pkl"), "wb")) first_generation = [] #pierwsza generacja
overall_solutions = [] #rozwiązania końcowe
def fitness(astar_costs): solutions = [] #rozwiązania danej generacji
ans = solution(astar_costs) for individual in range(definitions.GENETIC_ALGORITHM_NUMBER_OF_INDIVIDUALS_ZERO): #liczba osobników pierwszej generacji
if ans == 0: for _ in range(definitions.GENETIC_ALGORITHM_COSTS_AMOUNT):
first_generation.append(random.uniform(0, 10))
solutions.append(first_generation) #generowanie losowych kosztów pól dla pierwszej generacji
for gen in range(definitions.GENETIC_ALGORITHM_NUMBER_OF_GENERATIONS): #liczba generacji
print(f"=== Generation {gen + 1} ===")
ranked_solutions = [] #rozwiązania z wynikiem
index = 0
for s in solutions: #przypisanie rozwiązaniom wyniku funkcji fitness
ranked_solutions.append((fitness(s, index), s))
index = index + 1
ranked_solutions.sort()
print(f"=== Gen {gen + 1} best solution ===")
print(ranked_solutions[0])
overall_solutions.append(ranked_solutions[0])
#TODO warunek stopu
best_solutions = ranked_solutions[:definitions.GENETIC_ALGORITHM_NUMBER_OF_BEST_INDIVIDUALS] #najlepsze osobniki w danej generacji
elements = []
for element in range(definitions.GENETIC_ALGORITHM_COSTS_AMOUNT):
elems = []
elements.append(elems)
for solution in best_solutions:
for element in range(definitions.GENETIC_ALGORITHM_COSTS_AMOUNT):
elements[element].append(solution[1][element])
next_generation = [] #nowa ganeracja
e = []
for individual in range(definitions.GENETIC_ALGORITHM_NUMBER_OF_INDIVIDUALS): #liczba osobników w kolejnej generacji
for el in range(definitions.GENETIC_ALGORITHM_COSTS_AMOUNT):
#mutacje
e.append(random.choice(elements[el]) * random.uniform(0.99, 1.01))
next_generation.append(e)
solutions = next_generation #zastąpnienie osobników nową generacją
overall_solutions.sort()
for _ in range(definitions.GENETIC_ALGORITHM_COSTS_AMOUNT): #przyspianie finalnych kosztów astara
astar_costs[_] = overall_solutions[0][1][_]
return astar_costs
def fitness(astar_costs, index):
ans = harvest(astar_costs, index)
if ans == 0: #TODO
return 0 return 0
else: else:
return 1 / ans return 1 / ans
def solution(astar_costs): def harvest(astar_costs, index):
#kolejność alfabetyczna
definitions.BEETROOTS_ADULT_COST = astar_costs[0] definitions.BEETROOTS_ADULT_COST = astar_costs[0]
definitions.BEETROOTS_GROW_COST = astar_costs[1] definitions.BEETROOTS_GROW_COST = astar_costs[1]
definitions.CARROTS_ADULT_COST = astar_costs[2] definitions.CARROTS_ADULT_COST = astar_costs[2]
@ -68,7 +107,7 @@ def solution(astar_costs):
decision = [0] #początkowa decyzja o braku powrotu do stacji (0) decision = [0] #początkowa decyzja o braku powrotu do stacji (0)
grow_flower_dandelion = False grow_flower_dandelion = False
random_movement = False random_movement = False
for run in range(1000): #liczba ruchów wózka for run in range(definitions.GENETIC_ALGORITHM_NUMBER_OF_CART_MOVES): #liczba ruchów wózka
if not move_list: #jeżeli są jakieś ruchy do wykonania w move_list if not move_list: #jeżeli są jakieś ruchy do wykonania w move_list
grow_flower_dandelion = True grow_flower_dandelion = True
istate = graph.Istate(cart1.get_direction(), cart1.get_x() / definitions.BLOCK_SIZE, cart1.get_y() / definitions.BLOCK_SIZE) #stan początkowy wózka (jego orientacja oraz jego aktualne miejsce) istate = graph.Istate(cart1.get_direction(), cart1.get_x() / definitions.BLOCK_SIZE, cart1.get_y() / definitions.BLOCK_SIZE) #stan początkowy wózka (jego orientacja oraz jego aktualne miejsce)
@ -89,92 +128,5 @@ def solution(astar_costs):
cart1.do_work(cart1_rect, map1, station1) #wykonaj pracę na danym polu cart1.do_work(cart1_rect, map1, station1) #wykonaj pracę na danym polu
decision = treelearn.make_decision(cart1.get_all_amount_of_seeds(), cart1.get_all_collected_plants(), cart1.get_all_fertilizer(), cart1.get_fuel(), tree, cart1.get_water_level()) #podejmij decyzję czy wracać do stacji (0 : NIE, 1 : TAK) decision = treelearn.make_decision(cart1.get_all_amount_of_seeds(), cart1.get_all_collected_plants(), cart1.get_all_fertilizer(), cart1.get_fuel(), tree, cart1.get_water_level()) #podejmij decyzję czy wracać do stacji (0 : NIE, 1 : TAK)
plant.Plant.grow_plants(map1) #zwiększ poziom dojrzałości roślin plant.Plant.grow_plants(map1) #zwiększ poziom dojrzałości roślin
print("individual no.", index + 1, "score:", station1.get_all_collected_plants())
return station1.get_all_collected_plants()
print("Ile zebrał: ", station1.get_collected_plants("beetroot") + station1.get_collected_plants("carrot") + station1.get_collected_plants("potato") + station1.get_collected_plants("wheat"))
return station1.get_collected_plants("beetroot") + station1.get_collected_plants("carrot") + station1.get_collected_plants("potato") + station1.get_collected_plants("wheat")
def make_generations(astar_costs):
solutions = []
ans = []
for s in range(10): #liczba osobników zerowej generacji
solutions.append((random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10), random.uniform(0, 10)))
for i in range(10): #liczba generacji
ranked_solutions = []
for s in solutions:
ranked_solutions.append((fitness(s), s))
ranked_solutions.sort()
print(f"=== Gen {i + 1} best solution ===")
#print(f"=== Gen {i} best solutions ===")
print(ranked_solutions[0])
ans.append(ranked_solutions[0])
print(ans)
#można dodać warunek stopu
best_solutions = ranked_solutions[:4] #najlepsze 4 osobniki w danej generacji
elements1 = []
elements2 = []
elements3 = []
elements4 = []
elements5 = []
elements6 = []
elements7 = []
elements8 = []
elements9 = []
elements10 = []
elements11 = []
elements12 = []
elements13 = []
for s in best_solutions:
elements1.append(s[1][0])
elements2.append(s[1][1])
elements3.append(s[1][2])
elements4.append(s[1][3])
elements5.append(s[1][4])
elements6.append(s[1][5])
elements7.append(s[1][6])
elements8.append(s[1][7])
elements9.append(s[1][8])
elements10.append(s[1][9])
elements11.append(s[1][10])
elements12.append(s[1][11])
elements13.append(s[1][12])
new_gen = []
for i in range(10): # liczba osobników w kolejnej generacji
e1 = random.choice(elements1) * random.uniform(0.99, 1.01) # mutacje
e2 = random.choice(elements2) * random.uniform(0.99, 1.01)
e3 = random.choice(elements3) * random.uniform(0.99, 1.01)
e4 = random.choice(elements4) * random.uniform(0.99, 1.01)
e5 = random.choice(elements5) * random.uniform(0.99, 1.01)
e6 = random.choice(elements6) * random.uniform(0.99, 1.01)
e7 = random.choice(elements7) * random.uniform(0.99, 1.01)
e8 = random.choice(elements8) * random.uniform(0.99, 1.01)
e9 = random.choice(elements9) * random.uniform(0.99, 1.01)
e10 = random.choice(elements10) * random.uniform(0.99, 1.01)
e11 = random.choice(elements11) * random.uniform(0.99, 1.01)
e12 = random.choice(elements12) * random.uniform(0.99, 1.01)
e13 = random.choice(elements13) * random.uniform(0.99, 1.01)
new_gen.append((e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13))
solutions = new_gen
ans.sort()
astar_costs[0] = ans[0][1][0]
astar_costs[1] = ans[0][1][1]
astar_costs[2] = ans[0][1][2]
astar_costs[3] = ans[0][1][3]
astar_costs[4] = ans[0][1][4]
astar_costs[5] = ans[0][1][5]
astar_costs[6] = ans[0][1][6]
astar_costs[7] = ans[0][1][7]
astar_costs[8] = ans[0][1][8]
astar_costs[9] = ans[0][1][9]
astar_costs[10] = ans[0][1][10]
astar_costs[11] = ans[0][1][11]
astar_costs[12] = ans[0][1][12]
return astar_costs

View File

@ -14,7 +14,7 @@ class Plant:
def set_state(self, state): def set_state(self, state):
self.state = state self.state = state
@staticmethod @staticmethod
def get_closest_mature_plant(istate, map): # TO DO, pobiera współrzędne najbliższej dojrzałej rośliny od miejsca, w którym znajduje się traktor def get_closest_mature_plant(istate, map): #pobiera miejsce najbliższej dojrzałej rośliny od miejsca, w którym znajduje się wózek
x = None #x'owa pola x = None #x'owa pola
y = None #y'kowa pola y = None #y'kowa pola
min = None min = None

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -1,6 +1,8 @@
class Station: class Station:
def __init__(self, collected_plants): def __init__(self, collected_plants):
self.collected_plants = collected_plants #collected_plants to słownik, przechowuje informacje o oddanych plonach self.collected_plants = collected_plants #collected_plants to słownik, przechowuje informacje o oddanych plonach
def get_all_collected_plants(self): #zwraca łączną ilość zebranych plonów (suma plonów wszystkich roślin)
return self.collected_plants["beetroot"] + self.collected_plants["carrot"] + self.collected_plants["potato"] + self.collected_plants["wheat"]
def get_collected_plants(self, name): #zwraca łączną ilość oddanych plonów dla podanej rośliny (name) def get_collected_plants(self, name): #zwraca łączną ilość oddanych plonów dla podanej rośliny (name)
return self.collected_plants[name] return self.collected_plants[name]
def set_collected_plants(self, name, value): #dla podanej rośliny (name) ustawia łączną ilość oddanych plonów (value) def set_collected_plants(self, name, value): #dla podanej rośliny (name) ustawia łączną ilość oddanych plonów (value)