Skip to content

Time in DSOL

Time and state

Simulation is all about experimenting with a model where state changes over time. State is easily represented in an object-oriented programming environment: all attribute values of all object instances in the model constitute the state of the model. Programming languages have no similar concept for 'time', though. Therefore time is kept by the Simulator object that is responsible for maintaining and updating the simulation time.

Time representation in DSOL

DSOL supports any representation of time that extends Number and that is comparable to other times. The definition of the SimulatorInterface class is, for instance:

  public interface SimulatorInterface<T extends Number & Comparable<T>>

Examples of common and valid simulation times are:

Class Explanation / Example
Double This is the most common simulation time, represented by a double value.
Float Sometimes used when many simulation events with time need to be stored; a float is half the number of bytes of a double
Long Times are both represented by a long value. This is, for instance, a time unit that can be used for agent-based models that use equidistant time 'ticks' rather than varying time intervals between simulation events.
Duration Duration can be used with its DurationUnit. An example is
Duration duration = new Duration(45.0, DurationUnit.SECOND);
FloatDuration FloatDuration can be used with its DurationUnit. An example is
FloatDuration duration = new FloatDuration(12.0f, DurationUnit.HOUR);

Classes using time in DSOL such as the Simulator, Experiment, Replication, DsolModel, etc., all need to use the same definition of time within one simulation model; see the next section for several of the classes that are defined with a time generic.

Usage of simulation time type in other classes

Examples of classes and interfaces that use simulation time types as a generic are:

  • DsolModel. The DsolModel is the interface that specifies what a simulation model should implement. An example of a time-specified DsolModel interface is DsolModel<Duration>.
  • AbstractDsolModel. The AbstractDsolModel is a reference base implementation of the DsolModel interface, that actual models can inherit from. An example is: public class MM1Model extends AbstractDsolModel<Double>
  • Simulator. The Simulator interface specifies what any DSOL Simulator should implement. Example methods are start(), step() and stop(), as well as the getSimulatorTime() method that returns the simulation time. When calling getSimulatorTime() on a Simulator<Duration>, a Duration object is returned, whereas calling the same method on a Simulator<Double> returns a double value. All sub-interfaces and implementations of the Simulator interface such as the DevsSimulator, the DessSimulator, the DevDessSimulator and the DevsRealTimeAnimator have the same time type generic. A discrete-event model without animation using Duration for its time would run on a DevsSimulator<Duration>.
  • SimEventInterface and SimEvent that represent discrete events in the simulaton, need to know on which time unit they are executed because of the execution time of the event.
  • Experiment, RunControl, and Replication that represent the run control conditions under which the simulation is executed. A DsolModel<Long> can only be executed by an Experiment<Long>.
  • Flow-control blocks such as Generator, Seize, Delay, Release, Duplicate, Schedule and Departure all are generics with a time representing class.