mirror of
https://github.com/gsi-upm/soil
synced 2024-11-13 23:12:28 +00:00
Fixed bug (nodes could change state twice in a step)
This commit is contained in:
parent
a321823078
commit
4c71949d44
15
models.py
15
models.py
@ -59,7 +59,6 @@ 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)
|
||||
|
||||
@ -78,11 +77,11 @@ class SpreadModelM2(ComportamientoBase):
|
||||
|
||||
if self.state['id'] == 0: #Neutral
|
||||
self.neutral_behaviour()
|
||||
if self.state['id'] == 1: #Infected
|
||||
elif self.state['id'] == 1: #Infected
|
||||
self.infected_behaviour()
|
||||
if self.state['id'] == 2: #Cured
|
||||
elif self.state['id'] == 2: #Cured
|
||||
self.cured_behaviour()
|
||||
if self.state['id'] == 3: #Vaccinated
|
||||
elif self.state['id'] == 3: #Vaccinated
|
||||
self.vaccinated_behaviour()
|
||||
|
||||
self.attrs['status'] = self.state['id']
|
||||
@ -119,6 +118,7 @@ class SpreadModelM2(ComportamientoBase):
|
||||
if random.random() < self.prob_cured_healing_infected:
|
||||
neighbor.state['id'] = 2 # Cured
|
||||
|
||||
|
||||
def vaccinated_behaviour(self):
|
||||
|
||||
# Cure
|
||||
@ -126,7 +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)
|
||||
@ -135,11 +135,10 @@ 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:
|
||||
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
|
||||
return
|
||||
|
||||
|
||||
class SISaModel(ComportamientoBase):
|
||||
|
@ -40,10 +40,10 @@ def init():
|
||||
global prob_generate_anti_rumor
|
||||
|
||||
network_type=1
|
||||
number_of_nodes=100
|
||||
max_time=500
|
||||
number_of_nodes=20
|
||||
max_time=50
|
||||
num_trials=1
|
||||
timeout=20
|
||||
timeout=1
|
||||
|
||||
#Zombie model
|
||||
bite_prob=0.01 # 0-1
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user