Class Simulator
- java.lang.Object
-
- umontreal.iro.lecuyer.simevents.Simulator
-
- Direct Known Subclasses:
- ProcessSimulator
public class Simulator extends java.lang.ObjectRepresents the executive of a discrete-event simulator. This class maintains a simulation clock, an event list, and starts executing the events in the appropriate order. Its methods permit one to start, stop, and (re)initialize the simulation, and read the simulation clock.Usually, a simulation program uses a single simulation clock which is represented by an instance of this class. For more convenience and compatibility, this class therefore provides a mechanism to construct and return a default simulator which is used when an event is constructed without an explicit reference to a simulator, and when the simulator is accessed through the
Simclass.Note that this class is NOT thread-safe. Consequently, if a simulation program uses multiple threads, it should acquire a lock on a simulator (using a synchronized block) before accessing its state. Note however, that one can launch many simulations in parallel with as many threads, as long as each thread has its own Simulator.
-
-
Field Summary
Fields Modifier and Type Field and Description static SimulatordefaultSimulator
-
Constructor Summary
Constructors Constructor and Description Simulator()Constructs a new simulator using a splay tree for the event list.Simulator(EventList eventList)Constructs a new simulator using eventList for the event list.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description ContinuousStatecontinuousState()Returns the current state of continuous variables being integrated during the simulation.static SimulatorgetDefaultSimulator()Returns the default simulator instance used by the deprecated classSim.EventListgetEventList()Gets the currently used event list.voidinit()Reinitializes the simulation executive by clearing up the event list, and resetting the simulation clock to zero.voidinit(EventList evlist)Same asinit, but also chooses evlist as the event list to be used.booleanisSimulating()Determines if this simulator is currently running, i.e., executing scheduled events.booleanisStopped()Determines if this simulator was stopped by an event.voidstart()Starts the simulation executive.voidstop()Tells the simulation executive to stop as soon as it takes control, and to return control to the program that calledstart.doubletime()Returns the current value of the simulation clock.
-
-
-
Field Detail
-
defaultSimulator
public static Simulator defaultSimulator
Represents the default simulator being used by the classSim, and the no-argument constructor ofEvent. This simulator is usually obtained with thegetDefaultSimulatormethod, which initializes it if needed. But it might also be initialized differently, e.g., if process-driven simulation is required.
-
-
Constructor Detail
-
Simulator
public Simulator()
Constructs a new simulator using a splay tree for the event list.
-
Simulator
public Simulator(EventList eventList)
Constructs a new simulator using eventList for the event list.
-
-
Method Detail
-
time
public double time()
Returns the current value of the simulation clock.- Returns:
- the current simulation time
-
init
public void init()
Reinitializes the simulation executive by clearing up the event list, and resetting the simulation clock to zero.
-
init
public void init(EventList evlist)
Same asinit, but also chooses evlist as the event list to be used. For example, init (new DoublyLinked()) initializes the simulation with a doubly linked linear structure for the event list. To initialize the current Simulator with a not empty eventList is also possible, but the events scheduled in the eventList will be linked with the current simulator only.- Parameters:
evlist- selected event list implementation
-
getEventList
public EventList getEventList()
Gets the currently used event list.- Returns:
- the currently used event list
-
isSimulating
public boolean isSimulating()
Determines if this simulator is currently running, i.e., executing scheduled events.
-
isStopped
public boolean isStopped()
Determines if this simulator was stopped by an event. The simulator may still be processing the event which has called thestopmethod; in this case,isSimulatingreturns true.
-
start
public void start()
Starts the simulation executive. There must be at least one Event in the event list when this method is called.
-
stop
public void stop()
Tells the simulation executive to stop as soon as it takes control, and to return control to the program that calledstart. This program will then continue executing from the instructions right after its call tostartIf anEventis currently executing (and this event has just calledstop), the executive will take control when the event terminates its execution.
-
continuousState
public ContinuousState continuousState()
Returns the current state of continuous variables being integrated during the simulation. This state is used by theContinuousclass when performing simulation of continuous variables; it defaults to an empty state, which is initialized only when this method is called.- Returns:
- continuousState field
-
getDefaultSimulator
public static Simulator getDefaultSimulator()
Returns the default simulator instance used by the deprecated classSim. If this simulator does not exist yet, it is constructed using the no-argument constructor of this class. One can specify a different default simulator by setting the defaultSimulator field directly.
-
-
DMelt 3.0 © DataMelt by jWork.ORG