com.xj.anylogic.engine
Class Experiment<ROOT extends ActiveObject>

java.lang.Object
  extended by com.xj.anylogic.engine.Presentable
      extended by com.xj.anylogic.engine.Utilities
          extended by com.xj.anylogic.engine.Experiment<ROOT>
Type Parameters:
ROOT - class of root object
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ExperimentCompareRuns, ExperimentOptimization, ExperimentParamVariation, ExperimentSimulation

public abstract class Experiment<ROOT extends ActiveObject>
extends Utilities

A base class for all AnyLogic experiments. Experiment describes how would one like to run the model (just perfrom a single simulation run, do Monte Carlo simulation, vary parameters, optimize, etc.), and what outputs of the model you are interested in (this may be a simple chart of how a certain value was changing over time during a run, or how an observable depends on a parameter in case of multiple runs, or a histogram in case of risk analysis, etc.). The experiment is also capable of storing the outputs producted by the model so that they are available after the simulation and independently of it. Experiment can display itself in a presentation window and be controlled by the presentation GUI. For that purpose it supports a set of commands that can be assigned to the presentation window toolbar buttons and menu items.

AnyLogic models with GUI can run as Java applications as well as applets. This is the recommended HTML for AnyLogic applets:

 
 <?xml version="1.0" encoding="UTF-8"?>
 <html>
 <head>
        <meta http-equiv="content-type" content="text/html" />
        <meta http-equiv="pragma" content="no-cache" />
        <meta http-equiv="expires" content="0" />
        <title>My Model - AnyLogic 6</title>
 <style type="text/css">
 body, html, object, embed, applet { margin:0; padding:0; border:0; }
 </style></head>
 <body>
  <object
                classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
                width="100%"
                height="100%"
                codebase="http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,7">
                <param name="code" value="my_package/MyExperiment$Applet.class" />
                <param name="archive" value="com.xj.anylogic.engine.jar,my_model.jar" />
                <comment>
                        <embed
                                code="my_package/MyExperiment$Applet.class"
                                archive="com.xj.anylogic.engine.jar,my_model.jar"
                                width="100%"
                                height="100%"
                                type="application/x-java-applet"
                                pluginsspage="http://java.sun.com/j2se/1.5.0/download.html">
                        <noembed>
                         <applet
                                code="my_package/MyExperiment$Applet.class"
                                archive="com.xj.anylogic.engine.jar,my_model.jar"
                                width="100%"
                                height="100%"> </applet>
                        </noembed>
                </embed>
                </comment>
        </object>
 </body>
 </html>
 
 

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

Field Summary
static int ERROR
           
static int FINISHED
           
static int IDLE
           
 com.xj.anylogic.engine.internal.ActionQueue modelExecutionCommandQueue
          This field shouldn't be accessed by user
is public due to technical reasons
 com.xj.anylogic.engine.internal.ActionQueue mutexModelActionQueue
          This field shouldn't be accessed by user
is public due to technical reasons
static int OPEN_RESULTS
           
static int OPEN_SNAPSHOT
           
static int PAUSE
           
static int PAUSED
           
static int PLEASE_WAIT
           
static int RUN
           
static int RUNNING
           
static int SAVE_RESULTS
           
static int SAVE_SNAPSHOT
           
static int STEP
           
static int STOP
           
 
Fields inherited from class com.xj.anylogic.engine.Utilities
AM, APRIL, AUGUST, DAY, DECEMBER, FEBRUARY, FRIDAY, HOUR, infinity, JANUARY, JULY, JUNE, MARCH, MAY, MILLISECOND, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SUNDAY, THURSDAY, TIME_UNIT_DAY, TIME_UNIT_HOUR, TIME_UNIT_MILLISECOND, TIME_UNIT_MINUTE, TIME_UNIT_SECOND, TIME_UNIT_WEEK, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK, YEAR
 
