简体   繁体   中英

Reading Parameters row by row from excel for Anylogic Experiment

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.

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.

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.

在此处输入图片说明

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

在此处输入图片说明

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()

在此处输入图片说明

The excel file has some simple data in

在此处输入图片说明

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

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM