Skip to content

Commit f100519

Browse files
Syn-EonSyn-Eon
authored andcommitted
restructured files into package and used seeded RNG also whilst updating README
1 parent e5e5d36 commit f100519

5 files changed

Lines changed: 9 additions & 10 deletions

File tree

examples/pathogen_outbreak/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ analyzing changes in infection, death and immunity rates.
2222

2323
## How It Works
2424

25-
1. **Initialization** — citizens are placed randomly on a MultiGrid.
25+
1. **Initialization** — citizens are placed randomly on a Grid(OrthogonalMooreGrid).
2626
A configurable number are set initially as infected.
2727
2. **Disease Spread** — each step, healthy agents check their neighbours including diagonals.
2828
If any are infected, there is a configurable chance of transmission.
@@ -37,7 +37,7 @@ analyzing changes in infection, death and immunity rates.
3737
- Infected agents - compliant ones, freeze in place, simulating isolation or a lockdowned zone
3838
5. **Recovery** — after 10 steps of infection, agents recover to full
3939
immunity or die with the probability of 10%. Dead agents remain
40-
on the grid as red circles/squares(this is an intentional mechanic) as a visual indicator to assess how compliance affects the compliant as well as non-compliant groups.
40+
on the grid as red circles/squares(this is an intentional mechanic) as a visual indicator to assess how compliance affects the compliant as well as non-compliant groups.It is to be noted that dead agents block movement as well.
4141

4242
## Interesting Cases to Observe
4343

examples/pathogen_outbreak/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from mesa.visualization import SolaraViz, make_plot_component, make_space_component
2-
from model import PathogenModel
2+
from pathogen_outbreak.model import PathogenModel
33

44

55
def make_agent(agent):

examples/pathogen_outbreak/pathogen_outbreak/__init__.py

Whitespace-only changes.

examples/pathogen_outbreak/agents.py renamed to examples/pathogen_outbreak/pathogen_outbreak/agents.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import random
2-
31
from mesa.discrete_space import CellAgent
42

53

@@ -9,7 +7,7 @@ def __init__(self, model):
97

108
self.state = "healthy"
119
self.stage = 0
12-
self.compliant = random.random() < self.model.compliance_rate
10+
self.compliant = self.random.random() < self.model.compliance_rate
1311

1412
def step(self):
1513
if self.model.quarantine_status and self.compliant:
@@ -20,7 +18,7 @@ def step(self):
2018
if self.state == "infected":
2119
self.stage += 1
2220
if self.stage > 9:
23-
chance_of_death = random.random()
21+
chance_of_death = self.random.random()
2422

2523
if chance_of_death < 0.1:
2624
self.state = "dead"
@@ -36,7 +34,7 @@ def step(self):
3634
for a in cell.agents]
3735
for i in neighbors:
3836
if i.state == "infected":
39-
if random.random() > 0.40:
37+
if self.random.random() > 0.40:
4038
self.state = "infected"
4139
break
4240

examples/pathogen_outbreak/model.py renamed to examples/pathogen_outbreak/pathogen_outbreak/model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
from agents import Citizen
1+
from pathogen_outbreak.agents import Citizen
32
from mesa import DataCollector, Model
43
from mesa.discrete_space import OrthogonalMooreGrid
54

@@ -58,6 +57,8 @@ def __init__(
5857
for i in range(infn):
5958
self.agents[i].state = "infected"
6059

60+
self.datacollector.collect(self)
61+
6162
def step(self):
6263
self.infected_count = c_infected(self)
6364

0 commit comments

Comments
 (0)