com.xj.anylogic.engine
Class Engine

java.lang.Object
  extended by com.xj.anylogic.engine.Engine
All Implemented Interfaces:
java.io.Serializable

public final class Engine
extends java.lang.Object
implements java.io.Serializable

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
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.
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().

Author:
XJ Technologies Company Ltd. www.anylogic.com
See Also:
Serialized Form

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_LIFO
This 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 (Utilities.PM) 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 true
If 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

MODEL_TYPE_UNKNOWN

public static final int MODEL_TYPE_UNKNOWN
See Also:
Constant Field Values

MODEL_TYPE_DISCRETE

public static final int MODEL_TYPE_DISCRETE
See Also:
Constant Field Values

MODEL_TYPE_CONTINUOUS

public static final int MODEL_TYPE_CONTINUOUS
See Also:
Constant Field Values

MODEL_TYPE_HYBRID

public static final int MODEL_TYPE_HYBRID
See Also:
Constant Field Values

EVENT_SELECTION_LIFO

public static final 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

See Also:
Constant Field Values

EVENT_SELECTION_FIFO

public static final 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.

See Also:
Constant Field Values

EVENT_SELECTION_DETERMINISTIC

@Deprecated
public static final int EVENT_SELECTION_DETERMINISTIC
Deprecated. Use EVENT_SELECTION_LIFO or EVENT_SELECTION_FIFO instead
Deterministic selection mode constant for setSimultaneousEventsSelectionMode(int)
Offers good performance

See Also:
Constant Field Values

EVENT_SELECTION_RANDOM

public static final int EVENT_SELECTION_RANDOM
Random selection mode constant for setSimultaneousEventsSelectionMode(int)
This mode is slower than EVENT_SELECTION_FIFO or EVENT_SELECTION_LIFO
This mode utilises the default random number generator of the Engine.

See Also:
Constant Field Values

IDLE

public static final int IDLE
See Also:
Constant Field Values

PAUSED

public static final int PAUSED
See Also:
Constant Field Values

RUNNING

public static final int RUNNING
See Also:
Constant Field Values

FINISHED

public static final int FINISHED
See Also:
Constant Field Values

ERROR

public static final int ERROR
See Also:
Constant Field Values

PLEASE_WAIT

public static final int PLEASE_WAIT
See Also:
Constant Field Values

SOLVER_ODE_EULER

public static final int SOLVER_ODE_EULER
See Also:
Constant Field Values

SOLVER_ODE_RK4

public static final int SOLVER_ODE_RK4
See Also:
Constant Field Values

SOLVER_NAE_MODIFIED_NEWTON

public static final int SOLVER_NAE_MODIFIED_NEWTON
See Also:
Constant Field Values

SOLVER_NAE_FAST_NEWTON

public static final int SOLVER_NAE_FAST_NEWTON
See Also:
Constant Field Values

SOLVER_NAE_CLASSIC_NEWTON

public static final int SOLVER_NAE_CLASSIC_NEWTON
See Also:
Constant Field Values

SOLVER_DAE_RK45_NEWTON

public static final int SOLVER_DAE_RK45_NEWTON
See Also:
Constant Field Values

SOLVER_DAE_EULER_NEWTON

public static final int SOLVER_DAE_EULER_NEWTON
See Also:
Constant Field Values
Constructor Detail

Engine

public Engine()
Constructs the engine and sets the seed of the default random number generator to 0.
Normally this constructor calls are generated automatically by AnyLogic.

For AnyLogic Professional users: in custom experiments please use ExperimentCustom.createEngine() method instead of this constructor to create and obtain new instance of the engine

Method Detail

getRoot

public ActiveObject getRoot()
Returns the root active object setup for the engine (the topmost level active object from which the model creation and execution starts). Usually (and by default) it is an instance of ActiveObject class Main.

Returns:
the root active object

error

public java.lang.RuntimeException error(java.lang.String errorText)
Signals an error during the model run by throwing a RuntineException with the given text.

Parameters:
errorText - the text describing the error that will be displayed.
Returns:
actually this method never returns, it throws runtime exception by itself.
But the return type is defined for some cases when you would like to use the following form of call: throw error("my message");

