SI_InteligentnyWozekWidlowy/main.py
2022-06-10 01:16:43 +02:00

126 lines
5.0 KiB
Python

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
from ItemDisplayAgent import ItemDisplayAgent
from PatchAgent import PatchAgent
from PatchType import PatchType
from PictureVisualizationAgent import PictureVisualizationAgent
from data.enum.Direction import Direction
from util.PathDefinitions import GridWithWeights
from visualization.DisplayAttributeElement import DisplayAttributeElement
from visualization.DisplayItemListAttribute import DisplayItemListAttributeElement
from visualization.DisplayOrder import DisplayOrder
from visualization.DisplayOrderList import DisplayOrderList
colors = [
'blue', 'cyan', 'orange', 'yellow', 'magenta', 'purple', '#103d3e', '#9fc86c',
'#b4c2ed', '#31767d', '#31a5fa', '#ba96e0', '#fef3e4', '#6237ac', '#f9cacd', '#1e8123'
]
def agent_portrayal(agent):
if isinstance(agent, ForkliftAgent):
shape = ""
if agent.current_rotation == Direction.top:
shape = "img/image_top.png"
elif agent.current_rotation == Direction.right:
shape = "img/image_right.png"
elif agent.current_rotation == Direction.down:
shape = "img/image_down.png"
elif agent.current_rotation == Direction.left:
shape = "img/image_left.png"
portrayal = {"Shape": shape, "scale": 1.0, "Layer": 0}
if isinstance(agent, PatchAgent):
color = colors[0]
if agent.patch_type == PatchType.wall:
portrayal = {"Shape": "img/brick.webp", "scale": 1.0, "Layer": 0}
elif agent.patch_type == PatchType.dropOff:
portrayal = {"Shape": "img/truck.png", "scale": 1.0, "Layer": 0}
elif agent.patch_type == PatchType.pickUp:
portrayal = {"Shape": "img/okB00mer.png", "scale": 1.0, "Layer": 0}
elif agent.patch_type == PatchType.diffTerrain:
portrayal = {"Shape": "img/puddle.png", "scale": 1.0, "Layer": 0}
elif agent.patch_type == PatchType.packingShelf:
portrayal = {"Shape": "img/shelf_s.jpg", "scale": 1.0, "Layer": 0}
elif agent.patch_type == PatchType.packingRefrigerator:
portrayal = {"Shape": "img/fridge_f.jpg", "scale": 1.0, "Layer": 0}
elif agent.patch_type == PatchType.packingDoor:
portrayal = {"Shape": "img/door_d.jpg", "scale": 1.0, "Layer": 0}
elif agent.patch_type == PatchType.divider:
portrayal = \
{"Shape": "rect",
"Filled": "true",
"Layer": 0,
"Color": "black",
"w": 1,
"h": 1}
else:
color = colors[random.randrange(13) + 3]
portrayal = {"Shape": "rect",
"Filled": "true",
"Layer": 0,
"Color": color,
"w": 1,
"h": 1}
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
if __name__ == '__main__':
base = 512
gridWidth = 10
gridHeight = 13
scale = base / gridWidth
diagram = GridWithWeights(gridWidth, gridHeight)
diagram.walls = [(6, 5), (6, 6), (6, 7), (6, 8), (2, 3), (2, 4), (3, 4), (4, 4), (6, 4)]
diagram.puddles = [(2, 2), (2, 5), (2, 6), (5, 4)]
diagram.packingStations = [(PatchType.packingShelf, (4, 8)), (PatchType.packingRefrigerator, (4, 6)),
(PatchType.packingDoor, (4, 2))]
grid = CanvasGrid(agent_portrayal, gridWidth, gridHeight, scale * gridWidth, scale * gridHeight)
display_items = [(6, 11), (7, 11), (8, 11), (9, 11)]
readyText = DisplayAttributeElement("phase")
provided_itesm = DisplayItemListAttributeElement("provided_items")
recognised_items = DisplayItemListAttributeElement("recognised_items")
current_order = DisplayOrder("current_order")
current_item = DisplayAttributeElement("current_item")
ordersText = DisplayOrderList("orderList")
fulfilled_orders = DisplayOrderList("fulfilled_orders")
model = keras.models.load_model("imageClasification/my_model")
server = ModularServer(GameModel,
[grid, readyText, current_item, current_order, fulfilled_orders, ordersText],
"Automatyczny Wózek Widłowy",
dict(width=gridHeight, height=gridWidth, graph=diagram, items=60, orders=20,
classificator=model, item_display_pos=display_items))
server.port = 8888
server.launch()