My model is running a parameter variation experiment for an external optimization problem. I have to export the output of each experiment replication to Excel. I was using a function that is triggered at On destroy:
in the main agent and then using the following code for each output value:
ExcelResults.setCellValue(planned_leadtime_1, varExcelSheetName, ActRow, ActColumn++);
Currently, there are around 90 output values for each replication. Unfortunately, this method makes runtime very slow.
Trying to solve the issue, I stored the results of each replication in an ArrayList within the parameter variation experiment in After simulation run:
. Now I would like to transfer this ArrayList directly to Excel in After iteration:
and reset the ArrayList.
Is it possible to transfer the ArrayList directly to Excel without iterating over every value in the list by using setCellValue()
? Or is there another computationally efficient way to transfer the output of the parameter variation experiment to Excel?
To solve the issue I stored the value of each replication in an ArrayList experimentsResults
in the parameter variation experiment. After each iteration, the ArrayList representing an iteration of multiple replications is transferred to a CSV file.
To store the data in an ArrayList a java class was created to represent all the data that needs to be transferred to the list. Then the code below is used in a function that is being triggered in After simulation run:
ReplicationData row = new ReplicationData();
row.experimentDescription = experimentDescription;
row.varCurrentIteration = varCurrentIteration;
experimentResults.add(row);
To write the ArrayList to CSV I used this function that is triggered in After iteration:
for(int j=0; j<experimentResults.size(); j++)
{
String resultstring="";
resultstring = experimentResults.get(j).experimentDescription+";"+
experimentResults.get(j).varCurrentIteration+";"+
csvResults.println(resultstring);
}
csvResults.close();
The main thing that I was not aware of, was to place the Text File from the connectivity pallet directly in the experiment. This improved the writing speed a lot. After the experiment, the CSV file can be easily converted to Excel.