Fields inherited from class com.xj.anylogic.engine.Presentable
ALIGNMENT_CENTER, ALIGNMENT_LEFT, ALIGNMENT_RIGHT, CAD_ANTIALIASING, CAD_INVERTED, LINE_STYLE_DASHED, LINE_STYLE_DOTTED, LINE_STYLE_SOLID, NAVIGATION_FULL, NAVIGATION_LIMITED_TO_Z_ABOVE_ZERO, NAVIGATION_NONE, NAVIGATION_ROTATION_ONLY, SHAPE_ARC, SHAPE_BUTTON, SHAPE_CAD, SHAPE_CHART_BAR, SHAPE_CHART_HISTOGRAM, SHAPE_CHART_HISTOGRAM2D, SHAPE_CHART_PIE, SHAPE_CHART_PLOT, SHAPE_CHART_STACK, SHAPE_CHART_TIME_COLOR, SHAPE_CHART_TIME_PLOT, SHAPE_CHART_TIME_STACK, SHAPE_CHECKBOX, SHAPE_COMBOBOX, SHAPE_CURVE, SHAPE_EMBEDDED_OBJECT, SHAPE_FILECHOOSER, SHAPE_GROUP, SHAPE_IMAGE, SHAPE_LINE, SHAPE_LISTBOX, SHAPE_OVAL, SHAPE_PIXEL, SHAPE_POLYLINE, SHAPE_PROGRESSBAR, SHAPE_RADIOBUTTONS, SHAPE_RECTANGLE, SHAPE_ROUNDED_RECTANGLE, SHAPE_SLIDER, SHAPE_TEXT, SHAPE_TEXTFIELD
 
Method Summary
 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)
abstract  ROOT createRoot(Engine engine)
          Is called to obtain a new root active object.
 java.lang.RuntimeException error(java.lang.String errorText)
          Signals an error during the model run by throwing a RuntimeException with errorText preceded by the active object full name.
 java.lang.String[] getCommandLineArguments()
          Returns an array of Command-line Arguments passed to this experiment on model start (empty array in case of no arguments)
Never returns null
 java.lang.Object getMutexRead_xjal()
           
 java.lang.Object getMutexWrite_xjal()
           
 java.lang.String getName()
          Returns the name of the experiment.
 Presentation getPresentation()
          Returns the presentation object of the model, or null if there is none.
abstract  double getProgress()
          Returns the progress of the experiment: a number between 0 and 1 depending on what part of experiment is completed, or -1 if not known.
 int getRunCount()
          Returns the number of the current simulation run, more precisely the number of times the model was destroyed.
abstract  double getRunTimeSeconds()
          Returns the real duration of the experiment in seconds, excluding pause times.
 java.lang.String getSnapshotFileName()
          Returns the name of snapshot file this experiment is configured to start simulation from
abstract  int getState()
          Returns the current state of the experiment: IDLE, PAUSED, RUNNING, FINISHED, ERROR, or PLEASE_WAIT
 long getStep()
          Returns the number of events executed by the engine.
 int getWindowHeight()
          Returns the initial height of the experiment window, 600 by default.
 int getWindowWidth()
          Returns the initial width of the experiment window, 800 by default.
 void initDefaultRandomNumberGenerator(Engine engine)
          This method should be overridden to initialize random number generator of the given engine
Default implementation set new random generation with random seed - for unique experiments
 boolean isCommandEnabled(int cmd)
          Checks if a command can be executed.
 boolean isLoadRootFromSnapshot()
          Returns true if this experiment is configured to start simulation from state loaded from snapshot file
 void onBeforeSimulationRun(ROOT root)
          User's extension point for Before Simulation Run Code
By default does nothing
 void onDestroy_xjal()
          This method normally shouldn't be called by user.
 void onDestroy()
          User extension point which is called when the experiment object is dynamically disposed - before closing the model window.
 void onEngineFinished()
          Is called by the engine when it finishes running and is intended to wrap up a single simulation run.
 void onError(java.lang.Throwable error)
          This method may be overridden to perform custom processing on errors in the model execution (i.e. errors in the action code of events, dynamic events, transitions, entry/exit codes of states etc, formulas, conditions of events etc.)
abstract  void pause()
          Pauses the experiment execution.
 void registerPresentation_xjal(Presentation presentation)
          This method isn't designed to be called by user.
 void reset()
          Is called each time before a new model is created and is intended to reset all data associated with the experiment.
abstract  void run()
          Starts the experiment execution from the current state.
 void setCommandLineArguments_xjal(java.lang.String[] commandLineArguments)
          This method should not be called by user
 void setLoadRootFromSnapshot(java.lang.String snapshotFileName)
          Tells this experiment to load the root object from AnyLogic snapshot file

This method is only available in the AnyLogic Professional
 void setName(java.lang.String name)
          Sets the name of the experiment.
 void setup(java.awt.Container container)
          Is called in static main() method of applications and in the init() method of applets, after the experiment is constructed.
 void setupEngine(Engine engine)
          Is called for the simulation engine when it is created
abstract  void step()
          Performs one step of experiment execution.
abstract  void stop()
          Terminates the experiment execution.
 
