Package com.anylogic.engine
- java.lang.Object
- com.anylogic.engine.ExperimentCustom
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ExperimentReinforcementLearning
,ExperimentTest
public abstract class ExperimentCustom extends Object implements Serializable
Base class for all custom experiments
The experiment scenario should be defined in the overridden
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
A sample action code of some Main agent which runs custom experiment:
Usage notes
Use
Don't forget to setup stop time or stop date to the engine before
Use
The simplest example of
See also an example of optimization performed within custom experiment.
The experiment scenario should be defined in the overridden
run()
methodCustom 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 agent 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
modeDon't forget to setup stop time or stop date to the engine before
Use
ExperimentOptimization.createOptimization(Engine)
to
create new OptQuest Optimization instanceThe simplest example of
run()
code:
// Create Engine, initialize random number generator: Engine engine = createEngine(); // Set stop time engine.setStopTime( 100 ); // Create new top-level agent: Main root = new Main(engine, null, null); // Setup parameters of top-level agent 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:
- AnyLogic North America, LLC https://anylogic.com
- See Also:
-
run()
Serialized Form
Constructor | Description |
---|---|
ExperimentCustom |
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
|
Modifier and Type | Method | Description |
---|---|---|
final Engine | createEngine() |
Creates Engine
|
final 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 |
This method may be overridden to perform custom processing
on errors in the model execution (i.e.
|
void | onError |
This method may be overridden to perform custom processing
on errors in the model execution (i.e.
|
abstract void | run() |
Use
createEngine() |
void | setCommandLineArguments_xjal |
This method should not be called by user
|
void | setupEngine_xjal |
This method should not be called by user
|
public ExperimentCustom(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.)
public final Engine createEngine()
Creates Engine
- Returns:
- new
Engine
instance
@AnyLogicInternalCodegenAPI public void setupEngine_xjal(Engine engine)
This method should not be called by user
- Parameters:
engine
-
public abstract void run()
Use
createEngine()
public void onError(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.
This method shouldn't be called directly by user. Instead, engine calls it internally.
By default, this method does nothing.
This method shouldn't be called directly by user. Instead, engine calls it internally.
- Parameters:
error
- an error which has occurred during event execution
public void onError(Throwable error, Agent root)
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.
This method shouldn't be called directly by user. Instead, engine calls it internally.
By default, this method does nothing.
This method shouldn't be called directly by user. Instead, engine calls it internally.
- Parameters:
error
- an error which has occurred during event executionroot
- the root (main) agent of the model, useful for experiments with multiple runs executed in parallel. May benull
in some cases (e.g. on errors during root agent creation).- Since:
- 8.4
@AnyLogicInternalCodegenAPI public void setCommandLineArguments_xjal(String[] commandLineArguments)
This method should not be called by user
- Parameters:
commandLineArguments
-
public final 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
This method is designed for usage inside the
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