mirror of
https://github.com/gsi-upm/soil
synced 2024-11-14 15:32:29 +00:00
e1be3a730e
* Pandas integration * Improved environment * Logging and data dumps * Tests * Added Finite State Machine models * Rewritten ipython notebook and documentation
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
|