time

public double time()
Returns the current model (logical) time. Time stays constant during an event execution and is only advanced between events.
TODO in real time model should return intermediate values during time step

Returns:
current model time

getTime

@Deprecated
public double getTime()
Deprecated. Use time() instead.

Returns the current model (logical) time.

Returns:
the current model (logical) time

getProgress

public 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. In IDLE and ERROR states also returns -1.

Returns:
the progress of the simulation

setStartTime

public void setStartTime(double tstart)
Sets the start time for the simulation - the initial value of the model clock. By default it is 0. Has no effect if called after the model starts running.

Parameters:
tstart - the simulation start time.

getStartTime

public double getStartTime()
Returns the currently set start time - the model time at which the simulation starts, by default it is 0.

Returns:
the simulation start time

setStopTime

public void setStopTime(double tstop)
Sets the stop time for the simulation. The simulation won't stop if the stop time set at runtime is earlier than the current model time or equals Double.POSITIVE_INFINITY. If any event(s) are scheduled exactly at stop time, they will be executed. By default the stop time is Double.POSITIVE_INFINITY, so the simulation may run infinitely.

Parameters:
tstop - the (model) time to stop the simulation.

getStopTime

public 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.

Returns:
the simulation stop time or Double.POSITIVE_INFINITY

date

public java.util.Date date()
Returns the current model date with respect to the start time/date and the model time unit.

Returns:
the current model date

getDate

@Deprecated
public java.util.Date getDate()
Deprecated. Use date() instead

Returns the current model date.

Returns:
the current model date

getMillisecond

public 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.
E.g., at 10:04:15.250 PM the result is 250.

Returns:
the millisecond within the second of the current model date with respect to the start time/date and the model time unit

getSecond

public 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.
E.g., at 10:04:15.250 PM the result is 15.

Returns:
the second within the minute of the current model date with respect to the start time/date and the model time unit

getMinute

public 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.
E.g., at 10:04:15.250 PM the result is 4.

Returns:
the minute within the hour of the current model date with respect to the start time/date and the model time unit

getHour

public 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.
This method is used for the 12-hour clock.
Noon and midnight are represented by 0, not by 12.
E.g., at 10:04:15.250 PM the result is 10.

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
See Also:
getAmPm(), getHourOfDay()

getAmPm

public 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 (Utilities.PM) noon.
This method is used for the 12-hour clock.
E.g., at 10:04:15.250 PM the result is Utilities.PM.

Returns:
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 unit
See Also:
getHour(), getHourOfDay()

getHourOfDay

public int getHourOfDay()
Returns the hour of day of the current model date with respect to the start time/date and the model time unit.
This method is used for the 24-hour clock.
E.g., at 10:04:15.250 PM the result is 22.

Returns:
the hour of day of the current model date with respect to the start time/date and the model time unit
See Also:
getHour(), getAmPm()

getDayOfWeek

public 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.
Returned value is one of:

Returns:
the day of the week of the current model date with respect to the start time/date and the model time unit

getDayOfMonth

public 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.
The first day of the month has value 1.

Returns:
the day of the month of the current model date with respect to the start time/date and the model time unit

getDayOfYear

public 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.
The first day of the year has value 1.

Returns:
the day of the year of the current model date with respect to the start time/date and the model time unit

getMonth

public int getMonth()
Returns the month of the current model date with respect to the start time/date and the model time unit.
This is a calendar-specific value.
The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.
Possible values:

Returns:
the month of the current model date with respect to the start time/date and the model time unit

getYear

public int getYear()
Returns the year of the current model date with respect to the start time/date and the model time unit.
This is a calendar-specific value

Returns:
the year of the current model date with respect to the start time/date and the model time unit

dateToTime

public 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

Parameters:
d - the date to convert
Returns:
the model time corresponding to date

timeToDate

public 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.

Parameters:
t - the model time
Returns:
the date corresponding to the given model time, or null

setStartDate

public void setStartDate(java.util.Date date)
Sets the date corresponding to the start time of the simulation.

Parameters:
date - the date corresponding to the start time of the simulation (composed in the default time zone)

getStartDate

public java.util.Date getStartDate()
Returns the date corresponding to the start time of the simulation.

