We will use the AnyLogic Cloud optimization experiment to find the best values for the Smin and Smax parameters.
We will loop the model with the optimizer. The optimizer will perform a some search strategy in the parameter space and select parameters for the next set of runs based on the objectives of the previous runs.
To prepare the model for optimization, we need to finish creating formal metrics first.
We will use elements of the Statistics palette to automatically collect samples of data during the simulation run and generate the aggregated information: mean, minimum, or maximum.
To create metrics
- Switch to the Main agent type.
-
From the Analysis palette, add the Statistics element.
Set its properties to the following:
Name: statsRetailerStock
Continuous
Value: retailer.stock -
Hold Ctrl, then drag and drop the Statistics element on the diagram to create a copy.
Set its properties to the following:
Name: statsOutOfOil
Continuous
Value: oilChangeStations.nOutOfOil() -
From the same Analysis palette, add the Output element.
Set its properties to the following:
Name: meanRetailerStock
Value: statsRetailerStock.mean() -
Hold Ctrl, then drag and drop the Output element on the diagram to create a copy.
Set its properties to the following:
Name: maxPercentOutOfOil
Value: statsOutOfOil.max() / 500
Both output values are calculated at the end of a simulation run (as seen is the properties of the Output element). Therefore, they will get the last available statistics values covering the entire simulated period. And we will use these metrics in the optimization experiment.
Now, when we have all parameters and metrics set up, let us configure the optimization experiment.
To set up the experiment
- Open the drop-down list next to the Run button and select Open Experiments. This will compile the model and take you to the AnyLogic Cloud execution environment. Initially you will see the Simulation experiment and the input parameters.
- Click New experiment.
- Enter the name of the experiment: Optimization.
- Select Experiment type: Optimization.
- Click Add.
-
Next, set up the optimization inputs.
Click the gear icon next to the newly created Optimization experiment to open the dashboard editor. - Set the control type of the Smin and Smax parameters to Discrete range.
- Make the Stop time input visible, it will be useful for optimization. Make the Max percent out of oil value visible in Requirements.
-
Finally, let’s set up the optimization outputs.
Scroll down the dashboard and click Add output. - In the new output, select the Single value type, click Select input, and select Smin. It may seem strange to set up inputs in the Outputs section, but in the case of the optimization experiment, the optimal inputs are exactly the desired result of the simulation run.
- Save the dashboard.
The optimization experiment is performed using AnyLogic Cloud.
To start the experiment
-
Set the ranges and the steps:
Smax: 100..500, step 10
Smin: 0..400, step 10 - Set the Objective to Mean retailer stock: Minimize.
- Set the Number of iterations: 200.
- Set the requirement that Max percent out of oil is less than or equal to 0.01. Having Retailer stock as the objective and % out of oil as a requirement is natural for our problem: as the retailer, we want the stock to be as low as possible, while for the quality of service we have a hard upper bound of 1%. If we also wanted to minimize the % out of oil, we would have created a weighted sum objective function.
- Run the Optimization experiment and watch its progress.
- When the optimization is complete, you will see the results. They may differ from those shown in the figure. These results correspond to the simulation run that generates the best objective and is feasible, that is, satisfies the requirements.
With the results visible in the outputs you created, you can enter them as parameters to the simulation experiment and verify their feasibility.
However, there is no need to go to another experiment: you can perform a single run of a simulation experiment right from the Optimization experiment screen. Staying in the Optimization experiment, click the Play button: the animated run is displayed in the dialog.
You can manually adjust the Smax and Smin parameters to the feasible values and see how this affects the simulation.
-
How can we improve this article?
-