mirror of
https://github.com/gsi-upm/soil
synced 2024-11-22 11:12:29 +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):
|
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}
|
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=()):
|
def __init__(self, environment=None, agent_id=0, state=()):
|
||||||
super().__init__(environment=environment, agent_id=agent_id, state=state)
|
super().__init__(environment=environment, agent_id=agent_id, state=state)
|
||||||
|
|
||||||
@ -78,11 +77,11 @@ class SpreadModelM2(ComportamientoBase):
|
|||||||
|
|
||||||
if self.state['id'] == 0: #Neutral
|
if self.state['id'] == 0: #Neutral
|
||||||
self.neutral_behaviour()
|
self.neutral_behaviour()
|
||||||
if self.state['id'] == 1: #Infected
|
elif self.state['id'] == 1: #Infected
|
||||||
self.infected_behaviour()
|
self.infected_behaviour()
|
||||||
if self.state['id'] == 2: #Cured
|
elif self.state['id'] == 2: #Cured
|
||||||
self.cured_behaviour()
|
self.cured_behaviour()
|
||||||
if self.state['id'] == 3: #Vaccinated
|
elif self.state['id'] == 3: #Vaccinated
|
||||||
self.vaccinated_behaviour()
|
self.vaccinated_behaviour()
|
||||||
|
|
||||||
self.attrs['status'] = self.state['id']
|
self.attrs['status'] = self.state['id']
|
||||||
@ -119,6 +118,7 @@ class SpreadModelM2(ComportamientoBase):
|
|||||||
if random.random() < self.prob_cured_healing_infected:
|
if random.random() < self.prob_cured_healing_infected:
|
||||||
neighbor.state['id'] = 2 # Cured
|
neighbor.state['id'] = 2 # Cured
|
||||||
|
|
||||||
|
|
||||||
def vaccinated_behaviour(self):
|
def vaccinated_behaviour(self):
|
||||||
|
|
||||||
# Cure
|
# Cure
|
||||||
@ -126,7 +126,7 @@ class SpreadModelM2(ComportamientoBase):
|
|||||||
for neighbor in infected_neighbors:
|
for neighbor in infected_neighbors:
|
||||||
if random.random() < self.prob_cured_healing_infected:
|
if random.random() < self.prob_cured_healing_infected:
|
||||||
neighbor.state['id'] = 2 # Cured
|
neighbor.state['id'] = 2 # Cured
|
||||||
return
|
|
||||||
|
|
||||||
# Vaccinate
|
# Vaccinate
|
||||||
neutral_neighbors = self.get_neighboring_agents(state_id=0)
|
neutral_neighbors = self.get_neighboring_agents(state_id=0)
|
||||||
@ -135,11 +135,10 @@ class SpreadModelM2(ComportamientoBase):
|
|||||||
neighbor.state['id'] = 3 # Vaccinated
|
neighbor.state['id'] = 3 # Vaccinated
|
||||||
|
|
||||||
# Generate anti-rumor
|
# Generate anti-rumor
|
||||||
infected_neighbors = self.get_neighboring_agents(state_id=1)
|
infected_neighbors_2 = self.get_neighboring_agents(state_id=1)
|
||||||
for neighbor in infected_neighbors:
|
for neighbor in infected_neighbors_2:
|
||||||
if random.random() < self.prob_generate_anti_rumor:
|
if random.random() < self.prob_generate_anti_rumor:
|
||||||
neighbor.state['id'] = 2 # Cured
|
neighbor.state['id'] = 2 # Cured
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
class SISaModel(ComportamientoBase):
|
class SISaModel(ComportamientoBase):
|
||||||
|
@ -40,10 +40,10 @@ def init():
|
|||||||
global prob_generate_anti_rumor
|
global prob_generate_anti_rumor
|
||||||
|
|
||||||
network_type=1
|
network_type=1
|
||||||
number_of_nodes=100
|
number_of_nodes=20
|
||||||
max_time=500
|
max_time=50
|
||||||
num_trials=1
|
num_trials=1
|
||||||
timeout=20
|
timeout=1
|
||||||
|
|
||||||
#Zombie model
|
#Zombie model
|
||||||
bite_prob=0.01 # 0-1
|
bite_prob=0.01 # 0-1
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user