-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
36 lines (31 loc) · 1.32 KB
/
server.py
File metadata and controls
36 lines (31 loc) · 1.32 KB
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
from mesa.space import ContinuousSpace
from mesa.visualization.ModularVisualization import ModularServer
from mesa.visualization.modules import ChartModule
from SimpleContinuousModule import SimpleCanvas
from model import Traffic
from agent import Car, Pedestrian, Light
from data import Data
# You can change this to whatever you want. Make sure to make the different types
# of agents distinguishable
def agent_portrayal(agent):
if type(agent) is Pedestrian:
if agent.dir == "up":
pedest_color = "Blue"
else:
pedest_color = "Purple"
portrayal = {"Shape": "rect" if type(agent) is Car else "circle",
"Color": pedest_color if type(agent) is Pedestrian
else agent.color if type(agent) is Light
else "Pink",
"Filled": "true",
"w": 3.7*15 if type(agent) is Car else None,
"h": 1.7*15 if type(agent) is Car else None,
"r": .2*15 if type(agent) is not Car else None}
return portrayal
# Create a grid of 20 by 20 cells, and display it as 500 by 500 pixels
space = SimpleCanvas(agent_portrayal)
# Create the server, and pass the grid and the graph
server = ModularServer(Traffic,
[space],
"Traffic Model",
{})