1
0
mirror of https://github.com/gsi-upm/soil synced 2024-11-22 03:02:28 +00:00

Added dynamic graph.

Added dynamic graph to ControlModelM2.
This commit is contained in:
Tasio Mendez 2017-05-19 13:55:04 +02:00
parent cd9b7e096a
commit 764177c634
5 changed files with 1372 additions and 27162 deletions

28442
data.txt

File diff suppressed because it is too large Load Diff

View File

@ -71,6 +71,7 @@ class ControlModelM2(BaseBehaviour):
super().step(now) super().step(now)
def neutral_behaviour(self): def neutral_behaviour(self):
self.attrs['visible'] = False
# Infected # Infected
infected_neighbors = self.get_neighboring_agents(state_id=1) infected_neighbors = self.get_neighboring_agents(state_id=1)
@ -85,9 +86,11 @@ class ControlModelM2(BaseBehaviour):
for neighbor in neutral_neighbors: for neighbor in neutral_neighbors:
if random.random() < self.prob_infect: if random.random() < self.prob_infect:
neighbor.state['id'] = 1 # Infected neighbor.state['id'] = 1 # Infected
self.attrs['visible'] = False
def cured_behaviour(self): def cured_behaviour(self):
self.attrs['visible'] = True
# Vaccinate # Vaccinate
neutral_neighbors = self.get_neighboring_agents(state_id=0) neutral_neighbors = self.get_neighboring_agents(state_id=0)
for neighbor in neutral_neighbors: for neighbor in neutral_neighbors:
@ -101,6 +104,7 @@ class ControlModelM2(BaseBehaviour):
neighbor.state['id'] = 2 # Cured neighbor.state['id'] = 2 # Cured
def vaccinated_behaviour(self): def vaccinated_behaviour(self):
self.attrs['visible'] = True
# Cure # Cure
infected_neighbors = self.get_neighboring_agents(state_id=1) infected_neighbors = self.get_neighboring_agents(state_id=1)
@ -121,12 +125,13 @@ class ControlModelM2(BaseBehaviour):
neighbor.state['id'] = 2 # Cured neighbor.state['id'] = 2 # Cured
def beacon_off_behaviour(self): def beacon_off_behaviour(self):
self.attrs['visible'] = False
infected_neighbors = self.get_neighboring_agents(state_id=1) infected_neighbors = self.get_neighboring_agents(state_id=1)
if len(infected_neighbors) > 0: if len(infected_neighbors) > 0:
self.state['id'] == 5 # Beacon on self.state['id'] == 5 # Beacon on
def beacon_on_behaviour(self): def beacon_on_behaviour(self):
self.attrs['visible'] = False
# Cure (M2 feature added) # Cure (M2 feature added)
infected_neighbors = self.get_neighboring_agents(state_id=1) infected_neighbors = self.get_neighboring_agents(state_id=1)
for neighbor in infected_neighbors: for neighbor in infected_neighbors:

View File

@ -8,7 +8,7 @@
}, },
{ {
"agent": ["BaseBehaviour","SISaModel","ControlModelM2"], "agent": ["SISaModel","ControlModelM2"],
"bite_prob": 0.01, "bite_prob": 0.01,

Binary file not shown.

21
soil.py
View File

@ -16,14 +16,32 @@ import json
def visualization(graph_name): def visualization(graph_name):
for x in range(0, settings.network_params["number_of_nodes"]): for x in range(0, settings.network_params["number_of_nodes"]):
attributes = {}
spells = []
for attribute in models.networkStatus["agent_%s" % x]: for attribute in models.networkStatus["agent_%s" % x]:
if attribute == 'visible':
lastvisible = False
laststep = 0
for t_step in models.networkStatus["agent_%s" % x][attribute]:
nowvisible = models.networkStatus["agent_%s" % x][attribute][t_step]
if nowvisible and not lastvisible:
laststep = t_step
if not nowvisible and lastvisible:
spells.append((laststep, t_step))
lastvisible = nowvisible
if lastvisible:
spells.append((laststep, None))
else:
emotionStatusAux = [] emotionStatusAux = []
for t_step in models.networkStatus["agent_%s" % x][attribute]: for t_step in models.networkStatus["agent_%s" % x][attribute]:
prec = 2 prec = 2
output = math.floor(models.networkStatus["agent_%s" % x][attribute][t_step] * (10 ** prec)) / (10 ** prec) # 2 decimals output = math.floor(models.networkStatus["agent_%s" % x][attribute][t_step] * (10 ** prec)) / (10 ** prec) # 2 decimals
emotionStatusAux.append((output, t_step, t_step + settings.network_params["timeout"])) emotionStatusAux.append((output, t_step, t_step + settings.network_params["timeout"]))
attributes = {}
attributes[attribute] = emotionStatusAux attributes[attribute] = emotionStatusAux
if spells:
G.add_node(x, attributes, spells=spells)
else:
G.add_node(x, attributes) G.add_node(x, attributes)
print("Done!") print("Done!")
@ -101,7 +119,6 @@ if settings.network_params["network_type"] == 2:
G = nx.margulis_gabber_galil_graph(settings.network_params["number_of_nodes"], None) G = nx.margulis_gabber_galil_graph(settings.network_params["number_of_nodes"], None)
# More types of networks can be added here # More types of networks can be added here
############## ##############
# Simulation # # Simulation #
############## ##############