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