AnyLogic
Expand
Font size
All Known Implementing Classes:
ExperimentHost

public interface IExperimentHost
Object of this interface is responsible for various actions regarding AnyLogic Model animation and graphical user interface.
Author:
AnyLogic North America, LLC https://anylogic.com

Nested Class Summary

Nested Classes 
static interface  IExperimentHost.IValue
Used for converting String/JSON input data to arbitrary java classes requested by Engine.
Modifier and Type Interface Description

Method Summary

All Methods Instance Methods Abstract Methods Default Methods 
void addInspect​(double x, double y, Presentable p, java.lang.String name)
Creates an inspect window at a particular location for an element of a Presentable object.
java.lang.Object callFunction​(java.lang.String pathtofunction, IExperimentHost.IValue... args)  
void close()
This method returns immediately and performs the following actions in a separate thread: stops experiment if it is not stopped, destroys the model and closes experiment window (only if model is started in the application mode)
void copyToClipboard​(java.lang.String text)
Copies the given text to the system clipboard
Due to the security policy of the browser, the actual copying may be preceded by a prompt.
void executeCommand​(java.lang.String cmd, java.lang.String parameters)  
void executeUserAction​(long id, java.lang.String value)  
LaunchConfiguration getConfiguration()  
Experiment<?> getExperiment()
Returns the experiment associated with this host.
Experiment.State getExperimentState()  
long getNextFrameNumber()  
Presentable getPresentable()
Returns the current top-level object (Agent or Experiment), whose presentation is displayed.
double getProgress()  
AnimationPacket getUpdate​(boolean fullFrame)  
java.lang.Object getValue​(java.lang.String pathtofield)  
boolean isRunControlEnabled()
Tests if Run, Pause, and Stop buttons on the model toolbar are enabled.
boolean isSpeedControlEnabled()
Tests if the model execution speed control buttons on the model toolbar are enabled.
boolean isZoomAndPanningEnabled()
Tests if zoom & panning from the GUI is enabled.
default void launch()  
void launch​(boolean startServer, boolean startExperiment)
Creates and optionally runs experiment, starts frame collection
default void loadSnapshot​(java.lang.String fileName)
Stops experiment and loads snapshot (in its 'not running' state), doesn't resume simulation of loaded snapshot.
On any error throws nothing, silently rollbacks to the current experiment and resumes it if it was running.
void loadSnapshot​(java.lang.String fileName, java.lang.Runnable successfulCallback, java.util.function.Consumer<java.lang.Throwable> errorCallback)
Stops experiment and loads snapshot (in its 'not running' state), doesn't resume simulation of loaded snapshot.
On any error throws nothing, silently rollbacks to the current experiment and resumes it if it was running.

