Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Virus on Network documentation #100

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion examples/virus_on_network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## Summary

This model is based on the NetLogo model "Virus on Network".
This model is based on the NetLogo model "Virus on Network". It demonstrates the spread of a virus through a network and follows the SIR model, commonly seen in epidemiology.

The SIR model is one of the simplest compartmental models, and many models are derivatives of this basic form. The model consists of three compartments:

S: The number of susceptible individuals. When a susceptible and an infectious individual come into "infectious contact", the susceptible individual contracts the disease and transitions to the infectious compartment.
I: The number of infectious individuals. These are individuals who have been infected and are capable of infecting susceptible individuals.
R for the number of removed (and immune) or deceased individuals. These are individuals who have been infected and have either recovered from the disease and entered the removed compartment, or died. It is assumed that the number of deaths is negligible with respect to the total population. This compartment may also be called "recovered" or "resistant".

For more information about this model, read the NetLogo's web page: http://ccl.northwestern.edu/netlogo/models/VirusonaNetwork.

Expand All @@ -26,6 +32,15 @@ To run the model interactively, run ``mesa runserver`` in this directory. e.g.

Then open your browser to [http://127.0.0.1:8521/](http://127.0.0.1:8521/) and press Reset, then Run.

or

Directly run the file ``run.py`` in the terminal. e.g.

```
$ python run.py
```


## Files

* ``run.py``: Launches a model visualization server.
Expand Down
1 change: 0 additions & 1 deletion examples/virus_on_network/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def get_resistant_susceptible_ratio(model):

def make_plot(model):
# This is for the case when we want to plot multiple measures in 1 figure.
# We could incorporate this into core Mesa.
fig = Figure()
ax = fig.subplots()
measures = ["Infected", "Susceptible", "Resistant"]
Expand Down
EwoutH marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
8 changes: 7 additions & 1 deletion examples/virus_on_network/virus_on_network/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def number_resistant(model):


class VirusOnNetwork(mesa.Model):
"""A virus model with some number of agents"""
"""
A virus model with some number of agents
"""

def __init__(
self,
Expand Down Expand Up @@ -104,6 +106,10 @@ def run_model(self, n):


class VirusAgent(mesa.Agent):
"""
Individual Agent definition and its properties/interaction methods
"""

def __init__(
self,
unique_id,
Expand Down
81 changes: 45 additions & 36 deletions examples/virus_on_network/virus_on_network/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def get_agents(source, target):
return portrayal


network = mesa.visualization.NetworkModule(network_portrayal, 500, 500)
network = mesa.visualization.NetworkModule(
portrayal_method=network_portrayal,
canvas_height=500,
canvas_width=500,
)
chart = mesa.visualization.ChartModule(
[
{"Label": "Infected", "Color": "#FF0000"},
Expand All @@ -71,63 +75,68 @@ def get_resistant_susceptible_ratio(model):

model_params = {
"num_nodes": mesa.visualization.Slider(
"Number of agents",
10,
10,
100,
1,
name="Number of agents",
value=10,
min_value=10,
max_value=100,
step=1,
description="Choose how many agents to include in the model",
),
"avg_node_degree": mesa.visualization.Slider(
"Avg Node Degree", 3, 3, 8, 1, description="Avg Node Degree"
name="Avg Node Degree",
value=3,
min_value=3,
max_value=8,
step=1,
description="Avg Node Degree",
),
"initial_outbreak_size": mesa.visualization.Slider(
"Initial Outbreak Size",
1,
1,
10,
1,
name="Initial Outbreak Size",
value=1,
min_value=1,
max_value=10,
step=1,
description="Initial Outbreak Size",
),
"virus_spread_chance": mesa.visualization.Slider(
"Virus Spread Chance",
0.4,
0.0,
1.0,
0.1,
name="Virus Spread Chance",
value=0.4,
min_value=0.0,
max_value=1.0,
step=0.1,
description="Probability that susceptible neighbor will be infected",
),
"virus_check_frequency": mesa.visualization.Slider(
"Virus Check Frequency",
0.4,
0.0,
1.0,
0.1,
name="Virus Check Frequency",
value=0.4,
min_value=0.0,
max_value=1.0,
step=0.1,
description="Frequency the nodes check whether they are infected by a virus",
),
"recovery_chance": mesa.visualization.Slider(
"Recovery Chance",
0.3,
0.0,
1.0,
0.1,
name="Recovery Chance",
value=0.3,
min_value=0.0,
max_value=1.0,
step=0.1,
description="Probability that the virus will be removed",
),
"gain_resistance_chance": mesa.visualization.Slider(
"Gain Resistance Chance",
0.5,
0.0,
1.0,
0.1,
name="Gain Resistance Chance",
value=0.5,
min_value=0.0,
max_value=1.0,
step=0.1,
description="Probability that a recovered agent will become "
"resistant to this virus in the future",
),
}

server = mesa.visualization.ModularServer(
VirusOnNetwork,
[network, get_resistant_susceptible_ratio, chart],
"Virus Model",
model_params,
model_cls=VirusOnNetwork,
visualization_elements=[network, get_resistant_susceptible_ratio, chart],
name="Virus on Network Model",
model_params=model_params,
)
server.port = 8521