-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
117 lines (103 loc) · 4.41 KB
/
server.py
File metadata and controls
117 lines (103 loc) · 4.41 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
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
106
107
108
109
110
111
112
113
114
115
116
117
import mesa
from agents import Soil, Type_a, Type_b, Type_c, Type_d, Type_a_1, Type_a_2
from model import Microbiome
# Colors for the bacteria
COLOR_TYPE_A = "#F2C249"
COLOR_TYPE_B = "#E6772E"
COLOR_TYPE_C = "#4DB3B3"
COLOR_TYPE_D = "#E64A45"
COLOR_TYPE_A_1 = "#3D4C53"
COLOR_TYPE_A_2 = "#9FBF8C"
def bacteria_portrayal(agent):
#if agent is None or isinstance(agent, Soil):
# return
portrayal = {}
# update portrayal characteristics for each Person object
portrayal["Shape"] = "circle"
portrayal["r"] = 0.5
portrayal["Layer"] = 1
portrayal["Filled"] = "true"
# set agent color based on savings and loans
if isinstance(agent, Type_a):
color=COLOR_TYPE_A
elif isinstance(agent, Type_a_1):
color=COLOR_TYPE_A_1
elif isinstance(agent, Type_a_2):
color=COLOR_TYPE_A_2
elif isinstance(agent, Type_b):
color=COLOR_TYPE_B
elif isinstance(agent, Type_c):
color=COLOR_TYPE_C
elif isinstance(agent, Type_d):
color=COLOR_TYPE_D
portrayal["Layer"] = 2
# showing the antibiotic type_a_2
elif isinstance(agent, Soil):
if 'Type_a_2' in agent.antibiotics and agent.antibiotics['Type_a_2'] > 0:
portrayal["r"] = 1
color="#FF7777"
portrayal["Layer"] = 0
else:
color = "WHITE"
portrayal["Color"] = color
return portrayal
# dictionary of user settable parameters - these map to the model __init__ parameters
model_params = {
"STATIC_TEXT1": mesa.visualization.StaticText('<h4>Type A</h4> (Staphylococcus aureus)'),
"num_type_a": mesa.visualization.Slider(
"Type_a Anfangspopulation", 0, 0, 10, description="Zufällig Verteilt"
),
"type_a_population_limit": mesa.visualization.Slider(
"Type_a Population Limit", 1000, 0, 10000, description="0 means no Limit"
),
"STATIC_TEXT4": mesa.visualization.StaticText('<br><h4>Type D</h4> (Myxobakterien)'),
"num_type_d": mesa.visualization.Slider(
"Type_d Anzahl Schwärme", 0, 0, 5, description="Ein Schwarm bewegt sich zusammen und 'jagt' zusammen"
),
"type_d_population_limit": mesa.visualization.Slider(
"Type_d Population Limit", 400, 0, 5000, description="0 means no Limit"
),
"STATIC_TEXT2": mesa.visualization.StaticText('<br><h4>Type A 1 und Type A 2</h4>(Sub-Arten Staphylococcus aureus)<br> Typ A 1 kann Antibiotika gegen Typ A 2 absondern'),
"num_type_a_1": mesa.visualization.Slider(
"Type_a_1 Anfangspopulation", 1, 0, 10, description="Zufällig Verteilt"
),
"num_type_a_2": mesa.visualization.Slider(
"Type_a_2 Anfangspopulation", 1, 0, 10, description="Zufällig Verteilt"
),
"STATIC_TEXT3": mesa.visualization.StaticText('<br><h4>Type B und Type C</h4>(Salmonellen und Klebsiella)'),
"num_type_b": mesa.visualization.Slider(
"Type_b Anfangspopulation", 0, 0, 10, description="Zufällig Verteilt"
),
"num_type_c": mesa.visualization.Slider(
"Type_c Anfangspopulation", 0, 0, 10, description="Zufällig Verteilt"
),
"STATIC_TEXT5": mesa.visualization.StaticText('<br><h4>Grid</h4> Torus: Ein Torusgitter ist ein zweidimensionales Gitter, das sich zu einem Ring formt, indem die gegenüberliegenden Ränder verbunden werden.<br>grid_width und grid_height: an der Visualisierung änder sich nichts, es wird aber nur ein Teil des Gitters verwendet'),
"is_torus": mesa.visualization.Checkbox(
"Torus", True, description=""
),
"grid_width": mesa.visualization.Slider(
"grid_width", 50, 0, 100, description=""
),
"grid_height": mesa.visualization.Slider(
"grid_height", 50, 0, 100, description=""
)
}
# set the portrayal function and size of the canvas for visualization
canvas_element = mesa.visualization.CanvasGrid(bacteria_portrayal, 100, 100, 500, 500)
# Namen der Labels müssen gleich sein wie im DataCollector im model
chart_element = mesa.visualization.ChartModule(
[
{"Label": "Type_a", "Color": COLOR_TYPE_A},
{"Label": "Type_a_1", "Color": COLOR_TYPE_A_1},
{"Label": "Type_a_2", "Color": COLOR_TYPE_A_2},
{"Label": "Type_b", "Color": COLOR_TYPE_B},
{"Label": "Type_c", "Color": COLOR_TYPE_C},
{"Label": "Type_d", "Color": COLOR_TYPE_D}
]
)
server = mesa.visualization.ModularServer(
Microbiome,
[canvas_element, chart_element],
"Microbiome",
model_params=model_params
)