mirror of https://github.com/balkian/gists
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
488 B
Python
18 lines
488 B
Python
7 years ago
|
NEUTRAL = 0
|
||
|
INFECTED = 1
|
||
|
|
||
7 years ago
|
class ControlModelM2(BaseBehaviour):
|
||
|
NEUTRAL = 0
|
||
|
INFECTED = 1
|
||
|
def step(self, now):
|
||
7 years ago
|
if self.state['id'] == NEUTRAL:
|
||
7 years ago
|
self.neutral_behaviour()
|
||
7 years ago
|
elif self.state['id'] == INFECTED:
|
||
7 years ago
|
self.infected_behaviour()
|
||
|
…
|
||
|
def infected_behaviour(self):
|
||
7 years ago
|
neutral_neighbors = self.get_neighboring_agents(state_id=INFECTED)
|
||
7 years ago
|
for neighbor in neutral_neighbors:
|
||
|
if random.random() < self.prob_infect:
|
||
7 years ago
|
neighbor.state['id'] = INFECTED
|