Returns:
the date corresponding to the start time of the simulation (in local TimeZone set in the Java Virtual Machine)

setStopDate

public 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. Discards the previously set stop time.

Parameters:
date - the stop date for the simulation (composed in the default time zone)

getStopDate

public java.util.Date getStopDate()
Returns the date corresponding to the stop time, null if the stop time is infinity.

Returns:
the date corresponding to the stop time (in local TimeZone set in the Java Virtual Machine), or null

setTimeUnit

public void setTimeUnit(long tu)
Sets the correspondance between the model time unit and a real time unit. You may use constants TIME_UNIT_MILLISECOND, TIME_UNIT_SECOND, TIME_UNIT_MINUTE, etc., or provide your own one. The default value is TIME_UNIT_SECOND. This has nothing to do with the simulation real time mode but affects the conversion between the model time and date.

Parameters:
tu - the real time unit corresponding to the model time unit

getTimeUnit

public 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.

Returns:
the number of milliseconds per model time unit

getRunCount

public int getRunCount()
Returns the number of the current simulation run, more precisely the number of times the model was destroyed.

Returns:
the number of the current simulation run, more precisely the number of times the model was destroyed.

getStep

public long getStep()
Returns the number of events executed by the engine.

Returns:
the number of events executed

getEventCount

public long getEventCount()
Returns the number of currently scheduled events.

Returns:
the number of currently scheduled events

getStartTimeMillis

public long getStartTimeMillis()
Returns the result of a call to System.currentTimeMillis() at the simulation start.

Returns:
the system time at the simulation start

getRunTimeMillis

public long getRunTimeMillis()
Returns the real duration of the simulation run in milliseconds, excluding pause times.

Returns:
the real duration of the simulation run

setVMethods

public final void setVMethods(java.lang.Number n)

getVMethods

public final java.lang.Number getVMethods()

getModelType

public 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

Returns:
the type of model being executed

setRealTimeMode

public void setRealTimeMode(boolean on)
Sets the virtual or real time execution mode. In virtual time mode the model is executed as fast as possible, and no sleep() methods are executed. In real time mode the engine tries to maintain the given scale between model time and real time by executing sleep() if there remains any real time to spend in between two events.

Parameters:
on - true means execution in scale to real time

getRealTimeMode

public boolean getRealTimeMode()
Returns true if the current execution mode is real time, false if virtual time.

Returns:
the current model execution mode

setRealTimeScale

public void setRealTimeScale(double scale)
Sets the model time to real time scale. This will have effect when the model runs in real time execution mode

Parameters:
scale - then new real time scale

getRealTimeScale

public double getRealTimeScale()
Returns the currently set model time to real time scale. This scale only has effect in real time execution mode.

Returns:
the current real time scale

isRealTimeMaintained

public boolean isRealTimeMaintained()
                             throws java.lang.Exception
This method is not designed to be called by user
is public due to technical reasons

Throws:
java.lang.Exception

setPresentation

public void setPresentation(Presentation p)
Sets the presentation object that will be displaying the model execution. Engine needs to know the presentation to be able to notify it about destruction of active objects (they can be displayed), also the user can retrieve and access the presentation via engine.

Parameters:
p - the presentation object displaying the model

getPresentation

public Presentation getPresentation()
Returns the presentation object associated with this engine, or null if there is none.

Returns:
the presentation object of the model, or null

setExperiment

public void setExperiment(Experiment<?> ex)
Sets the experiment that will be controlling the model execution. Engine needs to know the experiment to be able to notify it about important events, also the user can retrieve and access the experiment via engine.

Parameters:
ex - the experiment

getExperiment

public Experiment<?> getExperiment()
Returns the experiment controlling the model execution.
Returns null for custom experiments

Returns:
the experiment controlling the model execution

setATOL

public void setATOL(double atol)
Sets the absolute tolerance of the numeric engine.

Parameters:
atol - the absolute tolerance to set

getATOL

public double getATOL()
Returns absolute tolerance of the numeric engine.

Returns:
absolute tolerance of the numeric engine

setRTOL

public void setRTOL(double rtol)
Sets the relative tolerance of the numeric engine.

