mirror of
https://github.com/gsi-upm/soil
synced 2024-11-25 04:12:29 +00:00
Visualizacion con dos parametros, sentimientos negativos y positivos.
This commit is contained in:
parent
99090b1494
commit
cf1dedf459
Binary file not shown.
@ -21,7 +21,7 @@ def init():
|
|||||||
global tweet_probability_enterprises
|
global tweet_probability_enterprises
|
||||||
|
|
||||||
network_type=1
|
network_type=1
|
||||||
number_of_nodes=200
|
number_of_nodes=50
|
||||||
max_time=1000
|
max_time=1000
|
||||||
num_trials=1
|
num_trials=1
|
||||||
timeout=10
|
timeout=10
|
||||||
@ -45,8 +45,8 @@ def init():
|
|||||||
##Users
|
##Users
|
||||||
tweet_probability_users = 0.44
|
tweet_probability_users = 0.44
|
||||||
tweet_relevant_probability = 0.25
|
tweet_relevant_probability = 0.25
|
||||||
tweet_probability_about = [0, 0]
|
tweet_probability_about = [0.25, 0.25]
|
||||||
sentiment_about = [0, 0] #Valores por defecto
|
sentiment_about = [0, 0] #Valores por defecto
|
||||||
##Enterprises
|
##Enterprises
|
||||||
tweet_probability_enterprises = [0.5, 0.5]
|
tweet_probability_enterprises = [0.3, 0.3]
|
||||||
|
|
||||||
|
Binary file not shown.
80
soil.py
80
soil.py
@ -31,9 +31,14 @@ if settings.network_type == 2:
|
|||||||
myList=[] # List just for debugging
|
myList=[] # List just for debugging
|
||||||
networkStatus=[] # This list will contain the status of every node of the network
|
networkStatus=[] # This list will contain the status of every node of the network
|
||||||
emotionStatus=[]
|
emotionStatus=[]
|
||||||
|
enterprise1Status=[]
|
||||||
|
enterprise2Status=[]
|
||||||
for x in range(0, settings.number_of_nodes):
|
for x in range(0, settings.number_of_nodes):
|
||||||
networkStatus.append({'id':x})
|
networkStatus.append({'id':x})
|
||||||
emotionStatus.append({'id':x})
|
emotionStatus.append({'id':x})
|
||||||
|
enterprise1Status.append({'id':x})
|
||||||
|
enterprise2Status.append({'id':x})
|
||||||
|
|
||||||
|
|
||||||
# Initialize agent states. Let's assume everyone is normal.
|
# Initialize agent states. Let's assume everyone is normal.
|
||||||
init_states = [{'id': 0, } for _ in range(settings.number_of_nodes)] # add keys as as necessary, but "id" must always refer to that state category
|
init_states = [{'id': 0, } for _ in range(settings.number_of_nodes)] # add keys as as necessary, but "id" must always refer to that state category
|
||||||
@ -69,15 +74,16 @@ class BigMarketModel(BaseNetworkAgent):
|
|||||||
self.tweet_probability_about = settings.tweet_probability_about #Lista
|
self.tweet_probability_about = settings.tweet_probability_about #Lista
|
||||||
self.sentiment_about = settings.sentiment_about #Lista
|
self.sentiment_about = settings.sentiment_about #Lista
|
||||||
|
|
||||||
networkStatus[self.id][self.env.now]=self.state['id']
|
#networkStatus[self.id][self.env.now]=self.state['id']
|
||||||
emotionStatus[self.id][self.env.now]=0
|
#emotionStatus[self.id][self.env.now]=0
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
if(self.id < 2): # Empresa
|
if(self.id < 2): # Empresa
|
||||||
self.enterpriseBehaviour()
|
self.enterpriseBehaviour()
|
||||||
else: # Usuario
|
else: # Usuario
|
||||||
self.userBehaviour()
|
#self.userBehaviour()
|
||||||
|
pass
|
||||||
yield self.env.timeout(settings.timeout)
|
yield self.env.timeout(settings.timeout)
|
||||||
|
|
||||||
|
|
||||||
@ -88,16 +94,21 @@ class BigMarketModel(BaseNetworkAgent):
|
|||||||
aware_neighbors = self.get_neighboring_agents(state_id=2) #Nodos vecinos usuarios
|
aware_neighbors = self.get_neighboring_agents(state_id=2) #Nodos vecinos usuarios
|
||||||
for x in aware_neighbors:
|
for x in aware_neighbors:
|
||||||
if random.uniform(0,10) < 5:
|
if random.uniform(0,10) < 5:
|
||||||
x.sentiment_about[self.id] += 0.01 #Aumenta para empresa
|
x.sentiment_about[self.id] += 0.1 #Aumenta para empresa
|
||||||
else:
|
else:
|
||||||
x.sentiment_about[self.id] -= 0.01 #Reduce para empresa
|
x.sentiment_about[self.id] -= 0.1 #Reduce para empresa
|
||||||
|
|
||||||
# Establecemos limites
|
# Establecemos limites
|
||||||
if x.sentiment_about[self.id] > 1:
|
if x.sentiment_about[self.id] > 1:
|
||||||
x.sentiment_about[self.id] = 1
|
x.sentiment_about[self.id] = 1
|
||||||
if x.sentiment_about[self.id] < -1:
|
if x.sentiment_about[self.id] < -1:
|
||||||
x.sentiment_about[self.id] = -1
|
x.sentiment_about[self.id] = -1
|
||||||
#Guardamos estado para visualizacion
|
|
||||||
emotionStatus[x.id][self.env.now]=x.sentiment_about[self.id]
|
#Visualización
|
||||||
|
if self.id == 0:
|
||||||
|
enterprise1Status[x.id][self.env.now]=x.sentiment_about[self.id]
|
||||||
|
if self.id == 1:
|
||||||
|
enterprise2Status[x.id][self.env.now]=x.sentiment_about[self.id]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -106,7 +117,6 @@ class BigMarketModel(BaseNetworkAgent):
|
|||||||
|
|
||||||
if random.random() < self.tweet_probability: #Twittea
|
if random.random() < self.tweet_probability: #Twittea
|
||||||
if random.random() < self.tweet_relevant_probability: #Twittea algo relevante
|
if random.random() < self.tweet_relevant_probability: #Twittea algo relevante
|
||||||
|
|
||||||
#Probabilidad de tweet para cada empresa
|
#Probabilidad de tweet para cada empresa
|
||||||
for i in range(len(self.tweet_probability_about)):
|
for i in range(len(self.tweet_probability_about)):
|
||||||
random_num = random.random()
|
random_num = random.random()
|
||||||
@ -122,16 +132,37 @@ class BigMarketModel(BaseNetworkAgent):
|
|||||||
#POSITIVO
|
#POSITIVO
|
||||||
self.userTweets("positive",i)
|
self.userTweets("positive",i)
|
||||||
|
|
||||||
|
|
||||||
def userTweets(self,sentiment,enterprise):
|
def userTweets(self,sentiment,enterprise):
|
||||||
aware_neighbors = self.get_neighboring_agents(state_id=2) #Nodos vecinos usuarios
|
aware_neighbors = self.get_neighboring_agents(state_id=2) #Nodos vecinos usuarios
|
||||||
for x in aware_neighbors:
|
for x in aware_neighbors:
|
||||||
if sentiment == "positive":
|
if sentiment == "positive":
|
||||||
x.sentiment_about[enterprise] +=0
|
x.sentiment_about[enterprise] +=0.003
|
||||||
elif sentiment == "negative":
|
elif sentiment == "negative":
|
||||||
x.sentiment_about[enterprise] -=0
|
x.sentiment_about[enterprise] -=0.003
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Establecemos limites
|
||||||
|
if x.sentiment_about[enterprise] > 1:
|
||||||
|
x.sentiment_about[enterprise] = 1
|
||||||
|
if x.sentiment_about[enterprise] < -1:
|
||||||
|
x.sentiment_about[enterprise] = -1
|
||||||
|
|
||||||
|
#Visualización
|
||||||
|
if enterprise == 0:
|
||||||
|
enterprise1Status[x.id][self.env.now]=x.sentiment_about[enterprise]
|
||||||
|
if enterprise == 1:
|
||||||
|
enterprise2Status[x.id][self.env.now]=x.sentiment_about[enterprise]
|
||||||
|
|
||||||
|
|
||||||
|
def checkLimits(sentimentValue):
|
||||||
|
if sentimentValue > 1:
|
||||||
|
return 1
|
||||||
|
if sentimentValue < -1:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -372,14 +403,37 @@ status_census = [sum([1 for node_id, state in g.items() if state['id'] == 1]) fo
|
|||||||
# Visualization #
|
# Visualization #
|
||||||
#################
|
#################
|
||||||
|
|
||||||
|
print("Empresa1")
|
||||||
|
print (enterprise1Status)
|
||||||
|
print("Empresa2")
|
||||||
|
print (enterprise2Status)
|
||||||
|
|
||||||
for x in range(0, settings.number_of_nodes):
|
for x in range(0, settings.number_of_nodes):
|
||||||
emotionStatusAux=[]
|
emotionStatusAux=[]
|
||||||
for tiempo in emotionStatus[x]:
|
|
||||||
|
# for tiempo in emotionStatus[x]:
|
||||||
|
# if tiempo != 'id':
|
||||||
|
# prec = 2
|
||||||
|
# output = math.floor(emotionStatus[x][tiempo] * (10 ** prec)) / (10 ** prec) #Para tener 2 decimales solo
|
||||||
|
# emotionStatusAux.append((output,tiempo,None))
|
||||||
|
# G.add_node(x, emotion= emotionStatusAux)
|
||||||
|
# del emotionStatusAux[:]
|
||||||
|
for tiempo in enterprise1Status[x]:
|
||||||
if tiempo != 'id':
|
if tiempo != 'id':
|
||||||
prec = 2
|
prec = 2
|
||||||
output = math.floor(emotionStatus[x][tiempo] * (10 ** prec)) / (10 ** prec) #Para tener 2 decimales solo
|
output = math.floor(enterprise1Status[x][tiempo] * (10 ** prec)) / (10 ** prec) #Para tener 2 decimales solo
|
||||||
emotionStatusAux.append((output,tiempo,None))
|
emotionStatusAux.append((output,tiempo,None))
|
||||||
G.add_node(x, emotion= emotionStatusAux)
|
G.add_node(x, enterprise1emotion= emotionStatusAux)
|
||||||
|
|
||||||
|
for x in range(0, settings.number_of_nodes):
|
||||||
|
emotionStatusAux2=[]
|
||||||
|
for tiempo in enterprise2Status[x]:
|
||||||
|
if tiempo != 'id':
|
||||||
|
prec = 2
|
||||||
|
output = math.floor(enterprise2Status[x][tiempo] * (10 ** prec)) / (10 ** prec) #Para tener 2 decimales solo
|
||||||
|
emotionStatusAux2.append((output,tiempo,None))
|
||||||
|
G.add_node(x, enterprise2emotion= emotionStatusAux2)
|
||||||
|
|
||||||
|
|
||||||
#lista = nx.nodes(G)
|
#lista = nx.nodes(G)
|
||||||
#print('Nodos: ' + str(lista))
|
#print('Nodos: ' + str(lista))
|
||||||
|
BIN
status.png
BIN
status.png
Binary file not shown.
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 13 KiB |
Loading…
Reference in New Issue
Block a user