Setting up parameters prior to model execution

Controls can be placed on the experiment's front-end page and used to set up parameters prior to the model execution (as shown in the figure below). 

Let's study this on the example of our model called Wandering Elephants. This model has the NumberOfElephants parameter defined in the Main top-level agent. This parameter defines the number of elephants. Let us enable users to set up this parameter from the simulation experiment page prior to the model execution.

How-To video: Setting up parameters from the experiment page

 To link a control on the experiment page to a parameter of the model top-level agent

  1. Open the diagram of the Simulation experiment (by double-clicking the Simulation item in the Projects view).
  1. On the experiment page, add a slider to vary the number of elephants. Drag the  Slider element from the  Controls palette into the graphical editor.
  1. Configure the slider. In the slider's properties, set the Minimum value, Maximum value and Default value parameters of the slider. Click the Add labels... button to add labels to the slider that will display its min, max and current values.
  2. Now we will link it to the parameter of the model's top-level agent Main. Open the Parameters section of the Simulation experiment's properties. Here you can set up values of all the parameters of the model's top-level agent (Main). 
  1. In the NumberOfElephants field, specify the actual value for this parameter by typing: slider.getIntValue().
    Use code completion to type this code.
  1. Run the experiment and play with the slider. You will see that the number of elephants in the model is equal to the number that you have defined with the slider prior to running the model.

We have used the getIntValue() function of the slider here to get the current integer value of the slider and link it to the NumberOfElephants parameter of the Main agent.

You can use the same technique for other controls. Please note that you use different functions, and the function name differs depending on the control and the value type of the parameter you are linking.

Control

Type of value

Can be linked to type

Function to get value

Checkbox

boolean

boolean

isSelected()

Edit box

String

String 

double 

int

getText()

getDoubleValue()

getIntValue()

Radio buttons

int

int

getValue()

Slider

double

double

int

getValue()

getIntValue()

Combo box

String

String

getValue()

List box

String

String

getValue()