-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
105 lines (90 loc) · 2.95 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from mesa.visualization.ModularVisualization import ModularServer
from mesa.visualization.modules import CanvasGrid, ChartModule
from mesa.visualization.UserParam import UserSettableParameter
from food import Food
from bee import Bee
from hive import Hive
from obstacle_grid import OBSTACLE
from config import GRID_HEIGHT, GRID_WIDTH
from model import BeeForagingModel
color_dic = {
4: "#005C00",
3: "#008300",
2: "#00AA00",
1: "#00F800",
0: "red"
}
def hive_portrayal(agent):
if agent is None:
return
elif type(agent) is Bee:
return {
"Shape": "circle",
"scale": 0.9,
"r": 0.5,
"Layer": 2,
"Filled": "true",
"Color": agent.color
}
elif type(agent) is Food:
col_intensity = agent.util
assert col_intensity >= 0, agent.__dict__
col_intensity = 4 if col_intensity > 4 else col_intensity
return {
"Shape": "circle",
"scale": 0.9,
"Layer": 1,
"Filled": "true",
"Color": color_dic[col_intensity],
"r": 0.7
}
elif type(agent) is Hive:
return {
"Shape": "rect",
"scale": 0.9,
"Layer": 0,
"Filled": "true",
"w": 1,
"h": 1,
"Color": agent.color
}
elif agent is OBSTACLE:
return {
"Shape": "rect",
"scale": 0.9,
"Layer": 0,
"Filled": "true",
"Color": "GREY",
"w": 1,
"h": 1
}
width = GRID_WIDTH
height = GRID_HEIGHT
canvas_element = CanvasGrid(hive_portrayal, width, height, 500, 500)
chart_element = ChartModule([{"Label": "n_bees", "Color": "#AA0000"},
{"Label": "hive_food", "Color": "#000000"},
{"Label": "scout_bees", "Color": "#70a5f9"},
{"Label": "forage_bees", "Color": "#f4b042"},
{"Label": "rest_bees", "Color": "#17ef71"},
{"Label": "baby_bees", "Color": "#ff93d0"}],
500, 500)
server = ModularServer(
BeeForagingModel,
[canvas_element, chart_element],
"Hive",
{
"width": width,
"height": height,
"obstacle_density": UserSettableParameter('slider',
'obstacle density',
value=0,
min_value=0,
max_value=100),
"food_density": UserSettableParameter('slider',
'food density',
value=1,
min_value=0,
max_value=100),
"VIZUALISATION": True
}
)