From afebf979653467c2a342c7dc9bd33d12bfb1b23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Tue, 20 Jun 2017 11:49:08 +0200 Subject: [PATCH 1/3] --- prueba.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 prueba.py diff --git a/prueba.py b/prueba.py new file mode 100644 index 0000000..b06a3fa --- /dev/null +++ b/prueba.py @@ -0,0 +1,14 @@ +class ControlModelM2(BaseBehaviour): + NEUTRAL = 0 + INFECTED = 1 + def step(self, now): + if self.state['id'] == self.NEUTRAL: #Neutral + self.neutral_behaviour() + elif self.state['id'] == self.INFECTED: #Infected + self.infected_behaviour() + … + def infected_behaviour(self): + neutral_neighbors = self.get_neighboring_agents(state_id=0) + for neighbor in neutral_neighbors: + if random.random() < self.prob_infect: + neighbor.state['id'] = self.INFECTED From 2798757188882f473a9d258f1e1917403b0ff503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Tue, 20 Jun 2017 11:50:22 +0200 Subject: [PATCH 2/3] --- prueba.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prueba.py b/prueba.py index b06a3fa..cc56567 100644 --- a/prueba.py +++ b/prueba.py @@ -8,7 +8,7 @@ class ControlModelM2(BaseBehaviour): self.infected_behaviour() … def infected_behaviour(self): - neutral_neighbors = self.get_neighboring_agents(state_id=0) + neutral_neighbors = self.get_neighboring_agents(state_id=self.NEUTRAL) for neighbor in neutral_neighbors: if random.random() < self.prob_infect: neighbor.state['id'] = self.INFECTED From b259496b2279a15887ceff85cab75a5072845905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Tue, 20 Jun 2017 11:51:56 +0200 Subject: [PATCH 3/3] --- prueba.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/prueba.py b/prueba.py index cc56567..2357a26 100644 --- a/prueba.py +++ b/prueba.py @@ -1,14 +1,17 @@ +NEUTRAL = 0 +INFECTED = 1 + class ControlModelM2(BaseBehaviour): NEUTRAL = 0 INFECTED = 1 def step(self, now): - if self.state['id'] == self.NEUTRAL: #Neutral + if self.state['id'] == NEUTRAL: self.neutral_behaviour() - elif self.state['id'] == self.INFECTED: #Infected + elif self.state['id'] == INFECTED: self.infected_behaviour() … def infected_behaviour(self): - neutral_neighbors = self.get_neighboring_agents(state_id=self.NEUTRAL) + neutral_neighbors = self.get_neighboring_agents(state_id=INFECTED) for neighbor in neutral_neighbors: if random.random() < self.prob_infect: - neighbor.state['id'] = self.INFECTED + neighbor.state['id'] = INFECTED