简体   繁体   English

从 Excel 中逐行读取参数用于 Anylogic 实验

[英]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.我想运行一个Anylogic参数实验,并且我希望从excel文件中连续读取参数,以便excel数据的每一行对应一次运行的参数。 Likewise I want it to run as many times as rows of parameters in excel.同样,我希望它运行的次数与 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.我可以使用 ExcelControlName.getCellNumericValue("ExcelSheetName", RowNumber, ColNumber) 读取一行数据,但是如何设置它以便它通过运行所有行的参数自动运行多次。

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>在您的模拟模型中,创建一个名为row的参数,这将是您的参数变化实验中发生变化的唯一参数...然后您将模拟中的参数转换为变量,每个变量将按如下方式读取 excel 文件>

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.其中 row 是在您的参数变化实验中发生变化的参数,colNumber 是表示您要评估的特定变量的列。

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()然后在实验中,我有一个 Excel 对象,一个链接到 main 参数的变量,以及一个只调用run()的按钮

在此处输入图片说明

The excel file has some simple data in excel文件中有一些简单的数据

在此处输入图片说明

Now on the experiment's Java section you only need to add the following code.现在在实验的 Java 部分,您只需要添加以下代码。

在此处输入图片说明

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.这可确保根据运行计数使用正确的数据更新变量,并且当您停止模型时,如果 Excel 工作表中有更多值要加载,它将再次调用运行函数。

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()请注意,Excel 中的行索引从 1 开始,并且我们有一个数据标题,因此我们希望从第 2 行开始,因此我添加了2 + getExperiment().getRunCount()

If you run this simple model you will see in the Console printed out the values from the Excel file.如果您运行这个简单的模型,您将在控制台中看到打印出 Excel 文件中的值。

10.0
20.0
30.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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