Methods inherited from class com.xj.anylogic.engine.Utilities
bernoulli, bernoulli, beta, beta, beta, beta, beta, binomial, binomial, binomial, binomial, binomial, briefInfoOn, cauchy, cauchy, cauchy, chi2, chi2, chi2, copyToClipboard, createURL_xjal, date, dateToTime, day, difference, difference, differenceInDateUnits, differenceInDateUnits, dropTime, erlang, erlang, erlang, error, exponential, exponential, exponential, exponential, exponential, exponential, format, format, format, format, format, format, formatDayOfWeek, formatGeoHeading, formatLatitude, formatLongitude, formatMonth, formatTimeInterval, gamma_frac, gamma, gamma, gamma, gamma, gamma, gammaLog, geometric, geometric, getAmPm, getAmPm, getDayOfMonth, getDayOfMonth, getDayOfWeek, getDayOfWeek, getDayOfYear, getDefaultRandomGenerator, getDistance, getDistance, getDistanceFromPointToLine, getDistanceFromPointToLineSq, getDistanceFromPointToSegment, getDistanceFromPointToSegmentSq, getDistanceSq, getDistanceSq, getHour, getHour, getHourOfDay, getHourOfDay, getLength, getLength, getMillisecond, getMillisecond, getMinute, getMinute, getMonth, getMonth, getRandom, getRandom, getSecond, getSecond, getTime, getYear, getYear, gumbel1, gumbel1, gumbel2, gumbel2, hour, hypergeometric, hypergeometric, inspectOf, isLineIntersectingLine, isLineIntersectingRectangle, isPointInsideRectangle, isPointOnTheSameLine, laplace, laplace, limit, limitMax, limitMin, logarithmic, logarithmic, logistic, logistic, lognormal, lognormal, millisecond, minute, negativeBinomial, negativeBinomial, negativeBinomial, negativeBinomial, normal, normal, normal, normal, normal, normal, pareto, pareto, pareto, pert, pert, poisson, poisson, poisson, poisson, prepareBeforeExperimentStart_xjal, pulse, pulseTrain, quantum, ramp, randomFalse, randomFalse, randomTrue, randomTrue, rayleigh, rayleigh, rayleigh, second, setDefaultRandomGenerator, sqr, step, time, timeToDate, toDate, toDateInMillis, toLatitude, toLongitude, toTimeout, trace, traceln, traceln, traceln, triangular, triangular, triangular, triangular, triangular, uniform_discr, uniform_discr, uniform_discr, uniform_pos, uniform_pos, uniform, uniform, uniform, uniform, uniform, week, weibull, weibull, weibull, weibull, weibull, xidz, zidz
 
