Search code examples
anylogic

How to export statistics_log data to excel after Parameters Variation AnyLogic


After running Parameters Variation, how can I export the statistics_log data (or dataset if better practice) to excel?


Solution

  • Add an Excel File element in your Parameter Variation experiment window and add a variable of type int with initial value of 0.

    enter image description here

    Then let's say you want to export a dataset for each run, write the following code in After simulation run: field:

    excelFile.writeDataSet(root.dataset, 1, 1, column*2 + 1);
    column++;
    

    A dataset takes two columns, this is why you need to multiply column by 2 in the code to avoid overwriting of previous data.

    On the other hand, if you want to export a single value, such as mean duration, use the following code:

    excelFile.setCellValue(root.mean, 1, 1, row + 1);
    row++;
    

    The row and column method is not set in stone, you can add the data vertically, horizontally or any other way, just get familiar with how Excel functions work (i.e. writeDataSet and setCellValue and similar).

    Also in the example above mean is assumed to be a variable. You can replace it with any other code that returns a single value such as statistics.mean().