Custom experiment runs experiment with custom scenario entirely written by user.
Custom experiment gives you maximum flexibility with setting parameters, managing simulation runs, making decisions. It simply gives you a code field where you can do all that (and a lot more) by using a rich Java API of AnyLogic engine (methods like run(), stop(), etc.). Refer to the Custom experiment functions section for details.
This experiment has no
built-in graphical interface as well as no predefined behavior.
To know how to save / restore model snapshots from custom experiment, please refer here.
Here are the links to demo models with custom experiments. Please examine the custom experiment's code in its Code properties section to understand the scenario implementation.
The following model is the simplest custom experiment demo. The experiment creates the engine, model, configures and runs the simulation, and outputs the result in Console:
Demo model: Simple Custom Experiment
In the following model the custom experiment implements interaction via Console:
Demo model: Custom Experiment Interacting with Console
In the following model the custom experiment configures and runs optimization without creating the optimization experiment window:
Demo model: Optimization Without UI
In the following model the custom experiment is used to perform the calibration from the running simulation experiment. Run the simulation, and you will see the button starting the custom experiment performing the calibration:
Demo model: Calibration from Within Simulation
– The name of the experiment.
Since AnyLogic generates Java class for each experiment, please follow Java naming guidelines and start the name with an uppercase letter.
Ignore – If selected, the experiment is excluded from the model.
Here you can type the code for this custom experiment. By default you
can find here code that was automatically generated on the
experiment creation. This
code creates simulation engine, sets experiment's stop time,
creates top-level agent, starts the experiment in the fast
and then stops it.
You can study
this very simple code to get some ideas on how to extend it
further to achieve the required custom behavior.
Maximum available memory – The maximum size of Java heap allocated for the model.
Java machine arguments – Specify here Java machine arguments you want to apply on launching your model. You can find the detailed information on possible arguments at Java Documentation web site: http://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html
Command-line arguments – Here you can specify command line arguments you want to pass to your model. You can get the values of passed argument values in the experiment's Additional class code using the method String getCommandLineArguments()
Imports section – import statements needed for correct compilation of the experiment class' code. When Java code is generated, these statements are inserted before definition of the Java class.
Additional class code – Arbitrary member variables, nested classes, constants and methods are defined here. This code will be inserted into the experiment class definition. You can access these class data members anywhere within this experiment.