Methods inherited from class com.xj.anylogic.engine.Presentable
contains, drawCollection, drawDatabase, drawDataset, drawExcelFile, drawFunction, drawHistogram2DData, drawHistogramData, drawInsert, drawKeyValueTable, drawModel, drawModelElements, drawPlainVariable, drawPresentation, drawQuery, drawSchedule, drawShape, drawStatistics, drawTableFunction, drawTextFile, drawUpdate, executeShapeControlAction, executeShapeControlAction, executeShapeControlAction, executeShapeControlAction, executeShapeControlAction, executeShapeControlAction, finishReadObject_xjal, getEngine, getExperiment, getNameOfShape, getPersistentShape, getShapeArcAngle, getShapeArcAngle, getShapeArcStartAngle, getShapeArcStartAngle, getShapeCADCustomLayerColors, getShapeCADDrawingAttributes, getShapeCADDrawingAttributes, getShapeCADFileName, getShapeCADFileName, getShapeCADVisibleLayerNames, getShapeChartColorFromDouble, getShapeChartDataColors, getShapeChartDataItems, getShapeChartDataPlotOptions, getShapeChartDataSets, getShapeChartDataTitles, getShapeChartHistogram2DOptions, getShapeChartHistogramOptions, getShapeChartHistograms, getShapeChartHistograms2D, getShapeChartProperties, getShapeControl, getShapeControl, getShapeControlDefaultValueBoolean, getShapeControlDefaultValueBoolean, getShapeControlDefaultValueDouble, getShapeControlDefaultValueDouble, getShapeControlDefaultValueInt, getShapeControlDefaultValueInt, getShapeControlDefaultValueString, getShapeControlDefaultValueString, getShapeControlManager, getShapeControlMaximum, getShapeControlMaximum, getShapeControlMinimum, getShapeControlMinimum, getShapeControlMultipleSelectionMode, getShapeControlMultipleSelectionMode, getShapeControlProgressString, getShapeControlProgressString, getShapeControlTexts, getShapeControlTexts, getShapeControlTexts2D, getShapeControlTexts2D, getShapeControlType, getShapeControlType, getShapeControlValueType, getShapeControlValueType, getShapeEmbeddedObject, getShapeEmbeddedObject, getShapeFillColor, getShapeFillColor, getShapeFont, getShapeFont, getShapeGroupContent, getShapeHeight, getShapeHeight, getShapeImageFileNames, getShapeImageFileNames, getShapeImageNumber, getShapeImageNumber, getShapeLineColor, getShapeLineColor, getShapeLineDx, getShapeLineDx, getShapeLineDy, getShapeLineDy, getShapeLineStyle, getShapeLineStyle, getShapeLineWidth, getShapeLineWidth, getShapeNPoints, getShapeNPoints, getShapePackagePrefix, getShapePointsDx, getShapePointsDx, getShapePointsDy, getShapePointsDy, getShapeRadiusX, getShapeRadiusX, getShapeRadiusY, getShapeRadiusY, getShapeReplication, getShapeRotation, getShapeRotation, getShapeScaleX, getShapeScaleX, getShapeScaleY, getShapeScaleY, getShapeText, getShapeText, getShapeTextAlignment, getShapeTextAlignment, getShapeType, getShapeWidth, getShapeWidth, getShapeX, getShapeX, getShapeY, getShapeY, getViewAreas, iconContains, isShapeCADNegative, isShapeCADNegative, isShapeClosed, isShapeClosed, isShapeControlEnabled, isShapeControlEnabled, isShapeControlVertical, isShapeControlVertical, isShapePublic, isShapeVisible, isShapeWithManualControlPoints, isShapeWithManualControlPoints, modelElementContains, modelElementContains, onClickIconAt, onClickModelAt, onClickPresentationAt, onItemRemoved, onSelectionChanged, onShapeClick, onShapeClickAt, onShapeGroupDraw, presentationContains, readCustomData, setControlValueToDefault, setControlValueToDefault, writeCustomData
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

OPEN_RESULTS

public static final int OPEN_RESULTS
See Also:
Constant Field Values

SAVE_RESULTS

public static final int SAVE_RESULTS
See Also:
Constant Field Values

OPEN_SNAPSHOT

public static final int OPEN_SNAPSHOT
See Also:
Constant Field Values

SAVE_SNAPSHOT

public static final int SAVE_SNAPSHOT
See Also:
Constant Field Values

RUN

public static final int RUN
See Also:
Constant Field Values

STEP

public static final int STEP
See Also:
Constant Field Values

PAUSE

public static final int PAUSE
See Also:
Constant Field Values

STOP

public static final int STOP
See Also:
Constant Field Values

modelExecutionCommandQueue

public transient com.xj.anylogic.engine.internal.ActionQueue modelExecutionCommandQueue
This field shouldn't be accessed by user
is public due to technical reasons


mutexModelActionQueue

public transient com.xj.anylogic.engine.internal.ActionQueue mutexModelActionQueue
This field shouldn't be accessed by user
is public due to technical reasons

Method Detail

setName

public void setName(java.lang.String name)
Sets the name of the experiment.

Parameters:
name - the new name of the experiment

getName

public java.lang.String getName()
Returns the name of the experiment.

Returns:
the name of the experiment

error

public java.lang.RuntimeException error(java.lang.String errorText)
Description copied from class: Utilities
Signals an error during the model run by throwing a RuntimeException with errorText preceded by the active object full name.

Specified by:
error in class Utilities
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");

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

getState

public abstract int getState()
Returns the current state of the experiment: IDLE, PAUSED, RUNNING, FINISHED, ERROR, or PLEASE_WAIT

Returns:
the current state of the experiment

getProgress

public abstract double getProgress()
Returns the progress of the experiment: a number between 0 and 1 depending on what part of experiment is completed, or -1 if not known.

Returns:
the progress of the experiment

getRunTimeSeconds

public abstract double getRunTimeSeconds()
Returns the real duration of the experiment in seconds, excluding pause times.

Returns:
the real duration of the experiment in seconds

getWindowWidth

public int getWindowWidth()
Returns the initial width of the experiment window, 800 by default.

Returns:
the initial width of the experiment window

getWindowHeight

public int getWindowHeight()
Returns the initial height of the experiment window, 600 by default.

Returns:
the initial height of the experiment window

getPresentation

