-
Notifications
You must be signed in to change notification settings - Fork 840
/
run_ascii.py
51 lines (42 loc) · 1.19 KB
/
run_ascii.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
from mesa.visualization.TextVisualization import (
TextData, TextGrid, TextVisualization
)
from model import Schelling
class SchellingTextVisualization(TextVisualization):
'''
ASCII visualization for schelling model
'''
def __init__(self, model):
'''
Create new Schelling ASCII visualization.
'''
self.model = model
grid_viz = TextGrid(self.model.grid, self.print_ascii_agent)
happy_viz = TextData(self.model, 'happy')
self.elements = [grid_viz, happy_viz]
@staticmethod
def print_ascii_agent(a):
'''
Minority agents are X, Majority are O.
'''
if a.type == 0:
return 'O'
if a.type == 1:
return 'X'
if __name__ == '__main__':
model_params = {
"height": 20,
"width": 20,
# Agent density, from 0.8 to 1.0
"density": 0.8,
# Fraction minority, from 0.2 to 1.0
"minority_pc": 0.2,
# Homophily, from 3 to 8
"homophily": 3
}
model = Schelling(**model_params)
viz = SchellingTextVisualization(model)
for i in range(10):
print("Step:", i)
viz.step()
print('---')