mirror of
https://github.com/gsi-upm/soil
synced 2024-11-24 11:52:29 +00:00
21 lines
598 B
Python
21 lines
598 B
Python
|
import soil
|
||
|
import random
|
||
|
|
||
|
class NewsSpread(soil.agents.FSM):
|
||
|
@soil.agents.default_state
|
||
|
@soil.agents.state
|
||
|
def neutral(self):
|
||
|
r = random.random()
|
||
|
if self['has_tv'] and r < self.env['prob_tv_spread']:
|
||
|
return self.infected
|
||
|
return
|
||
|
|
||
|
@soil.agents.state
|
||
|
def infected(self):
|
||
|
prob_infect = self.env['prob_neighbor_spread']
|
||
|
for neighbor in self.get_neighboring_agents(state_id=self.neutral.id):
|
||
|
r = random.random()
|
||
|
if r < prob_infect:
|
||
|
neighbor.state['id'] = self.infected.id
|
||
|
return
|