mirror of
https://github.com/gsi-upm/soil
synced 2024-11-13 06:52:28 +00:00
Paper model 1
This commit is contained in:
parent
ae01656ac3
commit
a321823078
@ -59,6 +59,7 @@ class ComportamientoBase(BaseNetworkAgent):
|
||||
class SpreadModelM2(ComportamientoBase):
|
||||
init_states[random.randint(0,settings.number_of_nodes)] = {'id':1}
|
||||
init_states[random.randint(0,settings.number_of_nodes)] = {'id':1}
|
||||
init_states[random.randint(0,settings.number_of_nodes)] = {'id': 1}
|
||||
def __init__(self, environment=None, agent_id=0, state=()):
|
||||
super().__init__(environment=environment, agent_id=agent_id, state=state)
|
||||
|
||||
@ -125,6 +126,7 @@ class SpreadModelM2(ComportamientoBase):
|
||||
for neighbor in infected_neighbors:
|
||||
if random.random() < self.prob_cured_healing_infected:
|
||||
neighbor.state['id'] = 2 # Cured
|
||||
return
|
||||
|
||||
# Vaccinate
|
||||
neutral_neighbors = self.get_neighboring_agents(state_id=0)
|
||||
@ -133,9 +135,11 @@ class SpreadModelM2(ComportamientoBase):
|
||||
neighbor.state['id'] = 3 # Vaccinated
|
||||
|
||||
# Generate anti-rumor
|
||||
infected_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
for neighbor in infected_neighbors:
|
||||
if random.random() < self.prob_generate_anti_rumor:
|
||||
neighbor.state['id'] = 2 # Cured
|
||||
return
|
||||
|
||||
|
||||
class SISaModel(ComportamientoBase):
|
||||
|
16
settings.py
16
settings.py
@ -40,7 +40,7 @@ def init():
|
||||
global prob_generate_anti_rumor
|
||||
|
||||
network_type=1
|
||||
number_of_nodes=1000
|
||||
number_of_nodes=100
|
||||
max_time=500
|
||||
num_trials=1
|
||||
timeout=20
|
||||
@ -88,16 +88,16 @@ def init():
|
||||
standard_variance = 0.055
|
||||
|
||||
#Spread Model M2
|
||||
prob_neutral_making_denier = 0.055
|
||||
prob_neutral_making_denier = 0.035
|
||||
|
||||
prob_infect = 0.1
|
||||
prob_infect = 0.075
|
||||
|
||||
prob_cured_healing_infected = 0.055
|
||||
prob_cured_vaccinate_neutral = 0.055
|
||||
prob_cured_healing_infected = 0.035
|
||||
prob_cured_vaccinate_neutral = 0.035
|
||||
|
||||
prob_vaccinated_healing_infected = 0.055
|
||||
prob_vaccinated_vaccinate_neutral = 0.055
|
||||
prob_generate_anti_rumor = 0.055
|
||||
prob_vaccinated_healing_infected = 0.035
|
||||
prob_vaccinated_vaccinate_neutral = 0.035
|
||||
prob_generate_anti_rumor = 0.035
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
32
soil.py
32
soil.py
@ -37,26 +37,48 @@ sim.run_simulation()
|
||||
# Results #
|
||||
###########
|
||||
x_values = []
|
||||
y_values = []
|
||||
infected_values = []
|
||||
neutral_values = []
|
||||
cured_values = []
|
||||
vaccinated_values = []
|
||||
|
||||
attribute_plot = 'status'
|
||||
for time in range(0, settings.max_time):
|
||||
value = settings.sentiment_about[0]
|
||||
value_infectados = 0
|
||||
value_neutral = 0
|
||||
value_cured = 0
|
||||
value_vaccinated = 0
|
||||
real_time = time * settings.timeout
|
||||
activity= False
|
||||
for x in range(0, settings.number_of_nodes):
|
||||
if attribute_plot in models.networkStatus["agente_%s" % x]:
|
||||
if real_time in models.networkStatus["agente_%s" % x][attribute_plot]:
|
||||
if models.networkStatus["agente_%s" % x][attribute_plot][real_time] == 1: ##Representar infectados
|
||||
value += 1
|
||||
value_infectados += 1
|
||||
activity = True
|
||||
if models.networkStatus["agente_%s" % x][attribute_plot][real_time] == 0: ##Representar neutrales
|
||||
value_neutral += 1
|
||||
activity = True
|
||||
if models.networkStatus["agente_%s" % x][attribute_plot][real_time] == 2: ##Representar cured
|
||||
value_cured += 1
|
||||
activity = True
|
||||
if models.networkStatus["agente_%s" % x][attribute_plot][real_time] == 3: ##Representar vaccinated
|
||||
value_vaccinated += 1
|
||||
activity = True
|
||||
|
||||
if activity:
|
||||
x_values.append(real_time)
|
||||
y_values.append(value)
|
||||
infected_values.append(value_infectados)
|
||||
neutral_values.append(value_neutral)
|
||||
cured_values.append(value_cured)
|
||||
vaccinated_values.append(value_vaccinated)
|
||||
activity=False
|
||||
|
||||
plt.plot(x_values,y_values)
|
||||
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.show()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user