|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.xj.anylogic.engine.Engine
public final class Engine
The simulation engine that drives the model execution. The engine maintains
the event queue, the default random number generator, etc. Although there is
one engine per simulation, it is designed to have no static data, so
there may exist several concurrent simulations in one JVM, in particular, one
simulation can invoke the other, etc.
The engine behavior and usage patterns are best described with a statechart with
states IDLE, PAUSED, RUNNING, FINISHED, ERROR, PLEASE_WAIT. The normal usage
pattern of the engine controlled by the Presentation GUI is like this:
Engine engine = new Engine(); // -> IDLE; random number generator is initialized
The engine state PLEASE_WAIT means the engine is executing a non-interruptable
single command, such as pause(), step(), or stop().
If you do not need multithreading and wish to run the model as fast as possible
(i.e. in virtual time mode only) in the controlling thread, you may call runFast()
instead of run(). runFast() ignores any synchronization, therefore you should not
access the model data (e.g. call drawing of active objects) concurrently with
runFast().
ActiveObject root = new RootActiveObject( engine, null, null );
...//setup parameters of root
engine.start( root ); // -> PAUSED
engine.run(); // -> RUNNING; launches execution in a new thread, calls the experiment back on finish
...
engine.pause(); // -> PAUSED
engine.step(); // -> PAUSED
engine.run(); // -> RUNNING
...
engine.stop(); // -> IDLE completely destroys the model
...
ActiveObject root2 = new RootActiveObject2( engine, null, null );
...etc.
| Field Summary | |
|---|---|
static int |
ERROR
|
static int |
EVENT_SELECTION_DETERMINISTIC
Deprecated. Use EVENT_SELECTION_LIFO or EVENT_SELECTION_FIFO instead |
static int |
EVENT_SELECTION_FIFO
Deterministic selection mode (first in - first out) constant for setSimultaneousEventsSelectionMode(int)Offers good performance, simultaneous events are executed in the same order they were scheduled. |
static int |
EVENT_SELECTION_LIFO
Deterministic selection mode (last in - first out) constant for setSimultaneousEventsSelectionMode(int)Offers good performance, simultaneous events are executed in the reverse to the order they were scheduled |
static int |
EVENT_SELECTION_RANDOM
Random selection mode constant for setSimultaneousEventsSelectionMode(int)This mode is slower than EVENT_SELECTION_FIFO or EVENT_SELECTION_LIFOThis mode utilises the default random number generator of the Engine. |
static int |
FINISHED
|
static int |
IDLE
|
static int |
MODEL_TYPE_CONTINUOUS
|
static int |
MODEL_TYPE_DISCRETE
|
static int |
MODEL_TYPE_HYBRID
|
static int |
MODEL_TYPE_UNKNOWN
|
static int |
PAUSED
|
static int |
PLEASE_WAIT
|
static int |
RUNNING
|
static int |
SOLVER_DAE_EULER_NEWTON
|
static int |
SOLVER_DAE_RK45_NEWTON
|
static int |
SOLVER_NAE_CLASSIC_NEWTON
|
static int |
SOLVER_NAE_FAST_NEWTON
|
static int |
SOLVER_NAE_MODIFIED_NEWTON
|
static int |
SOLVER_ODE_EULER
|
static int |
SOLVER_ODE_RK4
|
| Constructor Summary | |
|---|---|
Engine()
Constructs the engine and sets the seed of the default random number generator to 0. |
|
| Method Summary | |
|---|---|
java.util.Date |
date()
Returns the current model date with respect to the start time/date and the model time unit. |
double |
dateToTime(java.util.Date d)
Converts the given date to model time with respect to the start date, start time and model time unit settings |
java.lang.RuntimeException |
error(java.lang.String errorText)
Signals an error during the model run by throwing a RuntineException with the given text. |
boolean |
finish()
Terminates the model after execution of current event. |
void |
flushSnapshotCache()
Clears cache with contents of recently loaded snapshot file NB: cache is automatically cleared on new snapshot loading |
int |
getAmPm()
Indicates whether the hour of the current model date with respect to the start time/date and the model time unit is before ( AM)
or after () noon. |
double |
getATOL()
Returns absolute tolerance of the numeric engine. |
java.util.Date |
getDate()
Deprecated. Use date() instead |
int |
getDayOfMonth()
Returns the day of the month of the current model date with respect to the start time/date and the model time unit. |
int |
getDayOfWeek()
Returns the day of the week of the current model date with respect to the start time/date and the model time unit. |
int |
getDayOfYear()
Returns the day of the year of the current model date with respect to the start time/date and the model time unit. |
java.util.Random |
getDefaultRandomGenerator()
Returns the currently used default random number generator. |
long |
getEventCount()
Returns the number of currently scheduled events. |
Experiment<?> |
getExperiment()
Returns the experiment controlling the model execution. |
java.lang.String |
getHeaderText()
|
int |
getHour()
Returns the hour of the morning or afternoon of the current model date with respect to the start time/date and the model time unit. |
int |
getHourOfDay()
Returns the hour of day of the current model date with respect to the start time/date and the model time unit. |
double |
getHTOL()
Returns fixed step of the numeric engine. |
int |
getMillisecond()
Returns the millisecond within the second of the current model date with respect to the start time/date and the model time unit. |
int |
getMinute()
Returns the minute within the hour of the current model date with respect to the start time/date and the model time unit. |
int |
getModelType()
Returns the type of model being executed: MODEL_TYPE_UNKNOWN - the model is either empty or it is too early to judge MODEL_TYPE_DISCRETE - the model so far had at least one discrete event and no equations MODEL_TYPE_CONTINUOUS - the model so far had at equation and no discrete events MODEL_TYPE_HYBRID the model had both events and equations |
int |
getMonth()
Returns the month of the current model date with respect to the start time/date and the model time unit. |
java.lang.String |
getPopUpText()
|
Presentation |
getPresentation()
Returns the presentation object associated with this engine, or null if there is none. |
double |
getProgress()
Returns the progress of the simulation: the part of model time simulated so far in case the stop time is set, or -1 if it is not set. |
boolean |
getRealTimeMode()
Returns true if the current execution mode is real time, false if virtual time. |
double |
getRealTimeScale()
Returns the currently set model time to real time scale. |
ActiveObject |
getRoot()
Returns the root active object setup for the engine (the topmost level active object from which the model creation and execution starts). |
double |
getRTOL()
Returns relative tolerance of the numeric engine. |
int |
getRunCount()
Returns the number of the current simulation run, more precisely the number of times the model was destroyed. |
long |
getRunTimeMillis()
Returns the real duration of the simulation run in milliseconds, excluding pause times. |
int |
getSecond()
Returns the second within the minute of the current model date with respect to the start time/date and the model time unit. |
int |
getSolverDAE()
Returns solver type for mixed differential-algebraic equations |
int |
getSolverNAE()
Returns solver type for algebraic equations |
int |
getSolverODE()
Returns solver type for ordinary differential equations |
java.util.Date |
getStartDate()
Returns the date corresponding to the start time of the simulation. |
double |
getStartTime()
Returns the currently set start time - the model time at which the simulation starts, by default it is 0. |
long |
getStartTimeMillis()
Returns the result of a call to System.currentTimeMillis() at the simulation start. |
int |
getState()
Returns the current state of the engine: IDLE - no model is set for execution, doing nothing PAUSED - model is set and have started, ready to run or make a step RUNNING - in the loop of model execution invoked by run() or runFast() FINISHED - the model execution is finished OK, but the model is not yet destroyed ERROR - the model execution is finished with error, the model is not yet destroyed PLEASE_WAIT - in the process of executing a non-interruptable command like pause(), step() or stop() The state is however not guaranteed as may be modified concurrently. |
long |
getStep()
Returns the number of events executed by the engine. |
java.util.Date |
getStopDate()
Returns the date corresponding to the stop time, null if the stop time is infinity. |
double |
getStopTime()
Returns the currently set stop time - the model time at which the simulation should stop, or Double.POSITIVE_INFINITY if stop time is not set. |
double |
getTime()
Deprecated. Use time() instead. |
long |
getTimeUnit()
Returns the currently set real time unit corresponding to the model time unit. 1 means millisecond, 1,000 - second, 60,000 - minute, etc. |
double |
getTTOL()
Returns time tolerance of the numeric engine. |
java.lang.Number |
getVMethods()
|
int |
getYear()
Returns the year of the current model date with respect to the start time/date and the model time unit. |
boolean |
isRealTimeMaintained()
This method is not designed to be called by user is public due to technical reasons |
ActiveObject |
loadRootObjectFromSnapshot(java.lang.String snapshotFileName)
Loads and sets root object from the given snapshot with caching contents of snapshot file (for performance speed-up) This method supports loading from snapshots created with any experiment with animation (i.e. not custom) and from snapshots saved using saveRootObjectSnapshot(String) method |
ActiveObject |
loadRootObjectFromSnapshot(java.lang.String snapshotFileName,
boolean cacheSnapshot)
Loads and sets root object from the given snapshot with optional caching contents of snapshot file (for performance speed-up) This method supports loading from snapshots created with any experiment with animation (i.e. not custom) and from snapshots saved using saveRootObjectSnapshot(String) method |
boolean |
pause()
Engine command applicable only in RUNNING state (in other states does nothing and returns false). |
void |
registerActiveObjectWithEquations(ActiveObject ao)
Registers given active object with equations in Engine equations solver. |
void |
registerDelay(VariableDelay variableDelay)
Registers given delay in Engine equations solver. |
boolean |
run()
Engine command applicable only in PAUSED state (in other states does nothing and returns false). |
boolean |
runFast()
Runs the model in the fastest possible way in the same (calling) thread. |
boolean |
runFast(double pauseTime)
Calls runFast() but pauses the model execution at
the specified model time and returns trueIf the model finishes (because of stop time or finish() method called) before the pauseTime, the method runs the model until the
finish moment only. |
void |
saveRootObjectSnapshot(java.lang.String snapshotFileName)
Saves root object and current state of this Engine to a snapshot file with the given name. |
void |
setATOL(double atol)
Sets the absolute tolerance of the numeric engine. |
void |
setDefaultRandomGenerator(java.util.Random r)
Changes the default random number generator. |
void |
setExperiment(Experiment<?> ex)
Sets the experiment that will be controlling the model execution. |
void |
setHTOL(double htol)
Sets the fixed step of the numeric engine. |
void |
setPresentation(Presentation p)
Sets the presentation object that will be displaying the model execution. |
void |
setRealTimeMode(boolean on)
Sets the virtual or real time execution mode. |
void |
setRealTimeScale(double scale)
Sets the model time to real time scale. |
void |
setRTOL(double rtol)
Sets the relative tolerance of the numeric engine. |
void |
setSimultaneousEventsSelectionMode(int mode)
Sets the mode of event selection among simultaneous events (if any occur) The default mode is EVENT_SELECTION_DETERMINISTIC |
void |
setSolverDAE(int solverDAE)
Sets solver type for mixed differential-algebraic equations Available solvers: SOLVER_DAE_RK45_NEWTON (default)
SOLVER_DAE_EULER_NEWTON
|
void |
setSolverNAE(int solverNAE)
Sets solver type for algebraic equations Available solvers: SOLVER_NAE_MODIFIED_NEWTON (default)
SOLVER_NAE_FAST_NEWTON
SOLVER_NAE_CLASSIC_NEWTON
|
void |
setSolverODE(int solverODE)
Sets solver type for ordinary differential equations Available solvers: SOLVER_ODE_EULER (default)
SOLVER_ODE_RK4
|
void |
setStartDate(java.util.Date date)
Sets the date corresponding to the start time of the simulation. |
void |
setStartTime(double tstart)
Sets the start time for the simulation - the initial value of the model clock. |
void |
setStopDate(java.util.Date date)
Sets the stop time of the simulation by converting the stop date provided to the model time, subject to the start time, start date and time unit settings. |
void |
setStopTime(double tstop)
Sets the stop time for the simulation. |
void |
setTimeUnit(long tu)
Sets the correspondance between the model time unit and a real time unit. |
void |
setTTOL(double ttol)
Sets the time tolerance of the numeric engine. |
void |
setVMethods(java.lang.Number n)
|
boolean |
start(ActiveObject root)
Engine command applicable only in IDLE state (in other states does nothing and returns false). |
boolean |
step()
Makes at most one discrete step of the model (can be done from the PAUSED state only). |
boolean |
stop()
Stops and destroys the model, see also finish() method,
which doesn't destroy the model. |
void |
submitPredicate(EventOriginator eo)
Registers an EventOriginator instance in 'predicates' array. |
double |
time()
Returns the current model (logical) time. |
java.util.Date |
timeToDate(double t)
Converts the given model time to date with respect to the start date, start time and model time unit settings, null if the time is infinity. |
boolean |
unregisterActiveObjectWithEquations(ActiveObject ao)
Unregisters the active object from the engine equations solver. |
void |
unregisterDelay(VariableDelay variableDelay)
Unregisters the delay from the engine equations solver. |
boolean |
unsubmitPredicate(EventOriginator eo)
Unregisters given EventOriginator from the list 'predicates'. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MODEL_TYPE_UNKNOWN
public static final int MODEL_TYPE_DISCRETE
public static final int MODEL_TYPE_CONTINUOUS
public static final int MODEL_TYPE_HYBRID
public static final int EVENT_SELECTION_LIFO
setSimultaneousEventsSelectionMode(int)
public static final int EVENT_SELECTION_FIFO
setSimultaneousEventsSelectionMode(int)
@Deprecated public static final int EVENT_SELECTION_DETERMINISTIC
EVENT_SELECTION_LIFO or EVENT_SELECTION_FIFO insteadsetSimultaneousEventsSelectionMode(int)
public static final int EVENT_SELECTION_RANDOM
setSimultaneousEventsSelectionMode(int)EVENT_SELECTION_FIFO or EVENT_SELECTION_LIFO
public static final int IDLE
public static final int PAUSED
public static final int RUNNING
public static final int FINISHED
public static final int ERROR
public static final int PLEASE_WAIT
public static final int SOLVER_ODE_EULER
public static final int SOLVER_ODE_RK4
public static final int SOLVER_NAE_MODIFIED_NEWTON
public static final int SOLVER_NAE_FAST_NEWTON
public static final int SOLVER_NAE_CLASSIC_NEWTON
public static final int SOLVER_DAE_RK45_NEWTON
public static final int SOLVER_DAE_EULER_NEWTON
| Constructor Detail |
|---|
public Engine()
ExperimentCustom.createEngine() method instead of this constructor
to create and obtain new instance of the engine
| Method Detail |
|---|
public ActiveObject getRoot()
public java.lang.RuntimeException error(java.lang.String errorText)
errorText - the text describing the error that will be displayed.
throw error("my message");public double time()
@Deprecated public double getTime()
time() instead.
public double getProgress()
public void setStartTime(double tstart)
tstart - the simulation start time.public double getStartTime()
public void setStopTime(double tstop)
tstop - the (model) time to stop the simulation.public double getStopTime()
public java.util.Date date()
@Deprecated public java.util.Date getDate()
date() instead
public int getMillisecond()
public int getSecond()
public int getMinute()
public int getHour()
getAmPm(),
getHourOfDay()public int getAmPm()
AM)
or after (Utilities.PM) noon.Utilities.PM.
Utilities.AM or Utilities.PM depending on the hour of
the current model date with respect to the start time/date and the model time unitgetHour(),
getHourOfDay()public int getHourOfDay()
getHour(),
getAmPm()public int getDayOfWeek()
Utilities.SUNDAY
Utilities.MONDAY
Utilities.TUESDAY
Utilities.WEDNESDAY
Utilities.THURSDAY
Utilities.FRIDAY
Utilities.SATURDAY
public int getDayOfMonth()
public int getDayOfYear()
public int getMonth()
JANUARY which is 0; the last depends on the number of
months in a year.Utilities.JANUARY
Utilities.FEBRUARY
Utilities.MARCH
Utilities.APRIL
Utilities.MAY
Utilities.JUNE
Utilities.JULY
Utilities.AUGUST
Utilities.SEPTEMBER
Utilities.OCTOBER
Utilities.NOVEMBER
Utilities.DECEMBER
Utilities.UNDECIMBER (indicates the
thirteenth month of the year. Although GregorianCalendar
does not use this value, lunar calendars do)
public int getYear()
public double dateToTime(java.util.Date d)
d - the date to convert
public java.util.Date timeToDate(double t)
t - the model time
public void setStartDate(java.util.Date date)
date - the date corresponding to the start time of the simulation
(composed in the default time zone)public java.util.Date getStartDate()
public void setStopDate(java.util.Date date)
date - the stop date for the simulation (composed in the default time zone)public java.util.Date getStopDate()
public void setTimeUnit(long tu)
tu - the real time unit corresponding to the model time unitpublic long getTimeUnit()
public int getRunCount()
public long getStep()
public long getEventCount()
public long getStartTimeMillis()
public long getRunTimeMillis()
public final void setVMethods(java.lang.Number n)
public final java.lang.Number getVMethods()
public int getModelType()
public void setRealTimeMode(boolean on)
on - true means execution in scale to real timepublic boolean getRealTimeMode()
public void setRealTimeScale(double scale)
scale - then new real time scalepublic double getRealTimeScale()
public boolean isRealTimeMaintained()
throws java.lang.Exception
java.lang.Exceptionpublic void setPresentation(Presentation p)
p - the presentation object displaying the modelpublic Presentation getPresentation()
public void setExperiment(Experiment<?> ex)
ex - the experimentpublic Experiment<?> getExperiment()
null for custom experiments
public void setATOL(double atol)
atol - the absolute tolerance to setpublic double getATOL()
public void setRTOL(double rtol)
rtol - the relative tolerance to setpublic double getRTOL()
public void setTTOL(double ttol)
ttol - the time tolerance to setpublic double getTTOL()
public void setHTOL(double htol)
htol - the fixed step to setpublic double getHTOL()
public int getSolverODE()
public void setSolverODE(int solverODE)
SOLVER_ODE_EULER (default)
SOLVER_ODE_RK4
solverODE - solver type for ordinary differential equationspublic int getSolverNAE()
public void setSolverNAE(int solverNAE)
solverNAE - solver type for algebraic equationspublic int getSolverDAE()
public void setSolverDAE(int solverDAE)
solverDAE - solver type for mixed differential-algebraic equationspublic void setSimultaneousEventsSelectionMode(int mode)
EVENT_SELECTION_DETERMINISTIC
mode - one of the following values:EVENT_SELECTION_FIFO - fast deterministic selection mode, simultaneous events are executed in the same order they were scheduled
EVENT_SELECTION_LIFO - fast deterministic selection mode, simultaneous events are executed in the reverse to the order they were scheduled
EVENT_SELECTION_RANDOM - random (but slow) selection mode
public final java.lang.String getHeaderText()
public final java.lang.String getPopUpText()
public int getState()
public boolean start(ActiveObject root)
public boolean step()
public boolean run()
public boolean runFast()
public boolean runFast(double pauseTime)
runFast() but pauses the model execution at
the specified model time and returns truepauseTime, the method runs the model until the
finish moment only.
pauseTime - the time to pause model execution
runFast()public boolean pause()
false). Puts the engine into PLEASE_WAIT state and then sets a flag
that, when tested by the engine, causes it to pause after completing the
current event execution. Further behavior depends on context where this method is called:
true immediately. Model is paused just after
current event execution
true.
public boolean finish()
false). Sets a flag that, when tested by the engine,
causes it to finish after completing the current event execution. Further behavior
depends on context where this method is called:
true immediately.
Model is finished just after current event execution (After Simulation Run code
of an experiment may be used to handle this moment)true.
false if the engine state does not allow terminating
(engine is neither running nor paused)public boolean stop()
finish() method,
which doesn't destroy the model.true
immediately, leaving the model in PLEASE_WAIT state. Model is stopped and destroyed
some time later (After Simulation Run code of an experiment or On Destroy code
of root Active Object may be used to handle this moment)finish() method
in such situations
true.
public void registerActiveObjectWithEquations(ActiveObject ao)
ao - the active object that has equations and registerspublic boolean unregisterActiveObjectWithEquations(ActiveObject ao)
ao - the active object that had equations but now unregisterspublic void registerDelay(VariableDelay variableDelay)
variableDelay - delaypublic void unregisterDelay(VariableDelay variableDelay)
variableDelay - delaypublic void submitPredicate(EventOriginator eo)
eo - public boolean unsubmitPredicate(EventOriginator eo)
eo -
public java.util.Random getDefaultRandomGenerator()
public void setDefaultRandomGenerator(java.util.Random r)
r - the new random number generator.public void saveRootObjectSnapshot(java.lang.String snapshotFileName)
runFast() method).
Also, this method shouldn't be called when this engine is in
RUNNING state.loadRootObjectFromSnapshot methods, i.e. it isn't
compatible with any experiments with animation (i.e. not custom)
snapshotFileName - the absolute path to the snapshot filepublic ActiveObject loadRootObjectFromSnapshot(java.lang.String snapshotFileName)
saveRootObjectSnapshot(String) method
snapshotFileName - the absolute path to the snapshot fileflushSnapshotCache(),
loadRootObjectFromSnapshot(String, boolean)
public ActiveObject loadRootObjectFromSnapshot(java.lang.String snapshotFileName,
boolean cacheSnapshot)
saveRootObjectSnapshot(String) method
snapshotFileName - the absolute path to the snapshot filecacheSnapshot - if true, snapshot file
will be cached for performance speed-upflushSnapshotCache()public void flushSnapshotCache()
loadRootObjectFromSnapshot(String),
loadRootObjectFromSnapshot(String, boolean)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||