5
5
6
6
class EpsteinAgent (mesa .experimental .cell_space .CellAgent ):
7
7
def update_neighbors (self ):
8
- """
9
- Look around and see who my neighbors are
10
- """
8
+ """Look around and see who my neighbors are"""
11
9
self .neighborhood = self .cell .get_neighborhood (radius = self .vision )
12
10
13
11
self .neighbors = self .neighborhood .agents
14
12
self .empty_neighbors = [c for c in self .neighborhood if c .is_empty ]
15
13
16
14
17
15
class Citizen (EpsteinAgent ):
18
- """
19
- A member of the general population, may or may not be in active rebellion.
16
+ """A member of the general population, may or may not be in active rebellion.
20
17
Summary of rule: If grievance - risk > threshold, rebel.
21
18
22
19
Attributes:
@@ -46,8 +43,8 @@ def __init__(
46
43
threshold ,
47
44
vision ,
48
45
):
49
- """
50
- Create a new Citizen.
46
+ """Create a new Citizen.
47
+
51
48
Args:
52
49
model: the model to which the agent belongs
53
50
hardship: Agent's 'perceived hardship (i.e., physical or economic
@@ -73,9 +70,7 @@ def __init__(
73
70
self .arrest_probability = None
74
71
75
72
def step (self ):
76
- """
77
- Decide whether to activate, then move if applicable.
78
- """
73
+ """Decide whether to activate, then move if applicable."""
79
74
if self .jail_sentence :
80
75
self .jail_sentence -= 1
81
76
return # no other changes or movements if agent is in jail.
@@ -92,8 +87,7 @@ def step(self):
92
87
self .move_to (new_cell )
93
88
94
89
def update_estimated_arrest_probability (self ):
95
- """
96
- Based on the ratio of cops to actives in my neighborhood, estimate the
90
+ """Based on the ratio of cops to actives in my neighborhood, estimate the
97
91
p(Arrest | I go active).
98
92
"""
99
93
cops_in_vision = len ([c for c in self .neighbors if isinstance (c , Cop )])
@@ -111,8 +105,7 @@ def update_estimated_arrest_probability(self):
111
105
112
106
113
107
class Cop (EpsteinAgent ):
114
- """
115
- A cop for life. No defection.
108
+ """A cop for life. No defection.
116
109
Summary of rule: Inspect local vision and arrest a random active agent.
117
110
118
111
Attributes:
@@ -123,8 +116,8 @@ class Cop(EpsteinAgent):
123
116
"""
124
117
125
118
def __init__ (self , model , vision ):
126
- """
127
- Create a new Cop.
119
+ """Create a new Cop.
120
+
128
121
Args:
129
122
x, y: Grid coordinates
130
123
vision: number of cells in each direction (N, S, E and W) that
@@ -135,8 +128,7 @@ def __init__(self, model, vision):
135
128
self .vision = vision
136
129
137
130
def step (self ):
138
- """
139
- Inspect local vision and arrest a random active agent. Move if
131
+ """Inspect local vision and arrest a random active agent. Move if
140
132
applicable.
141
133
"""
142
134
self .update_neighbors ()
0 commit comments