-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
48 lines (38 loc) · 1.28 KB
/
Copy pathmodel.py
File metadata and controls
48 lines (38 loc) · 1.28 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
#!/usr/bin/env python
# coding: utf-8
from mesa import Model
from mesa.time import RandomActivation
from mesa.space import MultiGrid
from mesa.datacollection import DataCollector
from agent import MoneyAgent
#saving propensity = lamda
#model
#saving propensity = lamda
class BoltzmannWealthModel(Model):
def __init__(self,T,N,lamda, width=10, height=10):
self.num_agents = N
self.T = T
self.grid = MultiGrid(height, width, True)
self.lamda = lamda
self.count = 0
self.schedule = RandomActivation(self)
self.datacollector = DataCollector(agent_reporters={ 'mi':'m'})
# Create agents
for i in range(self.num_agents):
a = MoneyAgent(i, self)
self.schedule.add(a)
# Add the agent to a random grid cell
x = self.random.randrange(self.grid.width)
y = self.random.randrange(self.grid.height)
self.grid.place_agent(a, (x, y))
self.running = True
self.datacollector.collect(self)
def step(self):
self.schedule.step()
# collect data
self.datacollector.collect(self)
def run_model(self, n):
for i in tqdm(range(1,n)):
self.count+=1
#print("step:{}".format(i))
self.step()