com.xj.anylogic.engine
Class ExperimentCustom

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

public abstract class ExperimentCustom
extends java.lang.Object
implements java.io.Serializable

Base class for all custom experiments
The experiment scenario should be defined in the overridden run() method

Custom experiment may be executed from another experiment - in this case the latter should be passed as an argument to the constructor of the custom experiment. Experiment is executed by calling run() method.
A sample action code of some Main active object which runs custom experiment:

 // Create custom experiment, pass currently running experiment
 // as an argument to the constructor:
 MyCustomExperiment e = new MyCustomExperiment(getExperiment());
 // setup some custom fields defined in the
 // additional class code of MyCustomExperiment:
 e.day = getDayOfWeek();
 // run experiment
 e.run();
 // collect results from custom fields defined in the
 // additional class code of MyCustomExperiment:
 traceln( "result: " + e.myResult );
(In the example above, custom experiment has Code (which is actually inside run() method) which gets field day (defined in the additional class code), uses it in the experiment and then sets some result value to the field myResult)

Usage notes
Use createEngine() to create new Engine instance Use Engine.runFast() method to run experiment in the fastest possible mode
Don't forget to setup stop time or stop date to the engine before
Use ExperimentOptimization.createOptimization(Engine) to create new OptQuest Optimization instance

The simplest example of run() code:
 // Create Engine, initialize random number generator:
 Engine engine = createEngine();
 // Set stop time
 engine.setStopTime( 100 );
 // Create new root object:
 Main root = new Main(engine, null, null);
 // Setup parameters of root object here
 root.myParameter = 10;
 // Prepare Engine for simulation:
 engine.start( root );
 // Start simulation in fast mode:
 engine.runFast();
 // Obtain results of simulation here
 traceln( root.myResult );
 // Destroy the model:
 engine.stop();
 
This object is only available in the AnyLogic Professional

See also an example of optimization performed within custom experiment.

Author:
XJ Technologies Company Ltd. www.anylogic.com
See Also:
run(), Serialized Form

Constructor Summary
ExperimentCustom(java.lang.Object parentExperiment)
          Creates new custom experiment which may be executed from another experiment - in this case the latter should be passed as an argument to the constructor of the custom experiment
 
Method Summary
 Engine createEngine()
          Creates Engine
 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
This method is designed for usage inside the run() method
 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 run()
          Use createEngine()
 void setCommandLineArguments_xjal(java.lang.String[] commandLineArguments)
          This method should not be called by user
 void setupEngine_xjal(Engine engine)
          This method should not be called by user
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExperimentCustom

public ExperimentCustom(java.lang.Object parentExperiment)
Creates new custom experiment which may be executed from another experiment - in this case the latter should be passed as an argument to the constructor of the custom experiment

Parameters:
parentExperiment - experiment which uses/runs this custom experiment (it may be experiment of any type: simulation, optimization, custom etc.)
Method Detail

createEngine

public final Engine createEngine()
Creates Engine

Returns:
new Engine instance

setupEngine_xjal

public void setupEngine_xjal(Engine engine)
This method should not be called by user

Parameters:
engine -

run

public abstract void run()
Use createEngine()


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 -

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
This method is designed for usage inside the run() method

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


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