AnyLogic
Expand
Font size

Model time

Model time is the virtual (simulated) time maintained by the AnyLogic simulation engine. The model time has nothing to do with the real time or the computer clock (although you can run the model in a scale to real time).

In AnyLogic, the model time takes real numbers (double type values). The model clock is advanced in steps: while the engine is executing a discrete event model, the model time jumps from one event to another; if a continuous-time model is being executed, the time steps are typically smaller and have equal size.

As all events in AnyLogic are instantaneous and indivisible, the model time does not progress during event execution, no matter how long it takes to complete all the computations associated with the event.

Model time units

To establish the correspondence between the model time and real-world time where the system being modeled lives, we need to define the time units. The type of time unit depends on the time scale of the activities you are modeling. For example, if you are modeling a call center where the call durations are measured in seconds or minutes, you may set the time units to seconds or minutes. If you are modeling a supply chain, where manufacturing and shipping times are measured in days, days would be the right choice.

AnyLogic supports all popular time units: milliseconds, seconds, minutes, hours, days, weeks, months, years. You may change the model time units whenever you like, though we advise that you select the model time units when you create the model.

To set the time units

  1. In the Projects view, select the model (the topmost item).
  2. In the model’s Properties, choose required time units from the Model time units drop-down list.

Any time unit longer than a week is not a constant: a month may have 28, 29, 30 or 31 days, and a year can have 365 or 366 days. If you choose, say, months as the time unit in your model, then 1 month in the model will always have 30 days. In this case the calendar months will obviously differ slightly from months based on time units and the longer the period, the bigger the error. The same happens when you choose years as your model time units: every year in the model will be 365 days long.

Simulation start and stop times

You can set the stop time, the time at which you wish the simulation run to be terminated.

To set start and stop times

  1. In the Projects view, select the experiment you are currently working with.
  2. Open the Model time section of the experiment’s Properties.
  3. If you want the model to work infinitely until you stop it manually, select Never from the Stop drop-down list.
  4. Otherwise, if you want simulation to be stopped at some other time moment, you can specify stop time as a calendar date or you can specify simulation time horizon as a number of model time units.
  5. If you want to define the simulation time horizon as a number of model time units, choose Stop model at specified time from the Stop drop-down list, and specify the stop time in the Stop time edit box.
  6. Otherwise, if you prefer to specify times as calendar dates, choose Stop model at specified date from the Stop drop-down list, and enter the start and stop dates using Start date and Stop date controls. By default, the start date is set to the date when the model is created.
Setting Stop to Never does not mean the simulation will run infinitely long. It can be terminated in several other ways: programmatically, using a stop condition, or when the engine detects there are no more dynamics left in the model.

Time mode and simulation speed

AnyLogic can execute the simulation model in two modes, virtual time and real time on a given scale.

  • In real time mode, the mapping of AnyLogic model time to the real time is made, i.e. you specify how many model time units one second takes. It is frequently needed when you want your presentation to appear as in real life. The engine tries to keep to a given scale, say 10 model time units (e.g., 10 simulated weeks) per 1 real second. Sometimes, though, the engine is unable to keep a given time scale because of too-frequent or too-complex events or because of a large system of equations and/or a too-small time step. Then the engine will work as fast as possible until it finds the next opportunity to maintain the real-time scale. Thus, the only thing the model can guarantee with respect to the real time is that the model execution will never go faster than requested.
  • In virtual time mode, the simulation engine executes the model as fast as possible. The model runs at its maximum speed and no mapping is made between model time units and seconds of astronomical time. This time mode is useful when you need to simulate your model for a long period of time. The virtual time mode is used when simulation performance is important and animation of the model dynamics is not needed.

In real time mode, you can increase or decrease model simulation speed by changing the model simulation speed scale. The default 1x scale means that the model is simulated with the model simulation speed defined in the properties of the current AnyLogic experiment; 2x means that model is run twice faster than the specified model speed, etc. For instance, if the model speed is 6 model time units per second, 2x means that 12 model time units correspond to 1 second.

You can set the desired execution mode in the simulation experiment’s Model time properties section (for other experiment types, the virtual time mode is assumed). Later, you can use the controls in the model window to change the mode during runtime or do it programmatically.

To set the default time mode and simulation speed

  1. In the Projects view, select the experiment you are working with.
  2. In the Model time section of the experiment’s Properties, set the time mode using the controls in the Execution mode section.
  3. If you want to run your model in virtual time mode, select the Virtual time (as fast as possible) option.
  4. Otherwise, if you want to set the mapping between model time and real time units, select Real time with scale and set the scale value (number of model time units executed per one second) from the drop-down list to the right.
How can we improve this article?