2022-03-07 22:27:34 +01:00
|
|
|
import random
|
|
|
|
|
2022-03-06 22:16:21 +01:00
|
|
|
from mesa.visualization.modules import CanvasGrid
|
|
|
|
from mesa.visualization.ModularVisualization import ModularServer
|
|
|
|
|
|
|
|
from ForkliftModel import ForkliftModel
|
2022-03-07 22:27:34 +01:00
|
|
|
from ForkliftAgent import ForkliftAgent
|
|
|
|
from PatchAgent import PatchAgent
|
|
|
|
from PatchType import PatchType
|
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
|
|
|
|
|
|
|
def agent_portrayal(agent):
|
|
|
|
|
2022-03-07 22:27:34 +01:00
|
|
|
|
|
|
|
if isinstance(agent, ForkliftAgent):
|
|
|
|
portrayal = {"Shape": "image.png", "scale": 1.0, "Layer": 0}
|
|
|
|
|
|
|
|
if isinstance(agent, PatchAgent):
|
|
|
|
color = colors[0]
|
|
|
|
if agent.type == PatchType.dropOff:
|
|
|
|
color = colors[1]
|
|
|
|
elif agent.type == PatchType.pickUp:
|
|
|
|
color = colors[2]
|
|
|
|
else:
|
|
|
|
color = colors[random.randrange(13)+3]
|
|
|
|
portrayal = {"Shape": "rect",
|
|
|
|
"Filled": "true",
|
|
|
|
"Layer": 0,
|
|
|
|
"Color": color,
|
|
|
|
"w": 1,
|
|
|
|
"h": 1}
|
2022-03-06 22:16:21 +01:00
|
|
|
return portrayal
|
|
|
|
|
2022-03-07 22:27:34 +01:00
|
|
|
base = 512
|
|
|
|
gridWidth = 6
|
|
|
|
gridHeight = 4
|
|
|
|
scale = base/gridWidth
|
2022-03-06 22:16:21 +01:00
|
|
|
|
2022-03-07 22:27:34 +01:00
|
|
|
grid = CanvasGrid(agent_portrayal, gridWidth, gridHeight, scale*gridWidth, scale*gridHeight)
|
2022-03-06 22:16:21 +01:00
|
|
|
|
|
|
|
server = ModularServer(ForkliftModel,
|
|
|
|
[grid],
|
|
|
|
"Automatyczny Wózek Widłowy",
|
2022-03-07 22:27:34 +01:00
|
|
|
{"width": gridHeight, "height": gridWidth})
|
2022-03-06 22:16:21 +01:00
|
|
|
server.port = 8888
|
|
|
|
server.launch()
|