mirror of
https://github.com/gsi-upm/soil
synced 2024-11-25 04:12:29 +00:00
Control model M2 implemented
This commit is contained in:
parent
4c71949d44
commit
038d388afd
BIN
control_model.png
Normal file
BIN
control_model.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
112
models.py
112
models.py
@ -56,6 +56,118 @@ class ComportamientoBase(BaseNetworkAgent):
|
||||
final[a][stamp] = attrs[a]
|
||||
return final
|
||||
|
||||
class ControlModelM2(ComportamientoBase):
|
||||
#Init infected
|
||||
init_states[random.randint(0,settings.number_of_nodes-1)] = {'id':1}
|
||||
init_states[random.randint(0,settings.number_of_nodes-1)] = {'id':1}
|
||||
|
||||
# Init beacons
|
||||
init_states[random.randint(0, settings.number_of_nodes-1)] = {'id': 4}
|
||||
init_states[random.randint(0, settings.number_of_nodes-1)] = {'id': 4}
|
||||
def __init__(self, environment=None, agent_id=0, state=()):
|
||||
super().__init__(environment=environment, agent_id=agent_id, state=state)
|
||||
|
||||
self.prob_neutral_making_denier = np.random.normal(settings.prob_neutral_making_denier, settings.standard_variance)
|
||||
|
||||
self.prob_infect = np.random.normal(settings.prob_infect, settings.standard_variance)
|
||||
|
||||
self.prob_cured_healing_infected = np.random.normal(settings.prob_cured_healing_infected, settings.standard_variance)
|
||||
self.prob_cured_vaccinate_neutral = np.random.normal(settings.prob_cured_vaccinate_neutral, settings.standard_variance)
|
||||
|
||||
self.prob_vaccinated_healing_infected = np.random.normal(settings.prob_vaccinated_healing_infected, settings.standard_variance)
|
||||
self.prob_vaccinated_vaccinate_neutral = np.random.normal(settings.prob_vaccinated_vaccinate_neutral, settings.standard_variance)
|
||||
self.prob_generate_anti_rumor = np.random.normal(settings.prob_generate_anti_rumor, settings.standard_variance)
|
||||
|
||||
def step(self, now):
|
||||
|
||||
if self.state['id'] == 0: #Neutral
|
||||
self.neutral_behaviour()
|
||||
elif self.state['id'] == 1: #Infected
|
||||
self.infected_behaviour()
|
||||
elif self.state['id'] == 2: #Cured
|
||||
self.cured_behaviour()
|
||||
elif self.state['id'] == 3: #Vaccinated
|
||||
self.vaccinated_behaviour()
|
||||
elif self.state['id'] == 4: #Beacon-off
|
||||
self.beacon_off_behaviour()
|
||||
elif self.state['id'] == 5: #Beacon-on
|
||||
self.beacon_on_behaviour()
|
||||
|
||||
self.attrs['status'] = self.state['id']
|
||||
super().step(now)
|
||||
|
||||
|
||||
def neutral_behaviour(self):
|
||||
|
||||
# Infected
|
||||
infected_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
if len(infected_neighbors)>0:
|
||||
if random.random() < self.prob_neutral_making_denier:
|
||||
self.state['id'] = 3 # Vaccinated making denier
|
||||
|
||||
def infected_behaviour(self):
|
||||
|
||||
# Neutral
|
||||
neutral_neighbors = self.get_neighboring_agents(state_id=0)
|
||||
for neighbor in neutral_neighbors:
|
||||
if random.random() < self.prob_infect:
|
||||
neighbor.state['id'] = 1 # Infected
|
||||
|
||||
def cured_behaviour(self):
|
||||
|
||||
# Vaccinate
|
||||
neutral_neighbors = self.get_neighboring_agents(state_id=0)
|
||||
for neighbor in neutral_neighbors:
|
||||
if random.random() < self.prob_cured_vaccinate_neutral:
|
||||
neighbor.state['id'] = 3 # Vaccinated
|
||||
|
||||
# Cure
|
||||
infected_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
for neighbor in infected_neighbors:
|
||||
if random.random() < self.prob_cured_healing_infected:
|
||||
neighbor.state['id'] = 2 # Cured
|
||||
|
||||
|
||||
def vaccinated_behaviour(self):
|
||||
|
||||
# Cure
|
||||
infected_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
for neighbor in infected_neighbors:
|
||||
if random.random() < self.prob_cured_healing_infected:
|
||||
neighbor.state['id'] = 2 # Cured
|
||||
|
||||
|
||||
# Vaccinate
|
||||
neutral_neighbors = self.get_neighboring_agents(state_id=0)
|
||||
for neighbor in neutral_neighbors:
|
||||
if random.random() < self.prob_cured_vaccinate_neutral:
|
||||
neighbor.state['id'] = 3 # Vaccinated
|
||||
|
||||
# Generate anti-rumor
|
||||
infected_neighbors_2 = self.get_neighboring_agents(state_id=1)
|
||||
for neighbor in infected_neighbors_2:
|
||||
if random.random() < self.prob_generate_anti_rumor:
|
||||
neighbor.state['id'] = 2 # Cured
|
||||
|
||||
def beacon_off_behaviour(self):
|
||||
infected_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
if len(infected_neighbors) > 0:
|
||||
self.state['id'] == 5 #Beacon on
|
||||
|
||||
def beacon_on_behaviour(self):
|
||||
|
||||
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
|
||||
|
||||
# Vaccinate
|
||||
neutral_neighbors = self.get_neighboring_agents(state_id=0)
|
||||
for neighbor in neutral_neighbors:
|
||||
if random.random() < self.prob_cured_vaccinate_neutral:
|
||||
neighbor.state['id'] = 3 # Vaccinated
|
||||
|
||||
|
||||
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}
|
||||
|
@ -40,10 +40,10 @@ def init():
|
||||
global prob_generate_anti_rumor
|
||||
|
||||
network_type=1
|
||||
number_of_nodes=20
|
||||
number_of_nodes=1000
|
||||
max_time=50
|
||||
num_trials=1
|
||||
timeout=1
|
||||
timeout=2
|
||||
|
||||
#Zombie model
|
||||
bite_prob=0.01 # 0-1
|
||||
@ -87,7 +87,7 @@ def init():
|
||||
|
||||
standard_variance = 0.055
|
||||
|
||||
#Spread Model M2
|
||||
#Spread Model M2 and Control Model M2
|
||||
prob_neutral_making_denier = 0.035
|
||||
|
||||
prob_infect = 0.075
|
||||
|
Binary file not shown.
3
soil.py
3
soil.py
@ -79,7 +79,8 @@ 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()
|
||||
plt.savefig('spread_model.png')
|
||||
#plt.show()
|
||||
|
||||
|
||||
#################
|
||||
|
BIN
spread_model.png
Normal file
BIN
spread_model.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
Loading…
Reference in New Issue
Block a user