When AnyLogic model is run, you can control the model execution using the control panel, displayed in the bottom of AnyLogic model window.
The control panel contains buttons for controlling the execution of the launched model:
Button | Command | Description |
---|---|---|
Run |
[Visible only if the model is not running currently] Runs the model from the current state. The model will be run until you will stop it manually by clicking the Pause or Stop button (or until something in the model will pause or stop its execution). You can either run the model until the specified moment of model time, or for a specified period of model time starting from the current moment. Please see Running the model until a certain date or for a certain time interval for details. |
|
Pause |
[Visible only if the model is running currently] Pauses the running model. You can resume the paused simulation any time. You can pause the model at the specified moment of model time, please see Running the model until a certain date or for a certain time interval for details. |
|
Stop | Terminates the model run. |
Run control becomes disabled when there is no activity in the model. This indicates that your model has finished its work.
You can enable or disable these buttons and check their state (enabled / disabled) from code during the model runtime. The corresponding functions are described in the Control panel section in Accessing the presentation.
You may need to control your model execution programmatically. For example, you may need to pause the model on some event, e.g. on event expiry and resume its execution when some statechart transition will be taken. AnyLogic offers a rich API capable of solving all tasks concerned with controlling the model execution.
The table below lists the related functions of the model engine and analogous functions available at each agent.
To call some engine function, write e.g. getEngine().finish() wherever you need in your model.
Alternatively, you can simply call analogous function finishSimulation() from any agent’s activity.
Engine function | Agent’s function | Short description | Full description |
---|---|---|---|
boolean start() | N/A | Starts the model (if it is idle at the moment) and pauses it. |
Engine command applicable only in IDLE state (in other states does nothing and returns false). Does the following:
|
boolean pause() | boolean pauseSimulation() | Pauses the running model. Puts the engine into PAUSED state and causes the model to terminate after completing the current event execution. |
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 terminate after completing the current event execution. Further behavior depends on context where this function is called:
By the time this function finishes, the engine may be in PAUSED, FINISHED, or ERROR state.
Returns false, if the engine state does not allow pausing.
|
boolean run() | boolean runSimulation() | If the model is paused at the moment, runs the model. Puts the engine into RUNNING state and then starts the model execution. |
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:
This function should never be called from the model execution thread!
Returns false if the engine state does not allow running.
By the time this function finishes, then engine may already be in PAUSED, FINISHED, or ERROR state. |
boolean stop() | boolean stopSimulation() | Terminates the model execution, destroys the model and forgets it. Then puts the engine into IDLE state and returns true. |
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 function is called:
|
boolean finish() | boolean finishSimulation() | Finishes currently running or paused model. Unlike the stop() function, it does not destroy the model, so you can examine and analyze its 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 function is called:
By the time this function finishes, the engine may be in FINISHED, or ERROR state.
Returns false if the engine state does not allow pausing.
|
boolean runFast() | N/A | Runs the model in the fastest possible way. The run is done in virtual time mode regardless any settings. |
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 function finishes in one of the following cases:
Returns false if the engine state does not allow running. |
boolean step() | N/A | Makes at most one discrete step of the model (can be done from the PAUSED state only). |
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 function should never be called from the model execution thread!
Returns false if the engine state does not allow for making a step.
|
Engine.State getState() | N/A | Returns the current state of the engine (IDLE, PAUSED, RUNNING, FINISHED, ERROR, or PLEASE_WAIT). |
Returns the current state of the engine:
|
boolean getRealTimeMode() | N/A | Returns the current model execution mode. | Returns true if the current execution mode is real time, false if virtual time. |
void setRealTimeMode(boolean on) | N/A | Sets the virtual or real time execution mode. |
Sets the virtual or real time execution mode. In virtual time mode the model is executed as fast as possible. In real time mode the engine tries to maintain the given scale between model time and real time. on — true means execution in scale to real time. |
double getRealTimeScale() | N/A | Returns the currently set real time scale of model execution. |
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. |
void setRealTimeScale(double scale) | N/A | Sets the desired real time scale of model execution. |
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. scale — the new real time scale. |
-
How can we improve this article?
-