-
Notifications
You must be signed in to change notification settings - Fork 840
/
server.py
46 lines (39 loc) · 1.41 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import random
from mesa.visualization.modules import CanvasGrid
from mesa.visualization.ModularVisualization import ModularServer
from shape_model.model import Walker, ShapesModel
def agent_draw(agent):
portrayal = None
if agent is None:
# Actually this if part is unnecessary, but still keeping it for
# aesthetics
pass
elif isinstance(agent, Walker):
print("Uid: {0}, Heading: {1}".format(agent.unique_id, agent.heading))
portrayal = {"Shape": "arrowHead",
"Filled": "true",
"Layer": 2,
"Color": "green",
"Filled": "true",
"heading_x": agent.heading[0],
"heading_y": agent.heading[1],
"text": agent.unique_id,
"text_color": "white",
"scale": 0.8,
}
return portrayal
def launch_shape_model():
width = 15
height = 10
num_agents = 2
pixel_ratio = 50
grid = CanvasGrid(agent_draw, width, height,
width * pixel_ratio, height * pixel_ratio)
server = ModularServer(ShapesModel, [grid], "Shape Model Example",
{"N": num_agents, "width": width, "height": height})
server.max_steps = 0
server.port = 8521
server.launch()
if __name__ == "__main__":
random.seed(3)
launch_shape_model()