1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-13 23:12:28 +00:00

Visualizacion con dos parametros, sentimientos negativos y positivos.

This commit is contained in:
JesusMSM 2016-01-08 12:49:46 +01:00
parent 99090b1494
commit cf1dedf459
6 changed files with 790 additions and 13152 deletions

Binary file not shown.

View File

@ -21,7 +21,7 @@ def init():
global tweet_probability_enterprises
network_type=1
number_of_nodes=200
number_of_nodes=50
max_time=1000
num_trials=1
timeout=10
@ -45,8 +45,8 @@ def init():
##Users
tweet_probability_users = 0.44
tweet_relevant_probability = 0.25
tweet_probability_about = [0, 0]
tweet_probability_about = [0.25, 0.25]
sentiment_about = [0, 0] #Valores por defecto
##Enterprises
tweet_probability_enterprises = [0.5, 0.5]
tweet_probability_enterprises = [0.3, 0.3]

Binary file not shown.

80
soil.py
View File

@ -31,9 +31,14 @@ if settings.network_type == 2:
myList=[] # List just for debugging
networkStatus=[] # This list will contain the status of every node of the network
emotionStatus=[]
enterprise1Status=[]
enterprise2Status=[]
for x in range(0, settings.number_of_nodes):
networkStatus.append({'id':x})
emotionStatus.append({'id':x})
enterprise1Status.append({'id':x})
enterprise2Status.append({'id':x})
# 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
@ -69,15 +74,16 @@ class BigMarketModel(BaseNetworkAgent):
self.tweet_probability_about = settings.tweet_probability_about #Lista
self.sentiment_about = settings.sentiment_about #Lista
networkStatus[self.id][self.env.now]=self.state['id']
emotionStatus[self.id][self.env.now]=0
#networkStatus[self.id][self.env.now]=self.state['id']
#emotionStatus[self.id][self.env.now]=0
def run(self):
while True:
if(self.id < 2): # Empresa
self.enterpriseBehaviour()
else: # Usuario
self.userBehaviour()
#self.userBehaviour()
pass
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
for x in aware_neighbors:
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:
x.sentiment_about[self.id] -= 0.01 #Reduce para empresa
x.sentiment_about[self.id] -= 0.1 #Reduce para empresa
# Establecemos limites
if x.sentiment_about[self.id] > 1:
x.sentiment_about[self.id] = 1
if 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_relevant_probability: #Twittea algo relevante
#Probabilidad de tweet para cada empresa
for i in range(len(self.tweet_probability_about)):
random_num = random.random()
@ -122,16 +132,37 @@ class BigMarketModel(BaseNetworkAgent):
#POSITIVO
self.userTweets("positive",i)
def userTweets(self,sentiment,enterprise):
aware_neighbors = self.get_neighboring_agents(state_id=2) #Nodos vecinos usuarios
for x in aware_neighbors:
if sentiment == "positive":
x.sentiment_about[enterprise] +=0
x.sentiment_about[enterprise] +=0.003
elif sentiment == "negative":
x.sentiment_about[enterprise] -=0
x.sentiment_about[enterprise] -=0.003
else:
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 #
#################
print("Empresa1")
print (enterprise1Status)
print("Empresa2")
print (enterprise2Status)
for x in range(0, settings.number_of_nodes):
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':
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))
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)
#print('Nodos: ' + str(lista))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 13 KiB

13810
test.gexf

File diff suppressed because it is too large Load Diff