Package com.anylogic.engine
- Nested Class Summary
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- MODEL_TYPE_UNKNOWN
- MODEL_TYPE_DISCRETE
- MODEL_TYPE_CONTINUOUS
- MODEL_TYPE_HYBRID
- EVENT_SELECTION_LIFO
- EVENT_SELECTION_FIFO
- EVENT_SELECTION_DETERMINISTIC
- EVENT_SELECTION_RANDOM
- IDLE
- PAUSED
- RUNNING
- FINISHED
- ERROR
- PLEASE_WAIT
- SOLVER_ODE_EULER
- SOLVER_ODE_RK4
- SOLVER_NAE_MODIFIED_NEWTON
- SOLVER_NAE_FAST_NEWTON
- SOLVER_NAE_CLASSIC_NEWTON
- SOLVER_DAE_RK45_NEWTON
- SOLVER_DAE_EULER_NEWTON
- Constructor Details
- Method Details
- getRoot
- error
- errorInModel
- error
- errorInModel
- disableWarning
- time
- time
- getTime
- getNextEventTime
- getNextStepTime
- getProgress
- setStartTime
- setStartTime
- getStartTime
- getStartTime
- setStopTime
- setStopTime
- getStopTime
- getStopTime
- date
- getDate
- isCalendarDateUsed
- dateInMillis
- timeToDateInMillis
- getMillisecond
- getSecond
- getMinute
- getHour
- getAmPm
- getHourOfDay
- getDayOfWeek
- getDayOfMonth
- getDayOfYear
- getMonth
- getYear
- dateToTime
- timeToDate
- setStartDate
- getStartDate
- setStopDate
- getStopDate
- setTimeUnit
- getTimeUnit
- getRunCount
- getStep
- getEventCount
- getStartTimeMillis
- getRunTimeMillis
- setVMethods
- getVMethods
- getModelType
- setRealTimeMode
- getRealTimeMode
- setRealTimeScale
- getRealTimeScale
- isRealTimeMaintained
- setExperimentHost
- setPresentation
- getExperimentHost
- getPresentation
- setExperiment
- getExperiment
- getExperimentCustom
- setATOL
- getATOL
- setRTOL
- getRTOL
- setTTOL
- getTTOL
- setHTOL
- getHTOL
- setEventAwareSolver
- isEventAwareSolver
- getSolverODE
- setSolverODE
- getSolverNAE
- setSolverNAE
- getSolverDAE
- setSolverDAE
- setSimultaneousEventsSelectionMode
- getState
- resetBeforeStart
- start
- step
- isDebugging
- run
- runFast
- runFast
- runFastInterruptible
- interruptRunFast
- pause
- finish
- stop
- isTestExperiment
- isStopping
- registerAgentWithEquations
- unregisterAgentWithEquations
- registerDelay
- unregisterDelay
- getDefaultRandomGenerator
- setDefaultRandomGenerator
- saveRootObjectSnapshot
- loadRootObjectFromSnapshot
- loadRootObjectFromSnapshot
- flushSnapshotCache
- getModelDatabase
- getModelProperties
- isPackage3DResourcesLocatedinJar
- java.lang.Object
- com.anylogic.engine.Engine
- All Implemented Interfaces:
Serializable
public final class Engine extends Object implements 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:
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
Agent root = new RootAgent( 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
...
Agent root2 = new RootAgent2( engine, null, null );
...etc.
The engine state PLEASE_WAIT means the engine is executing a non-interruptible
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 agents) concurrently with
runFast().- Author:
- AnyLogic North America, LLC https://anylogic.com
- See Also:
- Serialized Form
Modifier and Type | Class | Description |
---|---|---|
static enum | Engine.EventSelectionMode |
Simultaneous event selection mode constants
|
static enum | Engine.ModelType |
The type of the model, returned by Engine.
|
static enum | Engine.SolverDAEType |
The solver type for mixed differential-algebraic equations
|
static enum | Engine.SolverNAEType |
The solver type for algebraic equations
|
static enum | Engine.SolverODEType |
The solver type for ordinary differential equations
|
static enum | Engine.State |
The state of the Engine
|
Constructor | Description |
---|---|
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 |
Modifier and Type | Method | Description |
---|---|---|
Date | date() |
Returns the current model date with respect to the start time/date and the
model time unit.
|
long | dateInMillis() |
Returns the current model date milliseconds with respect to the start
time/date and the model time unit.
|
double | dateToTime |
Converts the given date to model time with respect to the start date,
start time and model time unit settings
|
void | disableWarning |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
RuntimeException | error |
Signals an error during the model run by throwing a RuntineException
with the given text.
|
RuntimeException | error |
Signals an error during the model run by throwing a RuntineException
with the given text.
|
RuntimeException | errorInModel |
Signals an model logic error during the model run by throwing a
ModelException
with the given text.This method differs from error() in the way of displaying error message:
model logic errors are 'softer' than other errors, they use to happen in the models
and signal the modeler that model might need some parameters adjustments. |
RuntimeException | errorInModel |
Signals an model logic error during the model run by throwing a
ModelException
with the given text.This method differs from error() in the way of displaying error message:
model logic errors are 'softer' than other errors, they use to happen in the models
and signal the modeler that model might need some parameters adjustments. |
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.This method is used for the 12-hour clock. E.g., at 10:04:15.250 PM the result is . |
double | getATOL() |
Returns absolute tolerance of the numeric engine.
|
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.
The first day of the month has value 1. |
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:
|
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. |
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.
This method isn't designed for AnyLogic Cloud, also returns null for custom experiments |
ExperimentCustom | getExperimentCustom() |
Returns the custom experiment controlling the model execution.
Returns null for other types of experiments |
IExperimentHost | getExperimentHost() |
Returns the experiment host object associated with this engine, or some dummy object
with no functionality if there is none.
|
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. |
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. |
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.
E.g., at 10:04:15.250 PM the result is 250. |
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. |
ModelDatabase | getModelDatabase() |
Returns the the database of this model
|
ModelProperties | getModelProperties() |
Returns the model properties of this model
|
Engine.ModelType | 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.
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:
(indicates the
thirteenth month of the year. |
double | getNextEventTime() |
Returns the time of the earliest event scheduled so far.
|
double | getNextStepTime() |
Returns the time which will be after the next
step() execution
If the model is about to finish, returns -infinity .Special cases: in system-dynamics models the result may depend on the selected accuracy in system-dynamics models some conditional events may occur based on the value obtained from numerical solver within the step. |
IExperimentHost | getPresentation() |
Deprecated.
this method will be removed in the next releases.
|
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 real time scale of model execution, i.e.
|
Agent | getRoot() |
Returns the top-level agent setup for the engine (the topmost level
agent 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.
E.g., at 10:04:15.250 PM the result is 15. |
Engine.SolverDAEType | getSolverDAE() |
Returns solver type for mixed differential-algebraic equations
|
Engine.SolverNAEType | getSolverNAE() |
Returns solver type for algebraic equations
|
Engine.SolverODEType | getSolverODE() |
Returns solver type for ordinary differential equations
|
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.
|
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.
|
Engine.State | 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-interruptible 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.
|
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
+infinity if stop time is not set. |
double | getStopTime |
Returns the currently set stop time - the model time at which the simulation
should stop, or
+infinity if stop time is not set. |
double | getTime() |
Deprecated.
Use
time() instead. |
TimeUnits | getTimeUnit() |
Returns the real time units currently set as the model time units.
|
double | getTTOL() |
Returns time tolerance of the numeric engine.
|
final Number | getVMethods() | |
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 |
void | interruptRunFast |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
boolean | isCalendarDateUsed() |
Returns
true if calendar dates (e.g. |
static boolean | isDebugging() |
Returns
true if the model is started in the debug mode from AnyLogic |
boolean | isEventAwareSolver() |
Returns the current setting used by System Dynamics solver in the models
having both System Dynamics equations and Discrete Event parts.
|
boolean | isPackage3DResourcesLocatedinJar |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
boolean | isRealTimeMaintained() |
This method is not designed to be called by user
is public due to technical reasons |
boolean | isStopping() |
Deprecated.
|
boolean | isTestExperiment() |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
Agent | loadRootObjectFromSnapshot |
Loads and sets top-level agent 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. |
Agent | loadRootObjectFromSnapshot |
Loads and sets top-level agent 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. |
boolean | pause() |
Engine command applicable only in RUNNING state (in other states does nothing
and returns
false ). |
void | registerAgentWithEquations |
Registers given agent with equations in Engine
equations solver.
|
void | registerDelay |
Registers given delay in Engine equations solver.
|
void | resetBeforeStart() |
This method should be called from custom experiments which use logging to database.
Resets state variables which may be accessed by root parameters setup before start(Agent) is called.This method does nothing if state isn't IDLE |
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 |
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 | runFastInterruptible |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
void | saveRootObjectSnapshot |
Saves top-level agent and current state of this Engine to a
snapshot file with the given name.
|
void | setATOL |
Sets the absolute tolerance of the numeric engine.
|
void | setDefaultRandomGenerator |
Changes the default random number generator.
|
void | setEventAwareSolver |
This setting is actual for models having both System Dynamics equations and Discrete Event parts.
|
void | setExperiment |
Sets the experiment that will be controlling the model execution.
|
void | setExperimentHost |
Sets the object that will be host the model execution (animation and controls).
|
void | setHTOL |
Sets the fixed step of the numeric engine.
|
void | setPresentation |
Deprecated.
this method will be removed in the next releases.
|
void | setRealTimeMode |
Sets the virtual or real time execution mode.
|
void | setRealTimeScale |
Sets the desired real time scale of model execution, i.e.
|
void | setRTOL |
Sets the relative tolerance of the numeric engine.
|
void | setSimultaneousEventsSelectionMode |
Sets the mode of event selection among simultaneous events (if any occur).
|
void | setSolverDAE |
Sets solver type for mixed differential-algebraic equations
Available solvers: SOLVER_DAE_RK45_NEWTON (default)
SOLVER_DAE_EULER_NEWTON
|
void | setSolverNAE |
Sets solver type for algebraic equations
Available solvers: SOLVER_NAE_MODIFIED_NEWTON (default)
SOLVER_NAE_FAST_NEWTON
SOLVER_NAE_CLASSIC_NEWTON
|
void | setSolverODE |
Sets solver type for ordinary differential equations
Available solvers: SOLVER_ODE_EULER (default)
SOLVER_ODE_RK4
|
void | setStartDate |
Sets the date corresponding to the start time of the simulation.
|
void | setStartTime |
Sets the start time for the simulation - the initial value of the model clock.
|
void | setStartTime |
Sets the start time for the simulation - the initial value of the model clock.
|
void | setStopDate |
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 |
Sets the stop time for the simulation.
|
void | setStopTime |
Sets the stop time for the simulation.
|
void | setTimeUnit |
Sets the correspondence between the model time unit and a real time unit.
|
void | setTTOL |
Sets the time tolerance of the numeric engine.
|
final void | setVMethods | |
boolean | start |
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.Engine command applicable only in any non-IDLE state (in IDLE state does nothing and returns false ). |
double | time() |
Returns the current model (logical) time.
|
double | time |
Returns the current model (logical) time.
|
Date | timeToDate |
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.
|
long | timeToDateInMillis |
Returns the model date milliseconds with respect to the start
time/date and the model time unit for the given model time
|
boolean | unregisterAgentWithEquations |
Unregisters the agent from the engine equations solver.
|
void | unregisterDelay |
Unregisters the delay from the engine equations solver.
|
public static final Engine.ModelType MODEL_TYPE_UNKNOWN
public static final Engine.ModelType MODEL_TYPE_DISCRETE
public static final Engine.ModelType MODEL_TYPE_CONTINUOUS
public static final Engine.ModelType MODEL_TYPE_HYBRID
public static final Engine.EventSelectionMode EVENT_SELECTION_LIFO
Deterministic selection mode (last in - first out) constant for
Offers good performance, simultaneous events are executed in the reverse to the order they were scheduled
setSimultaneousEventsSelectionMode(EventSelectionMode)
Offers good performance, simultaneous events are executed in the reverse to the order they were scheduled
public static final Engine.EventSelectionMode EVENT_SELECTION_FIFO
Deterministic selection mode (first in - first out) constant for
Offers good performance, simultaneous events are executed in the same order they were scheduled.
This is the default mode used by engine
setSimultaneousEventsSelectionMode(EventSelectionMode)
Offers good performance, simultaneous events are executed in the same order they were scheduled.
This is the default mode used by engine
@Deprecated public static final Engine.EventSelectionMode EVENT_SELECTION_DETERMINISTIC
Deprecated.
Use
EVENT_SELECTION_LIFO
or EVENT_SELECTION_FIFO
insteadDeterministic selection mode constant for
Offers good performance
setSimultaneousEventsSelectionMode(EventSelectionMode)
Offers good performance
public static final Engine.EventSelectionMode EVENT_SELECTION_RANDOM
Random selection mode constant for
This mode is slower than
This mode utilises the default random number generator of the Engine.
setSimultaneousEventsSelectionMode(EventSelectionMode)
This mode is slower than
EVENT_SELECTION_FIFO
or EVENT_SELECTION_LIFO
This mode utilises the default random number generator of the Engine.
public static final Engine.State IDLE
public static final Engine.State PAUSED
public static final Engine.State RUNNING
public static final Engine.State FINISHED
public static final Engine.State ERROR
public static final Engine.State PLEASE_WAIT
public static final Engine.SolverODEType SOLVER_ODE_EULER
public static final Engine.SolverODEType SOLVER_ODE_RK4
public static final Engine.SolverNAEType SOLVER_NAE_MODIFIED_NEWTON
public static final Engine.SolverNAEType SOLVER_NAE_FAST_NEWTON
public static final Engine.SolverNAEType SOLVER_NAE_CLASSIC_NEWTON
public static final Engine.SolverDAEType SOLVER_DAE_RK45_NEWTON
public static final Engine.SolverDAEType SOLVER_DAE_EULER_NEWTON
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
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 enginepublic Agent getRoot()
Returns the top-level agent setup for the engine (the topmost level
agent from which the model creation and execution starts).
Usually (and by default) it is an instance of
Agent
class Main.- Returns:
- the top-level agent
public RuntimeException error(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");
public RuntimeException errorInModel(String errorText)
Signals an model logic error during the model run by throwing a
This method differs from
ModelException
with the given text.This method differs from
error()
in the way of displaying error message:
model logic errors are 'softer' than other errors, they use to happen in the models
and signal the modeler that model might need some parameters adjustments. Examples
are 'entity was unable to leave flowchart block because subsequent block was busy',
'insufficient capacity of pallet rack' etc.- 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");
public RuntimeException error(Throwable cause, String errorText)
Signals an error during the model run by throwing a RuntineException
with the given text.
- Parameters:
cause
- the cause (which will be saved for more detailed message), may benull
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");
public RuntimeException errorInModel(Throwable cause, String errorText)
Signals an model logic error during the model run by throwing a
This method differs from
ModelException
with the given text.This method differs from
error()
in the way of displaying error message:
model logic errors are 'softer' than other errors, they use to happen in the models
and signal the modeler that model might need some parameters adjustments. Examples
are 'entity was unable to leave flowchart block because subsequent block was busy',
'insufficient capacity of pallet rack' etc.- Parameters:
cause
- the cause (which will be saved for more detailed message), may benull
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");
@AnyLogicInternalAPI public void disableWarning(String warningType)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
public double time()
Returns the current model (logical) time. Time stays constant during an event
execution and is only advanced between events.
- Returns:
- current model time in model time units
- See Also:
-
getTimeUnit()
public double time(TimeUnits units)
Returns the current model (logical) time. Time stays constant during an event
execution and is only advanced between events.
- Parameters:
units
- the time units- Returns:
- current model time in the given units
- Since:
- 8.0
@Deprecated public double getTime()
Deprecated.
Use
time()
instead.Returns the current model (logical) time.
- Returns:
- the current model (logical) time
public double getNextEventTime()
Returns the time of the earliest event scheduled so far.
If there is no events, returns
This method should be generally used in the model internal logic because the "next event" may be the utility one which e.g. updates some plot/chart/...
This method is designed for some external time management applications, e.g. for HLA (High-level architecture) implementations.
-infinity
.This method should be generally used in the model internal logic because the "next event" may be the utility one which e.g. updates some plot/chart/...
This method is designed for some external time management applications, e.g. for HLA (High-level architecture) implementations.
- Returns:
- the time of the earliest event or
-infinity
- Since:
- 7.0
public double getNextStepTime()
Returns the time which will be after the next
Special cases:
step()
execution
If the model is about to finish, returns -infinity
.Special cases:
- in system-dynamics models the result may depend on the selected accuracy
- in system-dynamics models some conditional events may occur based
on the value obtained from numerical solver within the step. This
case can't be predicted and in such situations the actual
step()
will have the time "before" the value returned by this function - for the models without any activity, this method depends on the
setRealTimeMode(boolean)
andsetRealTimeScale(double)
settings: it either simply increments the time with some amount - like thestep()
function does or returns-infinity
- Returns:
- the time of the next step or
-infinity
- Since:
- 7.1
- See Also:
-
getNextEventTime()
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
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, in model time units- See Also:
-
getTimeUnit()
public void setStartTime(double tstart, TimeUnits units)
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:
units
- the time unitststart
- the simulation start time, in the given time units- Since:
- 8.0
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, in model time units
- See Also:
-
getTimeUnit()
public double getStartTime(TimeUnits units)
Returns the currently set start time - the model time at which the simulation
starts, by default it is 0.
- Parameters:
units
- the time units- Returns:
- the simulation start time, in the given time units
- Since:
- 8.0
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
+infinity
. If any event(s) are scheduled exactly at stop time,
they will be executed. By default the stop time is +infinity
,
so the simulation may run infinitely.- Parameters:
tstop
- the (model) time to stop the simulation, in model time units- See Also:
-
getTimeUnit()
public void setStopTime(double tstop, TimeUnits units)
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
+infinity
. If any event(s) are scheduled exactly at stop time,
they will be executed. By default the stop time is +infinity
,
so the simulation may run infinitely.- Parameters:
tstop
- the (model) time to stop the simulation, in the given time unitsunits
- the time units- Since:
- 8.0
public double getStopTime()
Returns the currently set stop time - the model time at which the simulation
should stop, or
+infinity
if stop time is not set.- Returns:
- the simulation stop time, in model time units or
+infinity
- See Also:
-
getTimeUnit()
public double getStopTime(TimeUnits units)
Returns the currently set stop time - the model time at which the simulation
should stop, or
+infinity
if stop time is not set.- Parameters:
units
- the time units- Returns:
- the simulation stop time, in the given time units or
+infinity
- Since:
- 8.0
public Date date()
Returns the current model date with respect to the start time/date and the
model time unit.
- Returns:
- the current model date
@Deprecated public Date getDate()
Deprecated.
Use
date()
insteadReturns the current model date.
- Returns:
- the current model date
public boolean isCalendarDateUsed()
Returns
true
if calendar dates (e.g. date()
method) are meaningful.- Returns:
true
if calendar dates are meaningful
@AnyLogicInternalAPI public long dateInMillis()
Returns the current model date milliseconds with respect to the start
time/date and the model time unit.
- Returns:
- the current model date milliseconds
@AnyLogicInternalAPI public long timeToDateInMillis(double time)
Returns the model date milliseconds with respect to the start
time/date and the model time unit for the given model time
- Returns:
- the model date milliseconds for the given model time
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.
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
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.
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
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.
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
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.
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()
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 (
This method is used for the 12-hour clock.
E.g., at 10:04:15.250 PM the result is
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:
orUtilities.AM
depending on the hour of the current model date with respect to the start time/date and the model time unitUtilities.PM
- See Also:
-
getHour()
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.
This method is used for the 24-hour clock.
E.g., at 10:04:15.250 PM the result is 22.
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:
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
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.
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
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.
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
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
Possible values:
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:
Utilities.JANUARY
Utilities.FEBRUARY
Utilities.MARCH
Utilities.APRIL
Utilities.MAY
Utilities.JUNE
Utilities.JULY
Utilities.AUGUST
Utilities.SEPTEMBER
Utilities.OCTOBER
Utilities.NOVEMBER
Utilities.DECEMBER
(indicates the thirteenth month of the year. AlthoughUtilities.UNDECIMBER
GregorianCalendar
does not use this value, lunar calendars do)
- Returns:
- the month of the current model date with respect to the start time/date and the model time unit
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
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
public double dateToTime(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
public 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
public void setStartDate(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)
public 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)
public void setStopDate(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)
public 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
@AnyLogicInternalCodegenAPI public void setTimeUnit(TimeUnits tu)
Sets the correspondence between the model time unit and a real time unit.
You may use constants SECOND,
MINUTE, etc.
The default value is SECOND. This has nothing to do with the
simulation real time mode but affects the conversion between the model time
and date.
This method is internal and generally shouldn't be called by user, because 'time units' is the property of the whole model and shouldn't be changed.
This method is internal and generally shouldn't be called by user, because 'time units' is the property of the whole model and shouldn't be changed.
- Parameters:
tu
- the real time unit corresponding to the model time unit
public TimeUnits getTimeUnit()
Returns the real time units currently set as the model time units.
- Returns:
- the units used as model time units
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.
public long getStep()
Returns the number of events executed by the engine.
- Returns:
- the number of events executed
public long getEventCount()
Returns the number of currently scheduled events.
- Returns:
- the number of currently scheduled events
@AnyLogicInternalAPI public long getStartTimeMillis()
Returns the result of a call to System.currentTimeMillis() at the simulation
start.
- Returns:
- the system time at the simulation start
@AnyLogicInternalAPI public long getRunTimeMillis()
Returns the real duration of the simulation run in milliseconds, excluding
pause times.
- Returns:
- the real duration of the simulation run
@AnyLogicInternalCodegenAPI public final void setVMethods(Number n)
@AnyLogicInternalCodegenAPI public final Number getVMethods()
public Engine.ModelType 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
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
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
public boolean getRealTimeMode()
Returns
true
if the current execution mode is real time, false
if
virtual time.- Returns:
- the current model execution mode
public void setRealTimeScale(double scale)
Sets the desired real time scale of model execution, i.e. the number of
model time units to be simulated per real second. The actual scale will depend on
factors such as simulation performance, applications running in parallel, etc.
This scale only has effect in real time execution mode.
- Parameters:
scale
- then new real time scale
public double getRealTimeScale()
Returns the currently set real time scale of model execution, i.e. the number of
model time units to be simulated per real second. The actual scale will depend on
factors such as simulation performance, applications running in parallel, etc.
This scale only has effect in real time execution mode.
- Returns:
- the current real time scale
@AnyLogicInternalAPI public boolean isRealTimeMaintained() throws Exception
This method is not designed to be called by user
is public due to technical reasons
is public due to technical reasons
- Throws:
Exception
public void setExperimentHost(IExperimentHost h)
Sets the object that will be host the model execution (animation and controls).
Engine needs to know the experiment host to be able to notify it about
destruction of agents (they can be displayed), also the user can
retrieve and access the experiment host via engine.
- Parameters:
h
- the experiment host object displaying the model
@Deprecated public void setPresentation(IExperimentHost p)
Deprecated.
this method will be removed in the next releases. Please use
getExperimentHost()
instead.public IExperimentHost getExperimentHost()
Returns the experiment host object associated with this engine, or some dummy object
with no functionality if there is none.
- Returns:
- the experiment host object of the model
@Deprecated public IExperimentHost getPresentation()
Deprecated.
this method will be removed in the next releases. Please use
getExperimentHost()
instead.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
public Experiment<?> getExperiment()
Returns the experiment controlling the model execution.
This method isn't designed for AnyLogic Cloud, also returns
This method isn't designed for AnyLogic Cloud, also returns
null
for custom experiments- Returns:
- the experiment controlling the model execution
public ExperimentCustom getExperimentCustom()
Returns the custom experiment controlling the model execution.
Returns
Returns
null
for other types of experiments- Returns:
- the custom experiment controlling the model execution
- Since:
- 8.5.0
public void setATOL(double atol)
Sets the absolute tolerance of the numeric engine.
- Parameters:
atol
- the absolute tolerance to set
public double getATOL()
Returns absolute tolerance of the numeric engine.
- Returns:
- absolute tolerance of the numeric engine
public void setRTOL(double rtol)
Sets the relative tolerance of the numeric engine.
- Parameters:
rtol
- the relative tolerance to set
public double getRTOL()
Returns relative tolerance of the numeric engine.
- Returns:
- relative tolerance of the numeric engine
public void setTTOL(double ttol)
Sets the time tolerance of the numeric engine.
- Parameters:
ttol
- the time tolerance to set
public double getTTOL()
Returns time tolerance of the numeric engine.
- Returns:
- time tolerance of the numeric engine
public void setHTOL(double htol)
Sets the fixed step of the numeric engine.
- Parameters:
htol
- the fixed step to set
public double getHTOL()
Returns fixed step of the numeric engine.
- Returns:
- fixed step of the numeric engine
public void setEventAwareSolver(boolean eventAwareSolver)
This setting is actual for models having both System Dynamics equations and Discrete Event parts.
- If
true
, SD equations will be solved with respect to each event occurrence time. This is the most precise technique, but in some cases it may significantly slow down the model, e.g. when many asynchronous agents generate dense events on the timeline. - If
false
, SD equations will be solved with fixed steps regardless events' occurrences. As a result, an event will operate with some recent (not quite actual) values of continuous variables, namely, corresponding to the last result of numeric integration step. In the worst case, the values will beHTOL
time units late. And similarly, in this mode SD formulas aren't evaluated after each event execution, this is done only on fixed steps of the solver.
true
by defaultpublic boolean isEventAwareSolver()
Returns the current setting used by System Dynamics solver in the models
having both System Dynamics equations and Discrete Event parts.
- See Also:
-
more information...
public Engine.SolverODEType getSolverODE()
Returns solver type for ordinary differential equations
- Returns:
- solver type for ordinary differential equations
public void setSolverODE(Engine.SolverODEType solverODE)
Sets solver type for ordinary differential equations
Available solvers:
Available solvers:
SOLVER_ODE_EULER
(default)SOLVER_ODE_RK4
- Parameters:
solverODE
- solver type for ordinary differential equations
public Engine.SolverNAEType getSolverNAE()
Returns solver type for algebraic equations
- Returns:
- solver type for algebraic equations
public void setSolverNAE(Engine.SolverNAEType solverNAE)
Sets solver type for algebraic equations
Available solvers:
Available solvers:
- Parameters:
solverNAE
- solver type for algebraic equations
public Engine.SolverDAEType getSolverDAE()
Returns solver type for mixed differential-algebraic equations
- Returns:
- solver type for mixed differential-algebraic equations
public void setSolverDAE(Engine.SolverDAEType solverDAE)
Sets solver type for mixed differential-algebraic equations
Available solvers:
Available solvers:
- Parameters:
solverDAE
- solver type for mixed differential-algebraic equations
public void setSimultaneousEventsSelectionMode(Engine.EventSelectionMode mode)
Sets the mode of event selection among simultaneous events (if any occur). The default choice is LIFO.
This feature is experimental and not recommended in general cases.
This feature is experimental and not recommended in general cases.
- Parameters:
mode
- one of the following values:EVENT_SELECTION_LIFO
(selected by default since AnyLogic 8.6) - fast deterministic selection mode, simultaneous events are executed in the reverse to the order they were scheduledEVENT_SELECTION_FIFO
- fast deterministic selection mode, simultaneous events are executed in the same order they were scheduledEVENT_SELECTION_RANDOM
- random (but slow) selection mode
public Engine.State 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-interruptible command like pause(), step() or stop()
The state is however not guaranteed as may be modified concurrently.
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-interruptible command like pause(), step() or stop()
The state is however not guaranteed as may be modified concurrently.
- Returns:
- the current state of the engine
public void resetBeforeStart()
This method should be called from custom experiments which use logging to database.
Resets state variables which may be accessed by root parameters setup before
This method does nothing if state isn't
Resets state variables which may be accessed by root parameters setup before
start(Agent)
is called.This method does nothing if state isn't
IDLE
- Since:
- 7.2
public boolean start(Agent root)
Engine command applicable only in IDLE state (in other states does nothing
and returns
1. Sets up the start time of the model execution
2. Creates whatever is needed in the top-level agent - calls root.create();
3. Starts the model (first events get scheduled) - calls root.start();
4. Puts the engine into the PAUSED state.
false
). Does the following:1. Sets up the start time of the model execution
2. Creates whatever is needed in the top-level agent - calls root.create();
3. Starts the model (first events get scheduled) - calls root.start();
4. Puts the engine into the PAUSED state.
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!
This method should never be called from the model execution thread!
- Returns:
false
if the engine state does not allow for making a step
public static boolean isDebugging()
Returns
true
if the model is started in the debug mode from AnyLogic- Returns:
true
if the model is started in the debug mode from AnyLogic,false
if this is an ordinary run- Since:
- 7.1
public boolean run()
Engine command applicable only in PAUSED state (in other states does nothing
and returns
- there are no more events to execute (state -> FINISHED)
- stopTime is reached (state -> FINISHED)
- pause() was called (state -> PAUSED)
- top-level agent has been destroyed (state -> FINISHED)
- exception occurred during event execution or agent 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.
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)
- top-level agent has been destroyed (state -> FINISHED)
- exception occurred during event execution or agent 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
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
- 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)
- top-level agent 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 agents, or execute any concurrent actions that may access the model.
- 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)
- top-level agent 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 agents, or execute any concurrent actions that may access the model.
- Returns:
false
if the engine state does not allow running
public boolean runFast(double pauseTime)
Calls
If the model finishes (because of stop time or finish() method called) before the
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()
@AnyLogicInternalAPI public void runFastInterruptible(double pauseTime)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
- Since:
- 8.0
@AnyLogicInternalAPI public void interruptRunFast(Runnable callback)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
- Since:
- 8.0
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:
- When this method is called from the model execution thread, from control
action code, or from on-click code of a shape,
it returns
true
immediately. Model is paused just after current event execution - When this method is called from other locations (e.g. user-defined concurrent thread),
it waits for the model execution thread to terminate and returns
true
.
- Returns:
false
if the engine state does not allow pausing
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
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:
- When this method is called from the model execution thread, control action code,
or from on-click code of a shape, it returns
true
immediately. Model is finished just after current event execution (After Simulation Run code of an experiment may be used to handle this moment)
- When this method is called from other locations (e.g. user-defined concurrent thread),
it waits for the model execution thread to terminate and returns
true
.
- Returns:
false
if the engine state does not allow terminating (engine is neither running nor paused)
public boolean stop()
Stops and destroys the model, see also
Engine command applicable only in any non-IDLE state (in IDLE state does nothing and returns
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:
- When this method is called from the model execution thread, or from control
action code, or from on-click code of a shape, it returns
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 top-level agent may be used to handle this moment)
It is more recommended to usefinish()
method in such situations - When this method is called from other locations (e.g. user-defined concurrent thread),
it waits for the model execution thread to terminate and then destroys the model
(calls root.onDestroy()) and forgets it. Then puts the engine into IDLE state
and returns
true
. - If this method is called during "run fast" execution, then it simply finishes the model - you should manually take care of stopping the engine after you collect all needed data from finished model.
@AnyLogicInternalAPI public boolean isTestExperiment()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI @Deprecated public boolean isStopping()
Deprecated.
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalCodegenAPI public void registerAgentWithEquations(Agent ao)
Registers given agent with equations in Engine
equations solver. Is called from
Agent
constructor code
if the object has equations.- Parameters:
ao
- the agent that has equations and registers
@AnyLogicInternalCodegenAPI public boolean unregisterAgentWithEquations(Agent ao)
Unregisters the agent from the engine equations solver.
Is called from agent onDestroy code if the agent had
equations.
- Parameters:
ao
- the agent that had equations but now unregisters
@AnyLogicInternalCodegenAPI public void registerDelay(VariableDelay variableDelay)
Registers given delay in Engine equations solver. Is called
from
Agent
constructor code
if the object has equations.- Parameters:
variableDelay
- delay
@AnyLogicInternalCodegenAPI public void unregisterDelay(VariableDelay variableDelay)
Unregisters the delay from the engine equations solver.
Is called from agent onDestroy code if the agent had
delay.
- Parameters:
variableDelay
- delay
public Random getDefaultRandomGenerator()
Returns the currently used default random number generator.
- Returns:
- the default random number generator.
public void setDefaultRandomGenerator(Random r)
Changes the default random number generator.
- Parameters:
r
- the new random number generator.
public void saveRootObjectSnapshot(String snapshotFileName)
Saves top-level agent 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
Note that created snapshot file may only be used in calls to
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
public Agent loadRootObjectFromSnapshot(String snapshotFileName)
Loads and sets top-level agent 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
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:
public Agent loadRootObjectFromSnapshot(String snapshotFileName, boolean cacheSnapshot)
Loads and sets top-level agent 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
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 filecacheSnapshot
- iftrue
, snapshot file will be cached for performance speed-up- See Also:
-
flushSnapshotCache()
public void flushSnapshotCache()
Clears cache with contents of recently loaded snapshot file
NB: cache is automatically cleared on new snapshot loading
NB: cache is automatically cleared on new snapshot loading
public ModelDatabase getModelDatabase()
Returns the the database of this model
- Returns:
- the database of this model
- Since:
- 7.2
@AnyLogicInternalAPI public ModelProperties getModelProperties()
Returns the model properties of this model
- Since:
- 7.2
@AnyLogicInternalAPI public boolean isPackage3DResourcesLocatedinJar(String packagePrefix)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
EVENT_SELECTION_LIFO
orEVENT_SELECTION_FIFO
instead