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-specifiedDsolModel
interface isDsolModel<Duration>
. - AbstractDsolModel. The
AbstractDsolModel
is a reference base implementation of theDsolModel
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 arestart()
,step()
andstop()
, as well as thegetSimulatorTime()
method that returns the simulation time. When callinggetSimulatorTime()
on aSimulator<Duration>
, aDuration
object is returned, whereas calling the same method on aSimulator<Double>
returns a double value. All sub-interfaces and implementations of theSimulator
interface such as theDevsSimulator
, theDessSimulator
, theDevDessSimulator
and theDevsRealTimeAnimator
have the same time type generic. A discrete-event model without animation using Duration for its time would run on aDevsSimulator<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 anExperiment<Long>
. - Flow-control blocks such as Generator, Seize, Delay, Release, Duplicate, Schedule and Departure all are generics with a time representing class.