mirror of
https://github.com/gsi-upm/soil
synced 2025-08-23 19:52:19 +00:00
Settings modules
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import settings
|
||||
import random
|
||||
from ..BaseBehaviour import *
|
||||
from .. import sentimentCorrelationNodeArray
|
||||
|
||||
settings.init()
|
||||
|
||||
|
||||
class SentimentCorrelationModel(BaseBehaviour):
|
||||
"""
|
||||
@@ -22,15 +19,15 @@ class SentimentCorrelationModel(BaseBehaviour):
|
||||
|
||||
def __init__(self, environment=None, agent_id=0, state=()):
|
||||
super().__init__(environment=environment, agent_id=agent_id, state=state)
|
||||
self.outside_effects_prob = settings.outside_effects_prob
|
||||
self.anger_prob = settings.anger_prob
|
||||
self.joy_prob = settings.joy_prob
|
||||
self.sadness_prob = settings.sadness_prob
|
||||
self.disgust_prob = settings.disgust_prob
|
||||
self.time_awareness=[]
|
||||
for i in range(4): #In this model we have 4 sentiments
|
||||
self.time_awareness.append(0) #0-> Anger, 1-> joy, 2->sadness, 3 -> disgust
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=0
|
||||
self.outside_effects_prob = environment.outside_effects_prob
|
||||
self.anger_prob = environment.anger_prob
|
||||
self.joy_prob = environment.joy_prob
|
||||
self.sadness_prob = environment.sadness_prob
|
||||
self.disgust_prob = environment.disgust_prob
|
||||
self.time_awareness = []
|
||||
for i in range(4): # In this model we have 4 sentiments
|
||||
self.time_awareness.append(0) # 0-> Anger, 1-> joy, 2->sadness, 3 -> disgust
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now] = 0
|
||||
|
||||
def step(self, now):
|
||||
self.behaviour()
|
||||
@@ -38,10 +35,10 @@ class SentimentCorrelationModel(BaseBehaviour):
|
||||
|
||||
def behaviour(self):
|
||||
|
||||
angry_neighbors_1_time_step=[]
|
||||
joyful_neighbors_1_time_step=[]
|
||||
sad_neighbors_1_time_step=[]
|
||||
disgusted_neighbors_1_time_step=[]
|
||||
angry_neighbors_1_time_step = []
|
||||
joyful_neighbors_1_time_step = []
|
||||
sad_neighbors_1_time_step = []
|
||||
disgusted_neighbors_1_time_step = []
|
||||
|
||||
angry_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
for x in angry_neighbors:
|
||||
@@ -67,18 +64,18 @@ class SentimentCorrelationModel(BaseBehaviour):
|
||||
disgusted_neighbors_1_time_step.append(x)
|
||||
num_neighbors_disgusted = len(disgusted_neighbors_1_time_step)
|
||||
|
||||
anger_prob= settings.anger_prob+(len(angry_neighbors_1_time_step)*settings.anger_prob)
|
||||
joy_prob= settings.joy_prob+(len(joyful_neighbors_1_time_step)*settings.joy_prob)
|
||||
sadness_prob = settings.sadness_prob+(len(sad_neighbors_1_time_step)*settings.sadness_prob)
|
||||
disgust_prob = settings.disgust_prob+(len(disgusted_neighbors_1_time_step)*settings.disgust_prob)
|
||||
outside_effects_prob= settings.outside_effects_prob
|
||||
anger_prob = self.anger_prob+(len(angry_neighbors_1_time_step)*self.anger_prob)
|
||||
joy_prob = self.joy_prob+(len(joyful_neighbors_1_time_step)*self.joy_prob)
|
||||
sadness_prob = self.sadness_prob+(len(sad_neighbors_1_time_step)*self.sadness_prob)
|
||||
disgust_prob = self.disgust_prob+(len(disgusted_neighbors_1_time_step)*self.disgust_prob)
|
||||
outside_effects_prob = self.outside_effects_prob
|
||||
|
||||
num = random.random()
|
||||
|
||||
if(num<outside_effects_prob):
|
||||
if num<outside_effects_prob:
|
||||
self.state['id'] = random.randint(1,4)
|
||||
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=self.state['id'] #It is stored when it has been infected for the dynamic network
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=self.state['id'] # It is stored when it has been infected for the dynamic network
|
||||
self.time_awareness[self.state['id']-1] = self.env.now
|
||||
self.attrs['sentiment'] = self.state['id']
|
||||
|
||||
@@ -95,13 +92,11 @@ class SentimentCorrelationModel(BaseBehaviour):
|
||||
self.time_awareness[self.state['id']-1] = self.env.now
|
||||
elif (num<sadness_prob+anger_prob+joy_prob and num>joy_prob+anger_prob):
|
||||
|
||||
|
||||
self.state['id'] = 3
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=3
|
||||
self.time_awareness[self.state['id']-1] = self.env.now
|
||||
elif (num<disgust_prob+sadness_prob+anger_prob+joy_prob and num>sadness_prob+anger_prob+joy_prob):
|
||||
|
||||
|
||||
self.state['id'] = 4
|
||||
sentimentCorrelationNodeArray[self.id][self.env.now]=4
|
||||
self.time_awareness[self.state['id']-1] = self.env.now
|
||||
|
Reference in New Issue
Block a user