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
|
NetLogo Models Library: |
Note: If you download the NetLogo application, every model in the Models Library is included. |
This is a simple demonstration of how to use NetLogo's time extension to represent real dates and times in a model. It shows how to create, manipulate, and output the "Logotime" variable type provided by the time extension.
Users should be able to copy code directly from this example into their own models. However, normally the time units and length of a tick are not parameters as they are here (explained below), but "hardwired" -- the anchor-to-ticks
statement in setup
normally looks like this:
set sim-time time:anchor-to-ticks sim-start-time 1 day
The NetLogo User Manual's section on the time extension provides much more detail and more examples.
A Logotime variable can hold one of three kinds of time values: a DATETIME--a date and time, with precision down to milliseconds; a DATE--a day specified by year, month, and date, but with no sub-daily information; and a DAY--a day of the year without specifying which year (e.g., April 15). This model uses only the DATETIME type.
This "model" simply ticks through a specified amount of time and reports the time at each tick in a variety of units.
Comments in the Code tab explain how the model works.
Users can explore how the time extension represents time by:
sim-start-time
and sim-end-time
inputs on the Interface. These are text strings that must be in the format: yyyy/M/d HH:mm:ss
(year, month, day, hour, minute, seconds).setup
.step
to update the time one tick, or go
for repeated updates.Note that changes in the time step units and length only take effect in the setup
procedure. Changing them during a simulation has no effect--you must set up again for changes in start time, end time, or the time step to take effect.
Setting the Interface to view updates on ticks (instead of "Continuous") may make the model run slow enough to observe; if not, turn down the speed slider.
Non-integer time step lengths are not supported for units of "months" or "years"; for months and years, the time step length will be rounded to the nearest whole number. (Try it!)
Month time units are also different because the time:difference-between
primitive used to update time-simulated
and time-remaining
ignores the year when calculating time differences in months. Hence, the difference between a date in April and a date in May is always 1 month, even if those dates are in different years. Consequently, time-simulated
and time-remaining
are not calculated correctly when time-step-units
is chosen to be months
.
Change the time step units in the chooser and the time step length in the slider, hit setup
and step
to see exactly how the time extension works. For example:
If you prefer a different format for date and time input (sim-start-time
and sim-end-time
), try changing the two time:create-with-format
statements in setup
to use your preferred format.
The NetLogo models library contains other example uses of the time extension, in its Code Examples > Extension Examples section.
Prepared by Steve Railsback January 2022.
(back to the NetLogo Models Library)