-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbowen_1.py
63 lines (41 loc) · 1.25 KB
/
bowen_1.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
"""
Simulate inherited nuclear family emotional process as defined by Murray Bowen, M.D. from the NIMH family research project.
"""
import logging
import mesa
import mesa.time
import mesa.space
from mesa.visualization.ModularVisualization import ModularServer
from mesa.visualization.modules import CanvasGrid, ChartModule
from mesa.visualization.UserParam import UserSettableParameter
log = logging.getLogger(__name__)
class PersonAgent(mesa.Agent):
pass
class BowenModel(mesa.Model):
pass
def agent_portrayal(agent):
state_colors = {
PersonAgent.STATE_FRUSTRATED: "black",
PersonAgent.STATE_GRATIFIED: "green",
PersonAgent.STATE_NEED: "red",
}
def _color(agent):
if agent.collision:
return "blue"
else:
return state_colors.get(agent.state)
portrayal = {
"Shape": "circle",
"Color": _color(agent),
"Filled": not agent.collision,
"Layer": 0,
"r": 0.5,
}
return portrayal
SIZE = 10
grid = CanvasGrid(agent_portrayal, SIZE, SIZE, 500, 500)
server = ModularServer(BowenModel, [grid], "BowenModel", {})
if __name__ == "__main__":
import os
server.launch()
os.system(f'open "https://localhost:{server.port}"')