|
|
|
@ -26,8 +26,8 @@ if settings.network_type == 2:
|
|
|
|
|
# Simulation #
|
|
|
|
|
##############
|
|
|
|
|
|
|
|
|
|
sim = NetworkSimulation(topology=G, states=init_states, agent_type=ControlModelM2,
|
|
|
|
|
max_time=settings.max_time, num_trials=settings.num_trials, logging_interval=1.0)
|
|
|
|
|
sim = NetworkSimulation(topology=G, states=init_states, agent_type=ControlModelM2, max_time=settings.max_time,
|
|
|
|
|
num_trials=settings.num_trials, logging_interval=1.0, **settings.environment_params)
|
|
|
|
|
|
|
|
|
|
sim.run_simulation()
|
|
|
|
|
|
|
|
|
@ -49,14 +49,14 @@ for time in range(0, settings.max_time):
|
|
|
|
|
value_cured = 0
|
|
|
|
|
value_vaccinated = 0
|
|
|
|
|
real_time = time * settings.timeout
|
|
|
|
|
activity= False
|
|
|
|
|
activity = False
|
|
|
|
|
for x in range(0, settings.number_of_nodes):
|
|
|
|
|
if attribute_plot in models.networkStatus["agent_%s" % x]:
|
|
|
|
|
if real_time in models.networkStatus["agent_%s" % x][attribute_plot]:
|
|
|
|
|
if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 1: ## Infected
|
|
|
|
|
value_infectados += 1
|
|
|
|
|
activity = True
|
|
|
|
|
if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 0: ## Neutral
|
|
|
|
|
if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 0: ## Neutral
|
|
|
|
|
value_neutral += 1
|
|
|
|
|
activity = True
|
|
|
|
|
if models.networkStatus["agent_%s" % x][attribute_plot][real_time] == 2: ## Cured
|
|
|
|
@ -72,12 +72,12 @@ for time in range(0, settings.max_time):
|
|
|
|
|
neutral_values.append(value_neutral)
|
|
|
|
|
cured_values.append(value_cured)
|
|
|
|
|
vaccinated_values.append(value_vaccinated)
|
|
|
|
|
activity=False
|
|
|
|
|
activity = False
|
|
|
|
|
|
|
|
|
|
infected_line = plt.plot(x_values,infected_values,label='Infected')
|
|
|
|
|
neutral_line = plt.plot(x_values,neutral_values, label='Neutral')
|
|
|
|
|
cured_line = plt.plot(x_values,cured_values, label='Cured')
|
|
|
|
|
vaccinated_line = plt.plot(x_values,vaccinated_values, label='Vaccinated')
|
|
|
|
|
infected_line = plt.plot(x_values, infected_values, label='Infected')
|
|
|
|
|
neutral_line = plt.plot(x_values, neutral_values, label='Neutral')
|
|
|
|
|
cured_line = plt.plot(x_values, cured_values, label='Cured')
|
|
|
|
|
vaccinated_line = plt.plot(x_values, vaccinated_values, label='Vaccinated')
|
|
|
|
|
plt.legend()
|
|
|
|
|
plt.savefig('control_model.png')
|
|
|
|
|
# plt.show()
|
|
|
|
@ -88,12 +88,12 @@ plt.savefig('control_model.png')
|
|
|
|
|
#################
|
|
|
|
|
|
|
|
|
|
for x in range(0, settings.number_of_nodes):
|
|
|
|
|
for attribute in models.networkStatus["agent_%s"%x]:
|
|
|
|
|
emotionStatusAux=[]
|
|
|
|
|
for t_step in models.networkStatus["agent_%s"%x][attribute]:
|
|
|
|
|
for attribute in models.networkStatus["agent_%s" % x]:
|
|
|
|
|
emotionStatusAux = []
|
|
|
|
|
for t_step in models.networkStatus["agent_%s" % x][attribute]:
|
|
|
|
|
prec = 2
|
|
|
|
|
output = math.floor(models.networkStatus["agent_%s"%x][attribute][t_step] * (10 ** prec)) / (10 ** prec) # 2 decimals
|
|
|
|
|
emotionStatusAux.append((output,t_step,None))
|
|
|
|
|
output = math.floor(models.networkStatus["agent_%s" % x][attribute][t_step] * (10 ** prec)) / (10 ** prec) # 2 decimals
|
|
|
|
|
emotionStatusAux.append((output, t_step,None))
|
|
|
|
|
attributes = {}
|
|
|
|
|
attributes[attribute] = emotionStatusAux
|
|
|
|
|
G.add_node(x, attributes)
|
|
|
|
@ -104,5 +104,4 @@ print("Done!")
|
|
|
|
|
with open('data.txt', 'w') as outfile:
|
|
|
|
|
json.dump(models.networkStatus, outfile, sort_keys=True, indent=4, separators=(',', ': '))
|
|
|
|
|
|
|
|
|
|
nx.write_gexf(G,"test.gexf", version="1.2draft")
|
|
|
|
|
|
|
|
|
|
nx.write_gexf(G, "test.gexf", version="1.2draft")
|
|
|
|
|