Class DevsRealTimeAnimator<T extends Number & Comparable<T>>
java.lang.Object
org.djutils.event.LocalEventProducer
nl.tudelft.simulation.dsol.simulators.Simulator<T>
nl.tudelft.simulation.dsol.simulators.DevsSimulator<T>
nl.tudelft.simulation.dsol.simulators.DevsAnimator<T>
nl.tudelft.simulation.dsol.simulators.DevsRealTimeAnimator<T>
- 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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Easy access class RealTimeClock<Double>.static class
Easy access class RealTimeClock<Duration>.static class
Easy access class RealTimeClock<Float>.static class
Easy access class RealTimeClock<FloatDuration>.static class
Easy access class RealTimeClock<Long>.Nested classes/interfaces inherited from class nl.tudelft.simulation.dsol.simulators.Simulator
Simulator.SimulatorWorkerThread
Nested classes/interfaces inherited from interface nl.tudelft.simulation.dsol.simulators.AnimatorInterface
AnimatorInterface.AnimationThread
-
Field Summary
Modifier and TypeFieldDescriptionstatic final org.djutils.event.EventType
the backlog event.static final org.djutils.event.EventType
the speed factor event.Fields inherited from class nl.tudelft.simulation.dsol.simulators.DevsSimulator
eventList
Fields inherited from class nl.tudelft.simulation.dsol.simulators.Simulator
model, replication, replicationState, runflag, runState, runUntilIncluding, runUntilTime, semaphore, simulatorTime, worker
Fields inherited from interface nl.tudelft.simulation.dsol.simulators.AnimatorInterface
ANIMATION_DELAY_CHANGED_EVENT, DEFAULT_ANIMATION_DELAY, UPDATE_ANIMATION_EVENT
Fields inherited from interface nl.tudelft.simulation.dsol.simulators.DevsSimulatorInterface
EVENTLIST_CHANGED_EVENT
Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITION
Fields inherited from interface nl.tudelft.simulation.dsol.simulators.SimulatorInterface
START_EVENT, STARTING_EVENT, STOP_EVENT, STOPPING_EVENT, TIME_CHANGED_EVENT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondouble
int
The relative update delay in milliseconds is the step size in wall clock time by which the time is updated between events.boolean
boolean
void
run()
The run method defines the actual time step mechanism of the simulator.void
setAnimation
(boolean animation) Indicate whether we support animation or not.void
setCatchup
(boolean catchup) void
setSpeedFactor
(double newSpeedFactor) Set the speedFactor, and send a CHANGE_SPEED_FACTOR event.void
setSpeedFactor
(double newSpeedFactor, boolean fireChangeSpeedFactorEvent) Set the speedFactor, and send a CHANGE_SPEED_FACTOR event.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.protected abstract T
simulatorTimeForWallClockMillis
(double wallMilliseconds) Calculate the how much simulation duration corresponds to the number of wall clock milliseconds indicated in the parameter.Methods inherited from class nl.tudelft.simulation.dsol.simulators.DevsAnimator
getAnimationDelay, setAnimationDelay, updateAnimation
Methods inherited from class nl.tudelft.simulation.dsol.simulators.DevsSimulator
cancelEvent, endReplication, getEventList, initialize, isPauseOnError, scheduleEvent, scheduleEventAbs, scheduleEventAbs, scheduleEventAbs, scheduleEventAbs, scheduleEventNow, scheduleEventNow, scheduleEventNow, scheduleEventNow, scheduleEventRel, scheduleEventRel, scheduleEventRel, scheduleEventRel, setEventList, setPauseOnError, stepImpl
Methods inherited from class nl.tudelft.simulation.dsol.simulators.Simulator
addScheduledMethodOnInitialize, cleanUp, fireTimedEvent, getErrorLogLevel, getErrorStrategy, getLogger, getModel, getReplication, getReplicationState, getRunState, getSimulatorTime, handleSimulationException, runUpTo, runUpToAndIncluding, setErrorLogLevel, setErrorStrategy, setErrorStrategy, start, startImpl, step, stop, stopImpl, warmup
Methods inherited from class org.djutils.event.LocalEventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface nl.tudelft.simulation.dsol.simulators.DevsSimulatorInterface
cancelEvent, getEventList, isPauseOnError, scheduleEvent, scheduleEventAbs, scheduleEventAbs, scheduleEventAbs, scheduleEventAbs, scheduleEventAbs, scheduleEventAbs, scheduleEventNow, scheduleEventNow, scheduleEventNow, scheduleEventNow, scheduleEventNow, scheduleEventNow, scheduleEventRel, scheduleEventRel, scheduleEventRel, scheduleEventRel, scheduleEventRel, scheduleEventRel, setEventList, setPauseOnError
Methods inherited from interface org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
Methods inherited from interface nl.tudelft.simulation.dsol.simulators.SimulatorInterface
addScheduledMethodOnInitialize, addScheduledMethodOnInitialize, cleanUp, endReplication, getErrorLogLevel, getErrorStrategy, getLogger, getModel, getReplication, getReplicationState, getRunState, getSimulatorTime, initialize, isInitialized, isStartingOrRunning, isStoppingOrStopped, runUpTo, runUpToAndIncluding, setErrorLogLevel, setErrorStrategy, setErrorStrategy, start, step, stop
-
Field Details
-
BACKLOG_EVENT
public static final org.djutils.event.EventType BACKLOG_EVENTthe backlog event. -
CHANGE_SPEED_FACTOR_EVENT
public static final org.djutils.event.EventType CHANGE_SPEED_FACTOR_EVENTthe speed factor event.
-
-
Constructor Details
-
DevsRealTimeAnimator
Constructs a new DevsRealTimeClock.- Parameters:
id
- the id of the simulator, used in logging and firing of events.
-
-
Method Details
-
simulatorTimeForWallClockMillis
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 interfaceRunnable
- Overrides:
run
in classDevsAnimator<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 setfireChangeSpeedFactorEvent
- 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
-