Parameters:
rtol - the relative tolerance to set

getRTOL

public double getRTOL()
Returns relative tolerance of the numeric engine.

Returns:
relative tolerance of the numeric engine

setTTOL

public void setTTOL(double ttol)
Sets the time tolerance of the numeric engine.

Parameters:
ttol - the time tolerance to set

getTTOL

public double getTTOL()
Returns time tolerance of the numeric engine.

Returns:
time tolerance of the numeric engine

setHTOL

public void setHTOL(double htol)
Sets the fixed step of the numeric engine.

Parameters:
htol - the fixed step to set

getHTOL

public double getHTOL()
Returns fixed step of the numeric engine.

Returns:
fixed step of the numeric engine

getSolverODE

public int getSolverODE()
Returns solver type for ordinary differential equations

Returns:
solver type for ordinary differential equations

setSolverODE

public void setSolverODE(int solverODE)
Sets solver type for ordinary differential equations
Available solvers:

Parameters:
solverODE - solver type for ordinary differential equations

getSolverNAE

public int getSolverNAE()
Returns solver type for algebraic equations

Returns:
solver type for algebraic equations

setSolverNAE

public void setSolverNAE(int solverNAE)
Sets solver type for algebraic equations
Available solvers:

Parameters:
solverNAE - solver type for algebraic equations

getSolverDAE

public int getSolverDAE()
Returns solver type for mixed differential-algebraic equations

Returns:
solver type for mixed differential-algebraic equations

setSolverDAE

public void setSolverDAE(int solverDAE)
Sets solver type for mixed differential-algebraic equations
Available solvers:

Parameters:
solverDAE - solver type for mixed differential-algebraic equations

setSimultaneousEventsSelectionMode

public void setSimultaneousEventsSelectionMode(int mode)
Sets the mode of event selection among simultaneous events (if any occur)
The default mode is EVENT_SELECTION_DETERMINISTIC

Parameters:
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

getHeaderText

public final java.lang.String getHeaderText()

getPopUpText

public final java.lang.String getPopUpText()

getState

public 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.

Returns:
the current state of the engine

start

public boolean start(ActiveObject root)
Engine command applicable only in IDLE state (in other states does nothing and returns false). Does the following:
1. Sets up the start time of the model execution
2. Creates whatever is needed in the root object - calls root.create();
3. Starts the model (first events get scheduled) - calls root.start();
4. Puts the engine into the PAUSED state.


step

public boolean step()
Makes at most one discrete step of the model (can be done from the PAUSED state only). Finishes in either FINISHED, ERROR or PAUSED state.
This method should never be called from the model execution thread!

Returns:
false if the engine state does not allow for making a step

run

public boolean run()
Engine command applicable only in PAUSED state (in other states does nothing and returns false). Puts the engine into RUNNING state and then starts the model execution in a separate thread. The execution may discontinue due to the one of the following reasons
- there are no more events to execute (state -> FINISHED)
- stopTime is reached (state -> FINISHED)
- pause() was called (state -> PAUSED)
- root active object has been destroyed (state -> FINISHED)
- exception occured during event execution or active object destruction (state -> ERROR)
This method should never be called from the model execution thread!
Please note that by the time this method finishes, then engine may already be in PAUSED, FINISHED, or ERROR state.

Returns:
false if the engine state does not allow running

runFast

public boolean runFast()
Runs the model in the fastest possible way in the same (calling) thread. The run is done in virtual time mode regardless any settings. The method finishes in one of the following cases:
- illegal engine state when it is called (returns false, in all other cases - returns true)
- there are no more events/equations to execute (state -> FINISHED)
- stopTime is reached (state -> FINISHED)
- pause() was called (state -> PAUSED)
- finish() was called (state -> FINISHED)
- root active object has been destroyed (state -> FINISHED)
- exception occurred during model execution (state -> ERROR)
The model is locked for both write and read during the entire run, so you should not try to display presentation of the active objects, or execute any concurrent actions that may access the model.

Returns:
false if the engine state does not allow running

runFast

public boolean runFast(double pauseTime)
Calls runFast() but pauses the model execution at the specified model time and returns true
If the model finishes (because of stop time or finish() method called) before the pauseTime, the method runs the model until the finish moment only.