public Presentation getPresentation()
Description copied from class: Presentable
Returns the presentation object of the model, or null if there is none.

Specified by:
getPresentation in class Presentable
Returns:
the presentation object of the model, or null

run

public abstract void run()
Starts the experiment execution from the current state.


step

public abstract void step()
Performs one step of experiment execution.


pause

public abstract void pause()
Pauses the experiment execution.


stop

public abstract void stop()
Terminates the experiment execution.


close

public void close()
This method returns immediately and performs the following actions in a separate thread:


isCommandEnabled

public boolean isCommandEnabled(int cmd)
Checks if a command can be executed. The possible command ids are: OPEN_RESULTS, SAVE_RESULTS, OPEN_SNAPSHOT, SAVE_SNAPSHOT, RUN, STEP PAUSE, STOP.

Parameters:
cmd - the command id
Returns:
true if the command can be executed, false otherwise

setLoadRootFromSnapshot

public final void setLoadRootFromSnapshot(java.lang.String snapshotFileName)
Tells this experiment to load the root object from AnyLogic snapshot file

This method is only available in the AnyLogic Professional

Parameters:
snapshotFileName -

isLoadRootFromSnapshot

public final boolean isLoadRootFromSnapshot()
Returns true if this experiment is configured to start simulation from state loaded from snapshot file

Returns:
true if this experiment is configured to start simulation from state loaded from snapshot file

getSnapshotFileName

public final java.lang.String getSnapshotFileName()
Returns the name of snapshot file this experiment is configured to start simulation from

Returns:
the name of snapshot file this experiment is configured to start simulation from

getCommandLineArguments

public final java.lang.String[] getCommandLineArguments()
Returns an array of Command-line Arguments passed to this experiment on model start (empty array in case of no arguments)
Never returns null

Returns:
array of Command-line Arguments passed to this experiment on model start

createRoot

public abstract ROOT createRoot(Engine engine)
Is called to obtain a new root active object. This method must be defined in a subclass. Note that the root active object should just be constructed in this method, as its create() and start() methods will be called later on.
This method should not be used to define parameters

Parameters:
engine - the simulation engine that will simulate the model

onBeforeSimulationRun

public void onBeforeSimulationRun(ROOT root)
User's extension point for Before Simulation Run Code
By default does nothing


onEngineFinished

public void onEngineFinished()
Is called by the engine when it finishes running and is intended to wrap up a single simulation run. This is a user's extension points; by default does nothing.


reset

public void reset()
Is called each time before a new model is created and is intended to reset all data associated with the experiment. This is an user's extension point; by default does nothing.


setup

public void setup(java.awt.Container container)
Is called in static main() method of applications and in the init() method of applets, after the experiment is constructed. Is intended to perform initial setup of the simulation engine and the presentation, if any. This is a user's extension points; by default does nothing.

Parameters:
container - the applet - in applet mode, external container - in component mode, or null in standalone application mode

setupEngine

public void setupEngine(Engine engine)
Is called for the simulation engine when it is created

Parameters:
engine - the simulation engine

onDestroy

public void onDestroy()
User extension point which is called when the experiment object is dynamically disposed - before closing the model window.
This method may be overridden to perform custom actions.
Default implementation does nothing.


onDestroy_xjal

public void onDestroy_xjal()
This method normally shouldn't be called by user.
Is called when the experiment object is dynamically disposed - before closing the model window.
This method should be overridden to call onDestroy(), release resources (e.g. commit connections with database) and call super.onDestroy_xjal() method


initDefaultRandomNumberGenerator

public void initDefaultRandomNumberGenerator(Engine engine)
This method should be overridden to initialize random number generator of the given engine
Default implementation set new random generation with random seed - for unique experiments

Parameters:
engine - the engine instance

onError

public void onError(java.lang.Throwable error)
This method may be overridden to perform custom processing on errors in the model execution (i.e. errors in the action code of events, dynamic events, transitions, entry/exit codes of states etc, formulas, conditions of events etc.)
By default, this method does nothing

Parameters:
error - an error which has occurred during event execution

setCommandLineArguments_xjal

public void setCommandLineArguments_xjal(java.lang.String[] commandLineArguments)
This method should not be called by user

Parameters:
commandLineArguments -

getMutexRead_xjal

public java.lang.Object getMutexRead_xjal()

getMutexWrite_xjal

public java.lang.Object getMutexWrite_xjal()

registerPresentation_xjal

public void registerPresentation_xjal(Presentation presentation)
This method isn't designed to be called by user.
Public due to technical reasons
May be removed in future releases



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