order_visualization #5

Merged
s464919 merged 7 commits from order_visualization into master 2022-06-10 08:56:02 +02:00
5 changed files with 32 additions and 10 deletions
Showing only changes of commit b37847b304 - Show all commits

View File

@ -141,8 +141,8 @@ class ForkliftAgent(AgentBase):
[Action(ActionType.DROP_ITEM)]
)
self.current_item = None
self.current_order_delivered_items.append(self.current_item)
self.current_item = None
self.item_station_completed = False
def step(self) -> None:

View File

@ -71,12 +71,12 @@ class GameModel(Model):
self.schedule.add(self.forklift_agent)
self.agents.append(self.forklift_agent)
self.display_agents: List[ItemDisplayAgent] = []
self.item_display_agents: List[ItemDisplayAgent] = []
# INITIALIZATION #
print("############## INITIALIZATION ##############")
self.phase = Phase.INIT
self.initialize_grid(graph)
self.initialize_grid(graph, item_display_pos)
self.orderList: List[Order] = InitialStateFactory.generate_order_list(orders)
self.fulfilled_orders: List[Order] = []
self.forklift_agent.orderList = self.orderList
@ -105,7 +105,7 @@ class GameModel(Model):
print(actions)
self.forklift_agent.queue_movement_actions(actions)
def initialize_grid(self, graph: GridWithWeights):
def initialize_grid(self, graph: GridWithWeights, item_display_pos):
print("INITIALIZING GRID")
# Add the agent to a random grid cell
x = 5
@ -126,6 +126,7 @@ class GameModel(Model):
self.place_walls_agents(graph.walls)
self.place_puddles(graph.puddles)
self.place_packing_stations(graph.packingStations)
self.place_order_items_display(item_display_pos)
def place_dividers(self):
for i in range(0, 10):
@ -169,13 +170,19 @@ class GameModel(Model):
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.item_display_agents.append(agent)
self.grid.place_agent(agent, p)
def update_item_display(self):
for index, item in enumerate(self.forklift_agent.current_order_delivered_items):
if item is not None:
self.item_display_agents[index].image = item.image
def step(self):
self.schedule.step()
self.grid.remove_agent(self.forklift_agent)
self.grid.place_agent(self.forklift_agent, self.forklift_agent.current_position)
self.update_item_display()
if self.phase == Phase.ITEM_RECOGNITION:
if not self.item_recognised and self.forklift_agent.current_position == self.drop_off.location:

View File

@ -5,13 +5,14 @@ from data.Order import Order
from data.enum.ItemType import ItemType
from data.enum.Priority import Priority
from util.ClientParamsFactory import ClientParamsFactory
from util.PathByEnum import PathByEnum
class InitialStateFactory:
@staticmethod
def generate_item_list(output_list_size: int):
item_list : [Item] = []
item_list: [Item] = []
for i in range(output_list_size):
item_list.append(InitialStateFactory.__generate_item())
@ -74,7 +75,7 @@ class InitialStateFactory:
@staticmethod
def generate_input_sequence(self, input_sequence_size):
sequence : [Item] = []
sequence: [Item] = []
for i in range(0, input_sequence_size):
sequence.append(self.__generate_item())
@ -83,4 +84,4 @@ class InitialStateFactory:
@staticmethod
def __generate_item() -> Item:
randomly_picked_type = random.choice(list(ItemType))
return Item(randomly_picked_type)
return Item(randomly_picked_type, PathByEnum.get_random_path(randomly_picked_type))

View File

@ -6,9 +6,10 @@ from data.enum.ItemType import ItemType
class Item:
id_counter = count(start=0)
def __init__(self, item_type: ItemType):
def __init__(self, item_type: ItemType, image):
self.id = next(self.id_counter)
self.real_type = item_type
self.image = image
self.guessed_type = None
def __repr__(self) -> str:

15
main.py
View File

@ -8,6 +8,7 @@ from tensorflow import keras
from ForkliftAgent import ForkliftAgent
from GameModel import GameModel
from InitialStateFactory import InitialStateFactory
from ItemDisplayAgent import ItemDisplayAgent
from PatchAgent import PatchAgent
from PatchType import PatchType
from PictureVisualizationAgent import PictureVisualizationAgent
@ -79,6 +80,18 @@ def agent_portrayal(agent):
if isinstance(agent, PictureVisualizationAgent):
portrayal = {"Shape": f"{agent.img}", "scale": 3.0, "Layer": 0}
if isinstance(agent, ItemDisplayAgent):
if agent is not None and agent.image is not None:
portrayal = {"Shape": f"{agent.image}", "scale": 1.0, "Layer": 0}
else:
portrayal = \
{"Shape": "rect",
"Filled": "true",
"Layer": 0,
"Color": "black",
"w": 1,
"h": 1}
return portrayal
@ -111,7 +124,7 @@ if __name__ == '__main__':
fulfilled_orders],
"Automatyczny Wózek Widłowy",
dict(width=gridHeight, height=gridWidth, graph=diagram, items=50, orders=3,
classificator=model,item_display_pos=display_items))
classificator=model, item_display_pos=display_items))
server.port = 8888
server.launch()