2022-06-07 23:15:04 +02:00
|
|
|
import math
|
2022-03-07 22:27:34 +01:00
|
|
|
import random
|
|
|
|
|
2022-03-06 22:16:21 +01:00
|
|
|
from mesa.visualization.ModularVisualization import ModularServer
|
2022-04-08 00:43:25 +02:00
|
|
|
from mesa.visualization.modules import CanvasGrid
|
2022-06-09 21:54:00 +02:00
|
|
|
from tensorflow import keras
|
2022-03-06 22:16:21 +01:00
|
|
|
|
2022-03-07 22:27:34 +01:00
|
|
|
from ForkliftAgent import ForkliftAgent
|
2022-05-14 15:05:43 +02:00
|
|
|
from GameModel import GameModel
|
2022-06-07 01:07:49 +02:00
|
|
|
from InitialStateFactory import InitialStateFactory
|
2022-03-07 22:27:34 +01:00
|
|
|
from PatchAgent import PatchAgent
|
|
|
|
from PatchType import PatchType
|
2022-05-25 23:51:29 +02:00
|
|
|
from PictureVisualizationAgent import PictureVisualizationAgent
|
2022-06-07 01:07:49 +02:00
|
|
|
from data.Order import Order
|
2022-05-09 15:49:11 +02:00
|
|
|
from data.enum.Direction import Direction
|
2022-06-02 11:13:21 +02:00
|
|
|
from tensorflow import keras
|
2022-06-07 01:07:49 +02:00
|
|
|
|
|
|
|
from data.enum.Priority import Priority
|
|
|
|
from genetic_order.GeneticOrder import GeneticOrder
|
2022-05-14 15:05:43 +02:00
|
|
|
from util.PathDefinitions import GridWithWeights
|
2022-05-22 16:27:36 +02:00
|
|
|
from visualization.DisplayAttributeElement import DisplayAttributeElement
|
2022-05-25 23:51:29 +02:00
|
|
|
from visualization.DisplayItemListAttribute import DisplayItemListAttributeElement
|
|
|
|
from visualization.DisplayOrderList import DisplayOrderList
|
2022-03-06 22:16:21 +01:00
|
|
|
|
2022-03-07 22:27:34 +01:00
|
|
|
colors = [
|
|
|
|
'blue', 'cyan', 'orange', 'yellow', 'magenta', 'purple', '#103d3e', '#9fc86c',
|
|
|
|
'#b4c2ed', '#31767d', '#31a5fa', '#ba96e0', '#fef3e4', '#6237ac', '#f9cacd', '#1e8123'
|
|
|
|
]
|
2022-03-06 22:16:21 +01:00
|
|
|
|
2022-03-07 22:27:34 +01:00
|
|
|
|
2022-04-08 00:43:25 +02:00
|
|
|
def agent_portrayal(agent):
|
2022-03-07 22:27:34 +01:00
|
|
|
if isinstance(agent, ForkliftAgent):
|
2022-04-08 00:43:25 +02:00
|
|
|
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}
|
2022-03-07 22:27:34 +01:00
|
|
|
|
|
|
|
if isinstance(agent, PatchAgent):
|
|
|
|
color = colors[0]
|
2022-04-16 14:55:25 +02:00
|
|
|
if agent.patch_type == PatchType.wall:
|
|
|
|
portrayal = {"Shape": "img/brick.webp", "scale": 1.0, "Layer": 0}
|
|
|
|
elif agent.patch_type == PatchType.dropOff:
|
2022-04-08 00:43:25 +02:00
|
|
|
portrayal = {"Shape": "img/truck.png", "scale": 1.0, "Layer": 0}
|
2022-04-16 14:55:25 +02:00
|
|
|
elif agent.patch_type == PatchType.pickUp:
|
2022-04-08 00:43:25 +02:00
|
|
|
portrayal = {"Shape": "img/okB00mer.png", "scale": 1.0, "Layer": 0}
|
2022-04-28 14:03:53 +02:00
|
|
|
elif agent.patch_type == PatchType.diffTerrain:
|
|
|
|
portrayal = {"Shape": "img/puddle.png", "scale": 1.0, "Layer": 0}
|
2022-06-09 22:24:46 +02:00
|
|
|
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}
|
|
|
|
|
2022-05-25 23:51:29 +02:00
|
|
|
elif agent.patch_type == PatchType.divider:
|
|
|
|
portrayal = \
|
|
|
|
{"Shape": "rect",
|
|
|
|
"Filled": "true",
|
|
|
|
"Layer": 0,
|
|
|
|
"Color": "black",
|
|
|
|
"w": 1,
|
|
|
|
"h": 1}
|
2022-03-07 22:27:34 +01:00
|
|
|
else:
|
2022-04-08 00:43:25 +02:00
|
|
|
color = colors[random.randrange(13) + 3]
|
2022-03-24 20:43:53 +01:00
|
|
|
portrayal = {"Shape": "rect",
|
2022-04-08 00:43:25 +02:00
|
|
|
"Filled": "true",
|
|
|
|
"Layer": 0,
|
|
|
|
"Color": color,
|
|
|
|
"w": 1,
|
|
|
|
"h": 1}
|
2022-05-25 23:51:29 +02:00
|
|
|
|
|
|
|
if isinstance(agent, PictureVisualizationAgent):
|
|
|
|
portrayal = {"Shape": f"{agent.img}", "scale": 3.0, "Layer": 0}
|
|
|
|
|
2022-03-06 22:16:21 +01:00
|
|
|
return portrayal
|
|
|
|
|
2022-04-08 00:43:25 +02:00
|
|
|
|
2022-04-16 15:55:43 +02:00
|
|
|
if __name__ == '__main__':
|
2022-05-14 15:03:29 +02:00
|
|
|
base = 512
|
|
|
|
gridWidth = 10
|
2022-05-25 23:51:29 +02:00
|
|
|
gridHeight = 13
|
2022-05-14 15:03:29 +02:00
|
|
|
scale = base / gridWidth
|
|
|
|
|
2022-05-22 16:27:36 +02:00
|
|
|
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)]
|
2022-06-09 22:24:46 +02:00
|
|
|
diagram.packingStations = [(PatchType.packingShelf, (4, 8)), (PatchType.packingRefrigerator, (4, 6)), (PatchType.packingDoor, (4, 2))]
|
2022-05-14 15:03:29 +02:00
|
|
|
|
|
|
|
grid = CanvasGrid(agent_portrayal, gridWidth, gridHeight, scale * gridWidth, scale * gridHeight)
|
|
|
|
|
2022-06-09 21:54:00 +02:00
|
|
|
display_items = [(6, 11), (7, 11), (8, 11), (9, 11)]
|
|
|
|
|
2022-05-22 16:27:36 +02:00
|
|
|
readyText = DisplayAttributeElement("phase")
|
2022-05-25 23:51:29 +02:00
|
|
|
# current_item = DisplayPictureElement("current_item_recognition")
|
|
|
|
provided_itesm = DisplayItemListAttributeElement("provided_items")
|
|
|
|
recognised_items = DisplayItemListAttributeElement("recognised_items")
|
|
|
|
ordersText = DisplayOrderList("orderList")
|
|
|
|
fulfilled_orders = DisplayOrderList("fulfilled_orders")
|
2022-05-22 16:27:36 +02:00
|
|
|
|
2022-06-02 11:13:21 +02:00
|
|
|
model = keras.models.load_model("imageClasification/my_model")
|
2022-05-27 00:03:24 +02:00
|
|
|
|
2022-05-14 15:03:29 +02:00
|
|
|
server = ModularServer(GameModel,
|
2022-05-25 23:51:29 +02:00
|
|
|
[grid, readyText, provided_itesm, recognised_items, ordersText,
|
|
|
|
fulfilled_orders],
|
2022-05-14 15:03:29 +02:00
|
|
|
"Automatyczny Wózek Widłowy",
|
2022-06-09 21:54:00 +02:00
|
|
|
dict(width=gridHeight, height=gridWidth, graph=diagram, items=50, orders=3,
|
|
|
|
classificator=model,item_display_pos=display_items))
|
2022-06-09 21:54:18 +02:00
|
|
|
|
|
|
|
server.port = 8888
|
|
|
|
server.launch()
|