From 6322d823fade56ea72ebcb05f4dc429f931249a5 Mon Sep 17 00:00:00 2001 From: andrzej Date: Mon, 15 Jun 2020 14:10:33 +0200 Subject: [PATCH] =?UTF-8?q?Pr=C3=B3ba=20integracji=20drzewa=20z=20alg.=20g?= =?UTF-8?q?enetycznym?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent.py | 21 ++++++++++----------- genetic_algorithm.py | 17 +++++++++++------ genetic_route.py | 4 ++-- main.py | 6 +++--- siec.py | 2 -- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/agent.py b/agent.py index 49b6e64..db53804 100755 --- a/agent.py +++ b/agent.py @@ -1,4 +1,3 @@ -from pandas.tests.io.json.test_ujson import numpy from warehouse import Coordinates, Tile, Pack from queue import PriorityQueue @@ -198,8 +197,8 @@ class Agent: sys.exit() pack_id = self.route[0] self.route = self.route[1:] - print("Next package ID:") - print(pack_id) + # print("Next package ID:") + # print(pack_id) dst_package = None for pack in self.warehouse.packages: if pack.id + 1 == pack_id: @@ -208,11 +207,11 @@ class Agent: if dst_package is not None: return dst_package - nmodel = Sequential() - imageClass(nmodel) - nmodel.load_weights('model_weights.h5') + nmodel = Sequential() + imageClass(nmodel) + nmodel.load_weights('model_weights.h5') - imgSkan() + imgSkan() def rack_heuristics(self, start, goal, can_place): heur_can_place = not can_place @@ -286,8 +285,8 @@ class Agent: self.graph_map[0][package1.id + 1] = len(self.path) def trace_route(self): - for packs in self.warehouse.packages: - print(packs.id) + # for packs in self.warehouse.packages: + # print(packs.id) self.route = genetic_trace_route(self.graph_map, len(self.warehouse.packages)) - print("best route") - print(self.route) + # print("best route") + # print(self.route) diff --git a/genetic_algorithm.py b/genetic_algorithm.py index 896b174..a7d7f69 100755 --- a/genetic_algorithm.py +++ b/genetic_algorithm.py @@ -1,6 +1,5 @@ import random import math - ### prawdopodobieństwo mutacji mutation_prob = 0.03 ### ilość osobników w pokoleniu, powinna być parzysta @@ -8,7 +7,7 @@ generation_size = 40 ### liczba pokoleń number_of_generations = 30 ### jak bardzo promowane są osobniki wykorzystujące całą pojemność regału -amount_of_promotion = 0 +amount_of_promotion = 5 def first_gen(number_of_packages, number_of_racks): @@ -24,11 +23,16 @@ def first_gen(number_of_packages, number_of_racks): def evaluation(individual, packages, racks, number_of_packages, number_of_racks, tree_predictor): # im większy fitness tym lepszy osobnik # print("regały: ",racks) - rest_of_capacity = racks.copy() + rest_of_capacity = [rack.capacity for rack in racks] # print("początkowa pojemność: ",rest_of_capacity) for i in range(number_of_packages): - rest_of_capacity[individual[i]] -= packages[i] + can_place = tree_predictor.check_if_can_place(packages[i], racks[i]) + if not can_place: + rest_of_capacity[individual[i]] -= packages[i].size * 5 + else: + rest_of_capacity[individual[i]] -= packages[i].size # print("pozostała pojemność: ",rest_of_capacity) + # pdb.set_trace() fitness = 0 for i in range(number_of_racks): # jak regał jest przepełniony, zmniejsza fitness osobnika @@ -36,8 +40,9 @@ def evaluation(individual, packages, racks, number_of_packages, number_of_racks, fitness += rest_of_capacity[i] # delikane promowanie osobników wykorzystujących regały w pełni elif rest_of_capacity[i] == 0: - fitness += amount_of_promotion - ### tu dodaj to co zrobi Andrzej + fitness += 2 + else: + fitness += 1 return fitness def roulette(generation, packages, racks, number_of_packages, number_of_racks, tree_predictor): diff --git a/genetic_route.py b/genetic_route.py index ab7f580..02ec8f5 100755 --- a/genetic_route.py +++ b/genetic_route.py @@ -90,8 +90,8 @@ def genetic_trace_route(graph_map, packages): population = copy.deepcopy(new_population) scores = score_all(graph_map, population) scores.sort(key=lambda x: x[1]) - print("Best route of all population in iteration " + str(i + 1)) - print(scores[0][1]) + # print("Best route of all population in iteration " + str(i + 1)) + # print(scores[0][1]) scores = score_all(graph_map, population) scores.sort(key=lambda x: x[1]) diff --git a/main.py b/main.py index a6e1b41..79cbcab 100755 --- a/main.py +++ b/main.py @@ -20,7 +20,7 @@ TILE_HEIGHT = 32 CIRCLE_CENTER_X, CIRCLE_CENTER_Y = int(TILE_WIDTH/2), int(TILE_HEIGHT/2) class MainGameFrame: - def __init__(self, mutation_prob=0.03, generation_size=40, number_of_generations=30, amount_of_promotion=0): + def __init__(self, mutation_prob=0.03, generation_size=40, number_of_generations=100, amount_of_promotion=0): pygame.font.init() self.display = pygame.display.set_mode(WINDOW_SIZE) pygame.display.set_caption("Smart ForkLift") @@ -35,8 +35,8 @@ class MainGameFrame: packs_coords = [(pack.lays_on_field.x_position, pack.lays_on_field.y_position) for pack in self.warehouse_map.packages] list_of_racks = self.warehouse_map.get_all_racks(True) racks_coords = [(line.x_position, line.y_position) for line in list_of_racks] - packs_sizes = [pack.size for pack in self.warehouse_map.packages] - racks_capacities = [rack.capacity for rack in list_of_racks] + packs_sizes = [pack for pack in self.warehouse_map.packages] + racks_capacities = list_of_racks # print("koordynaty paczek: ",packs_coords) # print("koordynaty regałów: ",racks_coords) print("wagi paczek: ",packs_sizes) diff --git a/siec.py b/siec.py index 94a401b..cce1492 100644 --- a/siec.py +++ b/siec.py @@ -41,5 +41,3 @@ def imgSkan(): prediction = numpy.argmax(prediction) print("Producent:", prediction) producent.append(prediction) - -imgSkan() \ No newline at end of file