1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-25 04:12:29 +00:00
soil/models/BassModel/BassModel.py

47 lines
1.5 KiB
Python
Raw Normal View History

2017-04-20 11:36:17 +00:00
import random
from ..BaseBehaviour import *
from .. import sentimentCorrelationNodeArray
class BassModel(BaseBehaviour):
"""
Settings:
innovation_prob
imitation_prob
"""
def __init__(self, environment=None, agent_id=0, state=()):
super().__init__(environment=environment, agent_id=agent_id, state=state)
2017-04-24 10:55:00 +00:00
self.innovation_prob = environment.environment_params['innovation_prob']
self.imitation_prob = environment.environment_params['imitation_prob']
2017-04-21 11:55:42 +00:00
sentimentCorrelationNodeArray[self.id][self.env.now] = 0
2017-04-20 11:36:17 +00:00
def step(self, now):
self.behaviour()
super().step(now)
def behaviour(self):
# Outside effects
2017-04-21 11:55:42 +00:00
if random.random() < self.innovation_prob:
2017-04-20 11:36:17 +00:00
if self.state['id'] == 0:
self.state['id'] = 1
2017-04-21 11:55:42 +00:00
sentimentCorrelationNodeArray[self.id][self.env.now] = 1
2017-04-20 11:36:17 +00:00
else:
pass
self.attrs['status'] = self.state['id']
return
# Imitation effects
if self.state['id'] == 0:
aware_neighbors = self.get_neighboring_agents(state_id=1)
num_neighbors_aware = len(aware_neighbors)
2017-04-21 11:55:42 +00:00
if random.random() < (self.imitation_prob*num_neighbors_aware):
2017-04-20 11:36:17 +00:00
self.state['id'] = 1
2017-04-21 11:55:42 +00:00
sentimentCorrelationNodeArray[self.id][self.env.now] = 1
2017-04-20 11:36:17 +00:00
else:
pass
self.attrs['status'] = self.state['id']