Home > database >  Reading Parameters row by row from excel for Anylogic Experiment
Reading Parameters row by row from excel for Anylogic Experiment

Time:10-14

I want to run an Anylogic Parameter experiment, and I want the parameters to be read continuously from an excel file such that each row of excel data corresponds to parameters of one run. Likewise I want it to run as many times as rows of parameters in excel. I am able to read one row data using ExcelControlName.getCellNumericValue("ExcelSheetName", RowNumber, ColNumber) but how do I set it up such that it automatically runs multiple times by running parameters from all rows.

CodePudding user response:

in your simulation model, create a parameter called row, and this will be the ONLY parameter that changes in your parameter variation experiment... then you will transform your parameters in your simulation to variables, and each variable will read the excel file as follows>

ExcelControlName.getCellNumericValue("ExcelSheetName", row, ColNumber)

where row, is the parameter that changes in your parameter variation experiment, and colNumber is the column representing the particular variable that you want to assess.

CodePudding user response:

A very useful question.

One option is to make use of the Simulation Object and not let the model skip the experiment and run the model.

enter image description here

This will just give you some more control over your model execution and you can use some of the before and after simulation run code.

Image the following super-simple model

enter image description here

I have a single parameter and an event that traces the parameter and then stops the simulation.

Then on Experiment I have an Excel object, and a variable that is linked to the parameters on main, and a button that just calls run()

enter image description here

The excel file has some simple data in

enter image description here

Now on the experiment's Java section you only need to add the following code.

enter image description here

This ensures that the variable is updated with the correct data based on the run count, and that when you stop the model it will call the run function again if there is more values in the Excel sheet to load.

Note that the row index in Excel starts at 1 and that we have a header for our data so we want to start at row 2, hence I added 2 getExperiment().getRunCount()

If you run this simple model you will see in the Console printed out the values from the Excel file.

10.0
20.0
30.0
  • Related