Four simple NetLogo models that demonstrate how to use the time extension are now available.

These models contain code that can be copied and reused to:

  • Create and use “Logotime” variables that contain dates (year, month, day), days (month and day), or date-time values (date and time).
  • Schedule events to be executed at specific future times, which are not necessarily on ticks. This capability makes “discrete event simulation” easy; our JASSS paper explains how this can make some models much much faster.
  • Read and write time-series data.

The code example models are:

(1) TimeExample-Logotimes.nlogo, a very simple illustration of creating and using Logotime variables. It shows how to associate NetLogo ticks with specific units of time. The model uses parameters for (a) the date and time at which simulations start and end, (b) the time units for ticks (e.g., days, hours, seconds), and (c) the number of time units represented by each tick (a tick could represent 5 minutes or 10 days, for example). The go procedure simply advances the ticks and reports the current simulation time in a variety of units (the year, the month as both a number and text name, the day of the year…), and the amount of time remaining.

It is at: http://ccl.northwestern.edu/netlogo/models/community/UpdatedTimeExample-Logotimes

(2) TimeExample-Whack-A-Mole.nlogo, which simulates the arcade game. This is a very simple example of using time extension commands to schedule events at future ticks. An example procedure that hides the mole and schedules it to re-appear a random number of ticks in the future:

to hide
   hide-turtle
   set shape "face happy"
   set color brown
   time:schedule-event self [ -> appear ] (ticks + random 3)
end

This model is at: http://ccl.northwestern.edu/netlogo/models/community/TimeExample-Whack-A-Mole

(3) DiscreteEventVirus.nlogo, a modification of the Models Library’s Virus model to use discrete events instead of counter variables to keep track of when people change from infected to immune to healthy status. The use of discrete events makes the code shorter, simpler, and faster. Instead of this:

if sick? [ set sick-time sick-time + 1 ]

if sick-time > duration [ ... ]

the time extension lets you simply schedule recovery as soon as the person becomes sick:

[ if random-float 100 < infectiousness
  [
   set status "infected"
   set color red
   ; Schedule the end of infection
   time:schedule-event self [ -> recover-or-die ] (ticks + duration)

It is at: http://ccl.northwestern.edu/netlogo/models/community/DiscreteEventVirus

(4) TimeExample-DistributionCenter.nlogo, a more complete example of using all the time extension’s capabilities and the time series tool. The model represents an internet store: orders arrive at random times, while workers fill them as they arrive. The model treats ticks as minutes and schedules most turtle actions as discrete events happening at fractions of ticks.

For example, the code to generate orders at random intervals requires only this:

to receive-an-order
  set num-orders-to-fill num-orders-to-fill + 1
  let time-to-next-order (random-exponential mean-order-interval) / 60
  ; Schedule the *next* order
  time:schedule-event "observer" [ -> receive-an-order ]
(ticks + time-to-next-order)
end

A log of worker activity can be output; it looks like this (for a simulation starting at 8:00 on May 1, 2020):

LOGOTIME,Shift,Employee,Event,Duration (min)
2020-05-01 08:00:00.000,day,1,wait,1
2020-05-01 08:00:00.000,day,13,pick an order,1.2666666666666666
2020-05-01 08:01:00.000,day,10,wait,1
2020-05-01 08:01:00.000,day,15,pick an order,1.7803133273813083
2020-05-01 08:01:16.000,day,13,wait,1
2020-05-01 08:02:00.000,day,10,pick an order,1.3771236166328253
2020-05-01 08:02:00.000,day,18,wait,1
2020-05-01 08:02:00.000,day,5,pick an order,1.42687494916219
2020-05-01 08:02:00.000,day,1,pick an order,1.3771236166328253
2020-05-01 08:02:16.000,day,13,wait,1
2020-05-01 08:02:46.818,day,15,pick an order,1.53748384988657

This one is at least temporarily at:

https://langrailsback.com/Transfer/TimeExample-DistributionCenter.nlogo