From 23950ba5b5773873fca041f50b382ecadf1d15c4 Mon Sep 17 00:00:00 2001 From: Jeremi Lisek Date: Thu, 9 Jun 2022 21:54:00 +0200 Subject: [PATCH] ItemDisplayAgent --- GameModel.py | 12 +++++++- ItemDisplayAgent.py | 10 +++++++ PatchType.py | 1 + main.py | 68 ++++----------------------------------------- 4 files changed, 27 insertions(+), 64 deletions(-) create mode 100644 ItemDisplayAgent.py diff --git a/GameModel.py b/GameModel.py index e7e14d0..8d8fc11 100644 --- a/GameModel.py +++ b/GameModel.py @@ -9,6 +9,7 @@ from mesa.time import RandomActivation from AgentBase import AgentBase from ForkliftAgent import ForkliftAgent from InitialStateFactory import InitialStateFactory +from ItemDisplayAgent import ItemDisplayAgent from PatchAgent import PatchAgent from PatchType import PatchType from PictureVisualizationAgent import PictureVisualizationAgent @@ -36,7 +37,9 @@ class Phase(Enum): class GameModel(Model): - def __init__(self, width, height, graph: GridWithWeights, items: int, orders: int, classificator): + def __init__(self, width, height, graph: GridWithWeights, items: int, orders: int, classificator, + item_display_pos: List[GridLocation]): + # self.num_agents = 5 self.first = True self.item_recognised = False @@ -68,6 +71,7 @@ class GameModel(Model): self.schedule.add(self.forklift_agent) self.agents.append(self.forklift_agent) + self.display_agents: List[ItemDisplayAgent] = [] # INITIALIZATION # print("############## INITIALIZATION ##############") @@ -162,6 +166,12 @@ class GameModel(Model): self.agents.append(agent) self.grid.place_agent(agent, p[1]) + def place_order_items_display(self, item_positions: List[GridLocation]): + for p in item_positions: + agent = ItemDisplayAgent(self, p) + self.display_agents.append(agent) + self.grid.place_agent(agent, p) + def step(self): self.schedule.step() self.grid.remove_agent(self.forklift_agent) diff --git a/ItemDisplayAgent.py b/ItemDisplayAgent.py new file mode 100644 index 0000000..73a9ca4 --- /dev/null +++ b/ItemDisplayAgent.py @@ -0,0 +1,10 @@ +from PatchAgent import PatchAgent +from PatchType import PatchType +from util.PathDefinitions import GridLocation + + +class ItemDisplayAgent(PatchAgent): + + def __init__(self, model, location: GridLocation): + self.image = None + super().__init__(model, location, patch_type=PatchType.itemDisplay) diff --git a/PatchType.py b/PatchType.py index 96a4c05..57fcc10 100644 --- a/PatchType.py +++ b/PatchType.py @@ -11,3 +11,4 @@ class PatchType(enum.Enum): packingRefrigerator = 7 packingDoor = 8 divider = 9 + itemDisplay = 10 diff --git a/main.py b/main.py index ffa4084..b8b216b 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ import random from mesa.visualization.ModularVisualization import ModularServer from mesa.visualization.modules import CanvasGrid +from tensorflow import keras from ForkliftAgent import ForkliftAgent from GameModel import GameModel @@ -94,6 +95,8 @@ if __name__ == '__main__': grid = CanvasGrid(agent_portrayal, gridWidth, gridHeight, scale * gridWidth, scale * gridHeight) + display_items = [(6, 11), (7, 11), (8, 11), (9, 11)] + readyText = DisplayAttributeElement("phase") # current_item = DisplayPictureElement("current_item_recognition") provided_itesm = DisplayItemListAttributeElement("provided_items") @@ -107,69 +110,8 @@ if __name__ == '__main__': [grid, readyText, provided_itesm, recognised_items, ordersText, fulfilled_orders], "Automatyczny Wózek Widłowy", - dict(width=gridHeight, height=gridWidth, graph=diagram, items=50, orders=20, classificator=model)) - - # def order_rule(order: Order): - # return order.id - # - # - # punish_low = 500 - # punish_med = 300 - # def sum_wrong(member: [Order]) -> int: - # last_high = 0 - # last_med = 0 - # - # sum_high = 0 - # sum_med = 0 - # sum_low = 0 - # - # counter = 0 - # - # for i in range(len(member)): - # o: Order = member[i] - # if o.priority == Priority.HIGH : - # sum_high += 1 - # last_high = i - # elif o.priority == Priority.MEDIUM: - # sum_med += 1 - # last_med = i - # else: - # sum_low += 1 - # - # for i in range(last_high): - # o: Order = member[i] - # if o.priority == Priority.MEDIUM: - # counter += punish_med - # elif o.priority == Priority.LOW: - # counter += punish_low - # - # for i in range(last_med): - # o: Order = member[i] - # if o.priority == Priority.LOW: - # counter += punish_low - # - # print("sum: high:", sum_high, "med:", sum_med, "low:", sum_low) - # print("last_high:", last_high, "last_med:", last_med, "sum:", counter) - # return counter - # - # orders = InitialStateFactory.generate_order_list_XD(20) - # test: GeneticOrder = GeneticOrder(orders) - # punish_low = test.punish_low - # punish_med = test.punish_med - # - # print("SIEMA before: ") - # sum_wrong(orders) - # for i in orders: - # print("id:", i.id, "priority:", i.priority, "sum/time:", i.sum/i.time) - # # print("id:", i.id, "priority:", i.priority) - # - # newOrders = test.get_orders_sorted(orders) - # - # print("NAURA after:") - # sum_wrong(newOrders) - # for i in newOrders: - # print("id:", i.id, "priority:", i.priority, "sum/time:", i.sum/i.time) - # # print("id:", i.id, "priority:", i.priority) + dict(width=gridHeight, height=gridWidth, graph=diagram, items=50, orders=3, + classificator=model,item_display_pos=display_items)) server.port = 8888 server.launch()