mirror of
https://github.com/gsi-upm/soil
synced 2024-11-13 06:52:28 +00:00
Added dynamic graph.
Added dynamic graph to ControlModelM2.
This commit is contained in:
parent
cd9b7e096a
commit
764177c634
@ -71,6 +71,7 @@ class ControlModelM2(BaseBehaviour):
|
||||
super().step(now)
|
||||
|
||||
def neutral_behaviour(self):
|
||||
self.attrs['visible'] = False
|
||||
|
||||
# Infected
|
||||
infected_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
@ -85,9 +86,11 @@ class ControlModelM2(BaseBehaviour):
|
||||
for neighbor in neutral_neighbors:
|
||||
if random.random() < self.prob_infect:
|
||||
neighbor.state['id'] = 1 # Infected
|
||||
self.attrs['visible'] = False
|
||||
|
||||
def cured_behaviour(self):
|
||||
|
||||
self.attrs['visible'] = True
|
||||
# Vaccinate
|
||||
neutral_neighbors = self.get_neighboring_agents(state_id=0)
|
||||
for neighbor in neutral_neighbors:
|
||||
@ -101,6 +104,7 @@ class ControlModelM2(BaseBehaviour):
|
||||
neighbor.state['id'] = 2 # Cured
|
||||
|
||||
def vaccinated_behaviour(self):
|
||||
self.attrs['visible'] = True
|
||||
|
||||
# Cure
|
||||
infected_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
@ -121,12 +125,13 @@ class ControlModelM2(BaseBehaviour):
|
||||
neighbor.state['id'] = 2 # Cured
|
||||
|
||||
def beacon_off_behaviour(self):
|
||||
self.attrs['visible'] = False
|
||||
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):
|
||||
|
||||
self.attrs['visible'] = False
|
||||
# Cure (M2 feature added)
|
||||
infected_neighbors = self.get_neighboring_agents(state_id=1)
|
||||
for neighbor in infected_neighbors:
|
||||
|
@ -8,7 +8,7 @@
|
||||
},
|
||||
|
||||
{
|
||||
"agent": ["BaseBehaviour","SISaModel","ControlModelM2"],
|
||||
"agent": ["SISaModel","ControlModelM2"],
|
||||
|
||||
|
||||
"bite_prob": 0.01,
|
||||
|
Binary file not shown.
35
soil.py
35
soil.py
@ -16,14 +16,32 @@ import json
|
||||
def visualization(graph_name):
|
||||
|
||||
for x in range(0, settings.network_params["number_of_nodes"]):
|
||||
attributes = {}
|
||||
spells = []
|
||||
for attribute in models.networkStatus["agent_%s" % x]:
|
||||
emotionStatusAux = []
|
||||
for t_step in models.networkStatus["agent_%s" % x][attribute]:
|
||||
prec = 2
|
||||
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"]))
|
||||
attributes = {}
|
||||
attributes[attribute] = emotionStatusAux
|
||||
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 = []
|
||||
for t_step in models.networkStatus["agent_%s" % x][attribute]:
|
||||
prec = 2
|
||||
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"]))
|
||||
attributes[attribute] = emotionStatusAux
|
||||
if spells:
|
||||
G.add_node(x, attributes, spells=spells)
|
||||
else:
|
||||
G.add_node(x, attributes)
|
||||
|
||||
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)
|
||||
# More types of networks can be added here
|
||||
|
||||
|
||||
##############
|
||||
# Simulation #
|
||||
##############
|
||||
@ -124,4 +141,4 @@ else:
|
||||
num_trials=settings.network_params["num_trials"], logging_interval=1.0, **settings.environment_params)
|
||||
sim.run_simulation()
|
||||
results(str(agent))
|
||||
visualization(str(agent))
|
||||
visualization(str(agent))
|
Loading…
Reference in New Issue
Block a user