51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import random
|
|
|
|
from mesa.visualization.modules import CanvasGrid
|
|
from mesa.visualization.ModularVisualization import ModularServer
|
|
|
|
from ForkliftModel import ForkliftModel
|
|
from ForkliftAgent import ForkliftAgent
|
|
from PatchAgent import PatchAgent
|
|
from PatchType import PatchType
|
|
|
|
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):
|
|
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}
|
|
return portrayal
|
|
|
|
base = 512
|
|
gridWidth = 6
|
|
gridHeight = 4
|
|
scale = base/gridWidth
|
|
|
|
grid = CanvasGrid(agent_portrayal, gridWidth, gridHeight, scale*gridWidth, scale*gridHeight)
|
|
|
|
server = ModularServer(ForkliftModel,
|
|
[grid],
|
|
"Automatyczny Wózek Widłowy",
|
|
{"width": gridHeight, "height": gridWidth})
|
|
server.port = 8888
|
|
server.launch()
|