Parameters:
pauseTime - the time to pause model execution
Returns:
false if the engine state does not allow running
See Also:
runFast()

pause

public boolean pause()
Engine command applicable only in RUNNING state (in other states does nothing and returns 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: Note that by the time this method finishes, the engine may be in PAUSED, FINISHED, or ERROR state.

Returns:
false if the engine state does not allow pausing

finish

public boolean finish()
Terminates the model after execution of current event. Doesn't destroy the model.
Note that by the time this method finishes, the engine may be in FINISHED or ERROR state.

Engine command applicable only in RUNNING or PAUSED state (in other states does nothing and returns 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:

Returns:
false if the engine state does not allow terminating (engine is neither running nor paused)

stop

public boolean stop()
Stops and destroys the model, see also finish() method, which doesn't destroy the model.

Engine command applicable only in any non-IDLE state (in IDLE state does nothing and returns false). If the state is RUNNING, sets a flag that, when tested by the model execution thread, causes it to terminate. Further behavior depends on context where this method is called:


registerActiveObjectWithEquations

public void registerActiveObjectWithEquations(ActiveObject ao)
Registers given active object with equations in Engine equations solver. Is called from ActiveObject constructor code if the object has equations.

Parameters:
ao - the active object that has equations and registers

unregisterActiveObjectWithEquations

public boolean unregisterActiveObjectWithEquations(ActiveObject ao)
Unregisters the active object from the engine equations solver. Is called from active object onDestroy code if the active object had equations.

Parameters:
ao - the active object that had equations but now unregisters

registerDelay

public void registerDelay(VariableDelay variableDelay)
Registers given delay in Engine equations solver. Is called from ActiveObject constructor code if the object has equations.

Parameters:
variableDelay - delay

unregisterDelay

public void unregisterDelay(VariableDelay variableDelay)
Unregisters the delay from the engine equations solver. Is called from active object onDestroy code if the active object had delay.

Parameters:
variableDelay - delay

submitPredicate

public void submitPredicate(EventOriginator eo)
Registers an EventOriginator instance in 'predicates' array. If the given EventOriginator is already there, does nothing. Has constant complexity.

Parameters:
eo -

unsubmitPredicate

public boolean unsubmitPredicate(EventOriginator eo)
Unregisters given EventOriginator from the list 'predicates'. Is called by active objects on destroy.

Parameters:
eo -
Returns:
true if the 'predicates' contained the specified element

getDefaultRandomGenerator

public java.util.Random getDefaultRandomGenerator()
Returns the currently used default random number generator.

Returns:
the default random number generator.

setDefaultRandomGenerator

public void setDefaultRandomGenerator(java.util.Random r)
Changes the default random number generator.

Parameters:
r - the new random number generator.

saveRootObjectSnapshot

public void saveRootObjectSnapshot(java.lang.String snapshotFileName)
Saves root object and current state of this Engine to a snapshot file with the given name. This method is designed to be used in custom experiments and is available in professional version only.
This method shouldn't be called from the model-execution thread (except calling from custom experiments where the model is executed using runFast() method). Also, this method shouldn't be called when this engine is in RUNNING state.
Note that created snapshot file may only be used in calls to loadRootObjectFromSnapshot methods, i.e. it isn't compatible with any experiments with animation (i.e. not custom)

Parameters:
snapshotFileName - the absolute path to the snapshot file

loadRootObjectFromSnapshot

public 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

Parameters:
snapshotFileName - the absolute path to the snapshot file
See Also:
flushSnapshotCache(), loadRootObjectFromSnapshot(String, boolean)

loadRootObjectFromSnapshot

public 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

Parameters:
snapshotFileName - the absolute path to the snapshot file
cacheSnapshot - if true, snapshot file will be cached for performance speed-up
See Also:
flushSnapshotCache()

flushSnapshotCache

public void flushSnapshotCache()
Clears cache with contents of recently loaded snapshot file
NB: cache is automatically cleared on new snapshot loading

See Also:
loadRootObjectFromSnapshot(String), loadRootObjectFromSnapshot(String, boolean)


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.