Class DevsRealTimeAnimator<T extends Number & Comparable<T>>

java.lang.Object
org.djutils.event.LocalEventProducer
Type Parameters:
T - the time type
All Implemented Interfaces:
Serializable, Runnable, Remote, AnimatorInterface, DevsSimulatorInterface<T>, SimulatorInterface<T>, org.djutils.event.EventProducer
Direct Known Subclasses:
DevsRealTimeAnimator.TimeDouble, DevsRealTimeAnimator.TimeDoubleUnit, DevsRealTimeAnimator.TimeFloat, DevsRealTimeAnimator.TimeFloatUnit, DevsRealTimeAnimator.TimeLong

public abstract class DevsRealTimeAnimator<T extends Number & Comparable<T>> extends DevsAnimator<T> implements DevsSimulatorInterface<T>
The reference implementation of the realTimeClock. The realTime clock is a DEVS simulator which runs at a ratio of realTime. If the executionTime exceeds the timeStep, a catchup mechanism can be triggered to make up lost time in consecutive steps.

Copyright (c) 2004-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.

Since:
1.5
Author:
Alexander Verbraeck
See Also:
  • Field Details

    • BACKLOG_EVENT

      public static final org.djutils.event.EventType BACKLOG_EVENT
      the backlog event.
    • CHANGE_SPEED_FACTOR_EVENT

      public static final org.djutils.event.EventType CHANGE_SPEED_FACTOR_EVENT
      the speed factor event.
  • Constructor Details

    • DevsRealTimeAnimator

      public DevsRealTimeAnimator(Serializable id)
      Constructs a new DevsRealTimeClock.
      Parameters:
      id - the id of the simulator, used in logging and firing of events.
  • Method Details

    • simulatorTimeForWallClockMillis

      protected abstract T simulatorTimeForWallClockMillis(double wallMilliseconds)
      Calculate the how much simulation duration corresponds to the number of wall clock milliseconds indicated in the parameter. When the DevsRealTimeClock works with djunits Time or Duration, and the simulation is scaled to milliseconds, the simulatorTimeForWallClockMillis of a millisecond is a Duration of 1 millisecond. When 1 simulated time unit stands for a second, the simulatorTimeForWallClockMillis is 0.001.
      Parameters:
      wallMilliseconds - double; the number of milliseconds to calculate the corresponding simulation time for
      Returns:
      the relative time step.
    • run

      public void run()
      The run method defines the actual time step mechanism of the simulator. The implementation of this method depends on the formalism. Where discrete event formalisms loop over an event list, continuous simulators take predefined time steps. Make sure that:
      - SimulatorInterface.TIME_CHANGED_EVENT is fired when the time of the simulator changes
      - the warmup() method is called when the warmup period has expired (through an event or based on simulation time)
      - the endReplication() method is called when the replication has ended
      - the simulator runs until the runUntil time, which is also set by the start() method.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class DevsAnimator<T extends Number & Comparable<T>>
    • setAnimation

      public void setAnimation(boolean animation)
      Indicate whether we support animation or not.
      Parameters:
      animation - boolean; whether we support animation or not
    • isAnimation

      public boolean isAnimation()
      Returns:
      animation boolean; whether we support animation or not
    • getSpeedFactor

      public double getSpeedFactor()
      Returns:
      speedFactor
    • setSpeedFactor

      public void setSpeedFactor(double newSpeedFactor, boolean fireChangeSpeedFactorEvent)
      Set the speedFactor, and send a CHANGE_SPEED_FACTOR event.
      Parameters:
      newSpeedFactor - double; the new speed factor to set
      fireChangeSpeedFactorEvent - boolean; whether to fire a CHANGE_SPEED_FACTOR event or not
    • setSpeedFactor

      public void setSpeedFactor(double newSpeedFactor)
      Set the speedFactor, and send a CHANGE_SPEED_FACTOR event.
      Parameters:
      newSpeedFactor - double; set speedFactor
    • isCatchup

      public boolean isCatchup()
      Returns:
      catchup
    • setCatchup

      public void setCatchup(boolean catchup)
      Parameters:
      catchup - boolean; set catchup
    • getUpdateMsec

      public int getUpdateMsec()
      The relative update delay in milliseconds is the step size in wall clock time by which the time is updated between events. Default, this value is set at 10 msec, which means that the simulation updates its clock with 100 Hz between events.
      Returns:
      the relative update delay in milliseconds
    • setUpdateMsec

      public void setUpdateMsec(int updateMsec)
      The relative update delay in milliseconds is the step size in wall clock time by which the time is updated between events. Default, this value is set at 10 msec, which means that the simulation updates its clock with 100 Hz between events. When this is too course, set e.g. to 1, which means that the clock will be updated with 1 kHz between events. The latter can be important in real time simulations. Note that the housekeeping of the simulation clock takes time as well, so 1 kHz can be too fine grained in some situations.
      Parameters:
      updateMsec - int; set the relative update delay in milliseconds