NetLogo banner

Home
Download
Help
Forum
Resources
Extensions
FAQ
NetLogo Publications
Contact Us
Donate

Models:
Library
Community
Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Web
Printable
Chinese
Czech
Farsi / Persian
Japanese
Spanish

  Donate

NetLogo Models Library:
Sample Models/Biology

(back to the library)

Virus Using Discrete Event Simulator

[screen shot]

Note: If you download the NetLogo application, every model in the Models Library is included.

WHAT IS IT?

This is a modification of the "Virus" model in the Biology section of the Models Library to illustrate use of the time extension for "discrete event simulation", which makes the code simpler and faster (see THINGS TO NOTICE below).

With the few (but important) exceptions noted below, this model does exactly what the original Virus model did and uses the same code. The model documentation is not duplicated here; instead, this tab only discusses the differences between the original Virus model and this discrete event implementation.

HOW IT WORKS

A discrete event scheduler is a convenient and efficient way of programming agents to do certain actions that don't happen every tick. In many agent-based models, the agents do the same thing every tick. But, sometimes agents take certain action only occasionally. Normally, this would require checking each tick if the right amount of time has passed and then, if it has, doing the action. In the case of the Virus model, agents get sick and then only recover after a certain number of ticks. So, they have to check each tick if that amount of time has passed. A discrete event schedule avoids this by keeping a list of events that are scheduled at different times and then running those events when the time comes. In this model, when an agent gets sick, it schedules when it will recover or die. The go procedure of this model uses both tick-based and discrete-event based updates. Each tick, turtles move and have a chance to infect others if they are infected and a chance to reproduce if they aren't. Then the tick counter is advanced and all events that were scheduled to happen during this tick are run with the command time:go-until ticks. For more information on the discrete event scheduler, see https://ccl.northwestern.edu/netlogo/docs/time.html.

The differences from the original Virus model are:

  • Instead of using counter variables (remaining-immunity, sick-time) to count down how many ticks remain until a turtle becomes susceptible or recovers, this version has turtles simply schedule the future time at which those events happen. In the procedure infect, the newly infected turtle schedules the time at which it executes recover-or-die. In recover-or-die, the turtle schedules the time at which its immunity ends and becomes susceptible again. This scheduling eliminates the need for code to check and update the counter variables each tick.

  • Instead of separate boolean variables for whether a turtle is sick or immune, turtles have one variable status that has values of "susceptible" (equivalent to "healthy" in the original model), "infected" (equivalent to "sick"), or "immune".

  • The only important difference in model formulation is that the times it takes turtles to recover (switch from "infected" to "immune") and to lose immunity (switch from "immune" to "susceptible") vary randomly among individuals. Discrete event simulation makes this easy: in each of the time:schedule-event statements in infect and recover-or-die, the future time at which the switch occurs is drawn from a random-exponential distribution, using the parameters "duration" and "immunity-duration" as the mean length of infection and immunity. This individual variation in infection and immunity times can be turned off by simply deleting the primitive random-exponential from the time:schedule-event statements in infect and recover-or-die.

  • Age is tracked in years instead of weeks, and birthdays are scheduled as discrete events. When each turtle is created in setup-turtles it schedules its next birthday (the get-older procedure) a random number of weeks in the future. New turtles created in reproduce schedule their first birthday 52 weeks after their birth. On each birthday, the turtle simply schedules another execution of get-older 52 weeks in the future.

HOW TO USE IT

This model's interface works exactly as the original Virus model does, with one exception:

The DURATION slider still controls the time it takes an infected person to either die or recover, but instead of always being equal to the slider's value, the duration of each turtle's illness is now drawn from an exponential distribution with the slider's value as its mean. As a result of the exponential distribution's characteristics, most turtles will remain ill for less time than the slider's value but a few will remain ill for much longer.

THINGS TO NOTICE

The use of discrete event simulation allows the code to be shorter and simpler. This version has 4 fewer procedures than the original: get-sick, get-health, become-immune are replaced by the time:schedule-event statements. The immune? reporter is made unnecessary by discrete event simulation and the status variable.

This model also executes more rapidly than the original Virus model because it eliminates the need to check counter variables every tick. In BehaviorSpace experiments with display updates off, this version executes in 2/3 the time of the original model, even though execution time (according to the profiler extension) is dominated by interface updates and the move procedure. The original model spends much of its execution time in the procedures immune? and get-older, which have been removed or simplified here.

The addition of individual variation in the duration of infection and immunity qualitatively changes the model's behavior. This model produces small and shorter cycles in infection than the original Virus model.

The model illustrates only one function of the time extension, discrete event simulation. It does not use the time extension's ability to represent specific years, dates, days, etc.

THINGS TO TRY

In addition to the experiments suggested for the original Virus model, the effects of variability in the duration of illness and immunity can be investigated with this version. For different kinds of virus (e.g., Ebola, with short duration, high infectiousness, and low recovery; AIDS, with long duration, low infectiousness, and low recovery), compare the behavior of this model with that of the original Virus model. (Or turn off this model's random variation among turtles, as explained above.)

EXTENDING THE MODEL

The modifications suggested for the original Virus model can all be implemented for this version.

Also, you can see what happens if infectiousness, or recovery time, or the duration of immunity depend on age. For example, the COVID-19 virus was originally believed much less infectious for children, and survival was lower for older adults. Modify the procedures for these processes to make the probabilities or rates depend on age (which is in years).

RELATED MODELS

This model illustrates only one of the time extension's capabilities, letting agents schedule actions at future times. The other time extension code example models illustrate the extension's other capabilities such as providing date and time variables, linking ticks to explicit time units, and reading and writing time-series data.

CREDITS AND REFERENCES

The original Virus model was written by Uri Wilensky:

HOW TO CITE

If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

Please cite the NetLogo software as:

COPYRIGHT AND LICENSE

Copyright 2022 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

(back to the NetLogo Models Library)