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

Type Parameters:
T - the simulation time type based on the absolute and relative time.
All Implemented Interfaces:
Serializable, Runnable, Remote, DevsSimulatorInterface<T>, SimulatorInterface<T>, EventProducer
Direct Known Subclasses:
DevDessSimulator, DevsAnimator

public class DevsSimulator<T extends Number & Comparable<T>> extends Simulator<T> implements DevsSimulatorInterface<T>
The DEVS defines the interface of the DEVS simulator. DEVS stands for the Discrete Event System Specification. More information on Discrete Event Simulation can be found in "Theory of Modeling and Simulation" by Bernard Zeigler et.al.

Copyright (c) 2002-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:
Peter Jacobs , Alexander Verbraeck
See Also:
  • Field Details

  • Constructor Details

    • DevsSimulator

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

    • cancelEvent

      public boolean cancelEvent(SimEventInterface<T> event)
      cancels an event from the event list.
      Specified by:
      cancelEvent in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      event - SimEventInterface<T>; a simulation event to be canceled.
      Returns:
      boolean the succes of the operation.
    • getEventList

      public EventListInterface<T> getEventList()
      returns the eventlist of the simulator.
      Specified by:
      getEventList in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Returns:
      the eventlist.
    • initialize

      public void initialize(DsolModel<T,? extends SimulatorInterface<T>> model, Replication<T> replication) throws SimRuntimeException
      Initializes the simulator with a replication for a model. It immediately fires a START_REPLICATION_EVENT and a TIME_CHANGED_EVENT with the starting time. It does not yet fire a WARMUP_EVENT in case the warmup time is zero; this will only be done after the simulator has been started. Note that the listeners of all statistics objects are removed when the simulator is initialized with the replication. Connecting the statistics objects to the simulation should be done between the initialize(...) method and starting the simulator, or could even be delayed till the WARMUP_EVENT has been fired.
      Specified by:
      initialize in interface SimulatorInterface<T extends Number & Comparable<T>>
      Overrides:
      initialize in class Simulator<T extends Number & Comparable<T>>
      Parameters:
      model - DsolModel<T, S>; the model to initialize
      replication - Replication<T, ? extends SimulatorInterface<T>>; the replication to use for running the model
      Throws:
      SimRuntimeException - when the simulator is running
    • scheduleEvent

      public SimEventInterface<T> scheduleEvent(SimEventInterface<T> event) throws SimRuntimeException
      Method scheduleEvent schedules an event on the eventlist.
      Specified by:
      scheduleEvent in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      event - SimEventInterface<T>; a simulation event
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever event is scheduled in past.
    • scheduleEventRel

      public SimEventInterface<T> scheduleEventRel(T relativeDelay, short priority, Object target, String method, Object[] args) throws SimRuntimeException
      schedules a methodCall at a relative duration. The executionTime is thus simulator.getSimulatorTime()+relativeDuration.
      Specified by:
      scheduleEventRel in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      relativeDelay - T; the relativeDelay in timeUnits of the simulator.
      priority - short; the priority compared to other events scheduled at the same time.
      target - Object; the target
      method - String; the method
      args - Object[]; the arguments.
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventRel

      public SimEventInterface<T> scheduleEventRel(T relativeDelay, Object target, String method, Object[] args) throws SimRuntimeException
      schedules a methodCall at a relative duration. The executionTime is thus simulator.getSimulatorTime()+relativeDuration.
      Specified by:
      scheduleEventRel in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      relativeDelay - T; the relativeDelay in timeUnits of the simulator.
      target - Object; the target
      method - String; the method
      args - Object[]; the arguments.
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventAbs

      public SimEventInterface<T> scheduleEventAbs(T absoluteTime, short priority, Object target, String method, Object[] args) throws SimRuntimeException
      schedules a methodCall at an absolute time.
      Specified by:
      scheduleEventAbs in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      absoluteTime - T; the exact time to schedule the method on the simulator.
      priority - short; the priority compared to other events scheduled at the same time.
      target - Object; the target
      method - String; the method
      args - Object[]; the arguments.
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventAbs

      public SimEventInterface<T> scheduleEventAbs(T absoluteTime, Object target, String method, Object[] args) throws SimRuntimeException
      schedules a methodCall at an absolute time.
      Specified by:
      scheduleEventAbs in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      absoluteTime - T; the exact time to schedule the method on the simulator.
      target - Object; the target
      method - String; the method
      args - Object[]; the arguments.
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventNow

      public SimEventInterface<T> scheduleEventNow(short priority, Object target, String method, Object[] args) throws SimRuntimeException
      schedules a methodCall immediately.
      Specified by:
      scheduleEventNow in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      priority - short; the priority compared to other events scheduled at the same time.
      target - Object; the target
      method - String; the method
      args - Object[]; the arguments.
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventNow

      public SimEventInterface<T> scheduleEventNow(Object target, String method, Object[] args) throws SimRuntimeException
      schedules a methodCall immediately.
      Specified by:
      scheduleEventNow in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      target - Object; the target
      method - String; the method
      args - Object[]; the arguments.
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventRel

      public SimEventInterface<T> scheduleEventRel(T relativeDelay, short priority, Executable executable) throws SimRuntimeException
      schedules a lambda expression at a relative duration. The executionTime is thus simulator.getSimulatorTime()+relativeDuration.
      Specified by:
      scheduleEventRel in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      relativeDelay - T; the relativeDelay in timeUnits of the simulator.
      priority - short; the priority compared to other events scheduled at the same time.
      executable - Executable; the lambda expression to execute
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventRel

      public SimEventInterface<T> scheduleEventRel(T relativeDelay, Executable executable) throws SimRuntimeException
      schedules a lambda expression at a relative duration. The executionTime is thus simulator.getSimulatorTime()+relativeDuration.
      Specified by:
      scheduleEventRel in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      relativeDelay - T; the relativeDelay in timeUnits of the simulator.
      executable - Executable; the lambda expression to execute
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventAbs

      public SimEventInterface<T> scheduleEventAbs(T absoluteTime, short priority, Executable executable) throws SimRuntimeException
      schedules a lambda expression at an absolute time.
      Specified by:
      scheduleEventAbs in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      absoluteTime - T; the exact time to schedule the method on the simulator.
      priority - short; the priority compared to other events scheduled at the same time.
      executable - Executable; the lambda expression to execute
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventAbs

      public SimEventInterface<T> scheduleEventAbs(T absoluteTime, Executable executable) throws SimRuntimeException
      schedules a lambda expression at an absolute time.
      Specified by:
      scheduleEventAbs in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      absoluteTime - T; the exact time to schedule the method on the simulator.
      executable - Executable; the lambda expression to execute
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventNow

      public SimEventInterface<T> scheduleEventNow(short priority, Executable executable) throws SimRuntimeException
      schedules a lambda expression immediately.
      Specified by:
      scheduleEventNow in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      priority - short; the priority compared to other events scheduled at the same time.
      executable - Executable; the lambda expression to execute
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • scheduleEventNow

      public SimEventInterface<T> scheduleEventNow(Executable executable) throws SimRuntimeException
      schedules a lambda expression immediately.
      Specified by:
      scheduleEventNow in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      executable - Executable; the lambda expression to execute
      Returns:
      the simulation event so it can be cancelled later
      Throws:
      SimRuntimeException - whenever the event is scheduled in the past.
    • setEventList

      public void setEventList(EventListInterface<T> eventList)
      Method setEventList sets the eventlist.
      Specified by:
      setEventList in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      eventList - EventListInterface<T>; the eventList for the simulator.
    • stepImpl

      protected void stepImpl()
      The implementation body of the step() method. The stepImpl() method should fire the TIME_CHANGED_EVENT before the execution of the simulation event, or before executing the integration of the differential equation for the next timestep. So the time is changed first to match the logic carried out for that time, and then the action for that time is carried out. This is INDEPENDENT of the fact whether the time changes or not. The TIME_CHANGED_EVENT is always fired.
      Specified by:
      stepImpl in class Simulator<T extends Number & Comparable<T>>
    • 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
      Specified by:
      run in class Simulator<T extends Number & Comparable<T>>
    • endReplication

      public void endReplication()
      End the replication before the official ending time. When the simulation is running, it will fire a STOP_EVENT followed by an END_REPLICATION_EVENT, and will stop the running of the simulator, moving the RunState and the ReplicatioNState both to the ENDED state. When the simulation time is not equal to or larger than the length of the replication, a logger warning is given, but the method is fully executed. In that case it does set the simulation time to the end time of the replication, to avoid restarting of the simulator.
      Specified by:
      endReplication in interface SimulatorInterface<T extends Number & Comparable<T>>
      Overrides:
      endReplication in class Simulator<T extends Number & Comparable<T>>
    • isPauseOnError

      @Deprecated public boolean isPauseOnError()
      Deprecated.
      DEPRECATED: Replaced by getErrorHandler() and getErrorLogLevel().
      Specified by:
      isPauseOnError in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Returns:
      pauseOnError whether we pause on an error or not.
    • setPauseOnError

      @Deprecated public void setPauseOnError(boolean pauseOnError)
      Deprecated.
      DEPRECATED: Replaced by setErrorHandler() and setErrorLogLevel(). Set the boolean whether we pause on an error or not.
      Specified by:
      setPauseOnError in interface DevsSimulatorInterface<T extends Number & Comparable<T>>
      Parameters:
      pauseOnError - boolean; set true or false.