When snapshot is loaded, presentation forgets everything about the model which was running before (including the engine, experiment and agents), therefore, it is recommended not to keep references to model objects after this method call
Usage example:
void navigateHome()
Navigates presentation home, i.e.
void navigateTo​(ViewArea viewArea)
Shows the given view area in the model animation panel
void onAgentDestroyed_xjal​(Agent ao)
A callback called by the engine when an agent is being destroyed.
void openWebSite​(java.lang.String url)
Opens web page with the given URL in the browser
void postExperimentSettings()  
void removeInspect​(Presentable p, java.lang.String name)
Removes the inspect window for the given element
default void saveSnapshot​(java.lang.String fileName)
Pauses experiment if it is currently running, saves snapshot and then resumes experiment if it was running
On any error throws nothing.
void saveSnapshot​(java.lang.String fileName, java.lang.Runnable successfulCallback, java.util.function.Consumer<java.lang.Throwable> errorCallback)
Pauses experiment if it is currently running, saves snapshot and then resumes experiment if it was running
On any error throws nothing.
Usage example:
void setCenter​(double x, double y)
Centers the animation view to the given x and y (in the model coordinates)
void setDeveloperPanelEnabled​(boolean developerPanelEnabled)
Enables or disables the developer panel.
void setDeveloperPanelVisibleOnStart​(boolean developerPanelVisibleOnStart)
Shows (if enabled) the developer panel when the model window is shown.
void setMaxFPS​(double maxFPS)  
void setPresentable​(Presentable presentable)
Sets a new top-level object (Agent or Experiment) to be displayed and navigates to its home point.
void setRunControlEnabled​(boolean runControlEnabled)
Enables or disables Run, Pause, and Stop buttons on the model toolbar (but not in the developer panel), and sets the corresponding tooltips.
void setSendConsoleItems​(boolean yes)  
void setSpeed​(double speed)  
void setSpeedControlEnabled​(boolean speedControlEnabled)
Enables or disables the model execution speed control buttons on the model toolbar (but not in the developer panel), and sets the corresponding tooltips.
void setValue​(java.lang.String pathtofield, IExperimentHost.IValue value)  
void setZoomAndPanningEnabled​(boolean zoomAndPanningEnabled)
Enables or disables zoom & panning initiated from the GUI (button.
void showErrorDialog​(java.lang.String text, java.lang.String title)
Shows a standard error dialog box with the given text.
void showErrorInModelDialog​(java.lang.String text, java.lang.String title)
Shows a standard 'error in model logic' dialog box with the given text.
void showMessageDialog​(java.lang.String text)
Shows a standard message dialog box with the given text.
void zoomIn​(double coefficient)
Zooms in the animation view by the given amount
void zoomOut​(double coefficient)
Zooms out the animation view by the given amount
Modifier and Type Method Description

Method Detail

setPresentable

void setPresentable​(Presentable presentable)
Sets a new top-level object (Agent or Experiment) to be displayed and navigates to its home point.
Parameters:
presentable - the new top-level object to be displayed

getPresentable

Presentable getPresentable()
Returns the current top-level object (Agent or Experiment), whose presentation is displayed.
Returns:
the current top-level object being displayed, or null

getExperiment

Experiment<?> getExperiment()
Returns the experiment associated with this host.
Returns:
the experiment associated with this host
void navigateHome()
Navigates presentation home, i.e. moves the presentation coordinate origin (0,0) to the top left corner of the window, and sets zoom to match the initial frame.
void navigateTo​(ViewArea viewArea)
Shows the given view area in the model animation panel
Parameters:
viewArea - the view area to show

zoomIn

void zoomIn​(double coefficient)
Zooms in the animation view by the given amount
Parameters:
coefficient - how much to zoom in, positive number. E.g. 2.0 will result in 2x scaling compared to the current view

zoomOut

void zoomOut​(double coefficient)
Zooms out the animation view by the given amount
Parameters:
coefficient - how much to zoom out, positive number. E.g. 2.0 will result in 0.5x scaling compared to the current view

setCenter

void setCenter​(double x,
               double y)
Centers the animation view to the given x and y (in the model coordinates)
Parameters:
x - the x to be centered
y - the y to be centered

setZoomAndPanningEnabled

void setZoomAndPanningEnabled​(boolean zoomAndPanningEnabled)
Enables or disables zoom & panning initiated from the GUI (button. mouse, or keyboard).
Parameters:
zoomAndPanningEnabled - if true, zoom & panning should be enabled, if false - disabled

isZoomAndPanningEnabled

boolean isZoomAndPanningEnabled()
Tests if zoom & panning from the GUI is enabled.
Returns:
true if zoom & panning are enabled, false if not.

setDeveloperPanelEnabled

void setDeveloperPanelEnabled​(boolean developerPanelEnabled)
Enables or disables the developer panel.
Parameters:
developerPanelEnabled - if false, there will be no button to show the developer panel

setDeveloperPanelVisibleOnStart

void setDeveloperPanelVisibleOnStart​(boolean developerPanelVisibleOnStart)
Shows (if enabled) the developer panel when the model window is shown.
Parameters:
developerPanelVisibleOnStart - if true, the panel will be visible from the beginning, and may be later hidden by pressing the special button.

setRunControlEnabled

void setRunControlEnabled​(boolean runControlEnabled)
Enables or disables Run, Pause, and Stop buttons on the model toolbar (but not in the developer panel), and sets the corresponding tooltips.
Parameters:
runControlEnabled - if false, those buttons will be disabled

isRunControlEnabled

boolean isRunControlEnabled()
Tests if Run, Pause, and Stop buttons on the model toolbar are enabled.
Returns:
true if they are enabled, false if not.

setSpeedControlEnabled

void setSpeedControlEnabled​(boolean speedControlEnabled)
Enables or disables the model execution speed control buttons on the model toolbar (but not in the developer panel), and sets the corresponding tooltips.
Parameters:
speedControlEnabled - if false, those buttons will be disabled

isSpeedControlEnabled

boolean isSpeedControlEnabled()
Tests if the model execution speed control buttons on the model toolbar are enabled.
Returns:
true if they are enabled, false if not.

addInspect

void addInspect​(double x,
                double y,
                Presentable p,
                java.lang.String name)
Creates an inspect window at a particular location for an element of a Presentable object. If there is another inspect with the same Presentable and same element name, it is brought to front and a new inspect is not created. The initial size of the window is adjusted to fit the initial contents.
Parameters:
x - the x coordinate in the presentable object system
y - the y coordinate in the presentable object system
p - the Presentable object whose element is being inspected
name - the name of the element being inspected

removeInspect

void removeInspect​(Presentable p,
                   java.lang.String name)
Removes the inspect window for the given element
Parameters:
p - the Presentable object whose element is being inspected
name - the name of the element being inspected

showMessageDialog

void showMessageDialog​(java.lang.String text)
Shows a standard message dialog box with the given text. This method usually returns immediately - it doesn't wait for the dialog to be closed (except the cases when called from UI thread)
Parameters:
text - the text to display

showErrorDialog

@AnyLogicInternalAPI
void showErrorDialog​(java.lang.String text,
                     java.lang.String title)
Shows a standard error dialog box with the given text. This method usually returns immediately - it doesn't wait for the dialog to be closed (except the cases when called from UI thread)
Parameters:
text - the text to display
title - title of the dialog window

showErrorInModelDialog

@AnyLogicInternalAPI
void showErrorInModelDialog​(java.lang.String text,
                            java.lang.String title)
Shows a standard 'error in model logic' dialog box with the given text. This method usually returns immediately - it doesn't wait for the dialog to be closed (except the cases when called from UI thread)
Parameters:
text - the text to display
title - title of the dialog window

openWebSite

void openWebSite​(java.lang.String url)
Opens web page with the given URL in the browser
Parameters:
url - the url to open

copyToClipboard

void copyToClipboard​(java.lang.String text)
Copies the given text to the system clipboard
Due to the security policy of the browser, the actual copying may be preceded by a prompt.
Parameters:
text - the text to copy

saveSnapshot

default void saveSnapshot​(java.lang.String fileName)
Pauses experiment if it is currently running, saves snapshot and then resumes experiment if it was running
On any error throws nothing. If you need "on success" notification and/or custom error processing, please saveSnapshot(String, Runnable, Consumer) function with callbacks

This method is only available in the AnyLogic Professional
Parameters:
fileName - the name of snapshot file

saveSnapshot

void saveSnapshot​(java.lang.String fileName,
                  java.lang.Runnable successfulCallback,
                  java.util.function.Consumer<java.lang.Throwable> errorCallback)
Pauses experiment if it is currently running, saves snapshot and then resumes experiment if it was running
On any error throws nothing.
Usage example:
 getExperimentHost().saveSnapshot(
                "file.als",
                () -> traceln("Saved!"),
                e -> {
                        traceln("Error!");
                        e.printStackTrace();
                }
 );
 

This method is only available in the AnyLogic Professional
Parameters:
fileName - the name of snapshot file
successfulCallback - called when snapshot is successfully saved
errorCallback - called in case of any error

loadSnapshot

default void loadSnapshot​(java.lang.String fileName)
Stops experiment and loads snapshot (in its 'not running' state), doesn't resume simulation of loaded snapshot.
On any error throws nothing, silently rollbacks to the current experiment and resumes it if it was running. If you need "on success" notification and/or custom error processing, please loadSnapshot(String, Runnable, Consumer) function with callbacks

When snapshot is loaded, presentation forgets everything about the model which was running before (including the engine, experiment and agents), therefore, it is recommended not to keep references to model objects after this method call

This method is only available in the AnyLogic Professional
Parameters:
fileName - the name of snapshot file

loadSnapshot

void loadSnapshot​(java.lang.String fileName,
                  java.lang.Runnable successfulCallback,
                  java.util.function.Consumer<java.lang.Throwable> errorCallback)
Stops experiment and loads snapshot (in its 'not running' state), doesn't resume simulation of loaded snapshot.
On any error throws nothing, silently rollbacks to the current experiment and resumes it if it was running.

When snapshot is loaded, presentation forgets everything about the model which was running before (including the engine, experiment and agents), therefore, it is recommended not to keep references to model objects after this method call
Usage example:
 getExperimentHost().loadSnapshot(
                "file.als",
                () -> {
                        traceln("Loaded!");
                        getExperimentHost().setPresentable(
                                getExperiment().getEngine().getRoot()
                        );
                        getExperiment().run();
                },
                e -> {
                        traceln("Error!");
                        e.printStackTrace();
                }
 );
 

This method is only available in the AnyLogic Professional
Parameters:
fileName - the name of snapshot file

close

void close()
This method returns immediately and performs the following actions in a separate thread:
  • stops experiment if it is not stopped,
  • destroys the model and
  • closes experiment window (only if model is started in the application mode)

launch

@AnyLogicInternalAPI
void launch​(boolean startServer,
            boolean startExperiment)
Creates and optionally runs experiment, starts frame collection
Parameters:
startServer - TODO

launch

default void launch()

getConfiguration

@AnyLogicInternalAPI
LaunchConfiguration getConfiguration()

getUpdate

@AnyLogicInternalAPI
AnimationPacket getUpdate​(boolean fullFrame)

getNextFrameNumber

@AnyLogicInternalAPI
long getNextFrameNumber()

executeUserAction

@AnyLogicInternalAPI
void executeUserAction​(long id,
                       java.lang.String value)

executeCommand

@AnyLogicInternalAPI
void executeCommand​(java.lang.String cmd,
                    java.lang.String parameters)

getExperimentState

@AnyLogicInternalAPI
Experiment.State getExperimentState()

setValue

@AnyLogicInternalAPI
void setValue​(java.lang.String pathtofield,
              IExperimentHost.IValue value)

getValue

@AnyLogicInternalAPI
java.lang.Object getValue​(java.lang.String pathtofield)

callFunction

@AnyLogicInternalAPI
java.lang.Object callFunction​(java.lang.String pathtofunction,
                              IExperimentHost.IValue... args)

getProgress

@AnyLogicInternalAPI
double getProgress()

setSpeed

@AnyLogicInternalAPI
void setSpeed​(double speed)

setMaxFPS

@AnyLogicInternalAPI
void setMaxFPS​(double maxFPS)

setSendConsoleItems

@AnyLogicInternalAPI
void setSendConsoleItems​(boolean yes)

postExperimentSettings

@AnyLogicInternalAPI
void postExperimentSettings()

onAgentDestroyed_xjal

@AnyLogicInternalAPI
void onAgentDestroyed_xjal​(Agent ao)
A callback called by the engine when an agent is being destroyed. If that agent is currently displayed by the presentation, display experiment.
Parameters:
ao - the agent being destroyed
How can we improve this article?