1
0
mirror of https://github.com/balkian/gists.git synced 2024-11-24 02:12:29 +00:00
gists/repos/887c5b163f5359a6a13a7858e7f484d4/prueba.py

18 lines
488 B
Python
Raw Normal View History

2017-06-20 09:51:56 +00:00
NEUTRAL = 0
INFECTED = 1
2017-06-20 09:49:08 +00:00
class ControlModelM2(BaseBehaviour):
NEUTRAL = 0
INFECTED = 1
def step(self, now):
2017-06-20 09:51:56 +00:00
if self.state['id'] == NEUTRAL:
2017-06-20 09:49:08 +00:00
self.neutral_behaviour()
2017-06-20 09:51:56 +00:00
elif self.state['id'] == INFECTED:
2017-06-20 09:49:08 +00:00
self.infected_behaviour()
def infected_behaviour(self):
2017-06-20 09:51:56 +00:00
neutral_neighbors = self.get_neighboring_agents(state_id=INFECTED)
2017-06-20 09:49:08 +00:00
for neighbor in neutral_neighbors:
if random.random() < self.prob_infect:
2017-06-20 09:51:56 +00:00
neighbor.state['id'] = INFECTED