public class Simulator
extends java.lang.Object
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 Sim class.
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.
| Modifier and Type | Field and Description |
|---|---|
static Simulator |
defaultSimulator
|
| 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.
|
| Modifier and Type | Method and Description |
|---|---|
ContinuousState |
continuousState()
Returns the current state of continuous variables being
integrated during the simulation.
|
static Simulator |
getDefaultSimulator()
Returns the default simulator instance used by
the deprecated class
Sim. |
EventList |
getEventList()
Gets the currently used event list.
|
void |
init()
Reinitializes the simulation executive by clearing up the event
list, and resetting the simulation clock to zero.
|
void |
init(EventList evlist)
Same as
init, but also chooses evlist as the
event list to be used. |
boolean |
isSimulating()
Determines if this simulator is currently running, i.e.,
executing scheduled events.
|
boolean |
isStopped()
Determines if this simulator was stopped by
an event.
|
void |
start()
Starts the simulation executive.
|
void |
stop()
Tells the simulation executive to stop as soon as it takes control,
and to return control to the program that called
start. |
double |
time()
Returns the current value of the simulation clock.
|
public static Simulator defaultSimulator
Sim, and the no-argument constructor of Event.
This simulator is usually obtained with the
getDefaultSimulator method, which initializes it if needed.
But it might also be initialized
differently, e.g., if process-driven simulation is required.public Simulator()
public Simulator(EventList eventList)
public double time()
public void init()
public void init(EventList evlist)
init, 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.evlist - selected event list implementationpublic EventList getEventList()
public boolean isSimulating()
public boolean isStopped()
stop method; in this case,
isSimulating returns true.public void start()
public void stop()
start.
This program will then continue executing from the instructions right after
its call to start If an Event is currently executing (and
this event has just called stop), the executive will take
control when the event terminates its execution.public ContinuousState continuousState()
Continuous class when performing
simulation of continuous variables; it defaults to an empty state,
which is initialized only when this method is called.public static Simulator getDefaultSimulator()
Sim.
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.To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.