简体   繁体   English

Anylogic为模拟实验的每次迭代导入新的Excel文件-anylogic帮助代码不起作用

[英]Anylogic import new Excel file for each iteration of a simulation experiment - anylogic help code does not work

In my anylogic model my agents receive their parameters from a database table, which is based on an Excel file.在我的 anylogic 模型中,我的代理从基于 Excel 文件的数据库表中接收参数。 In the Excel file, each cell has its own code stored, so each time I open the file, the cell values change.在 Excel 文件中,每个单元格都存储了自己的代码,因此每次打开文件时,单元格的值都会发生变化。

I would like to have that with each automatic run of my model the Excel file is read in again as the database table (ie the parameter values of the agents change).我希望每次自动运行我的模型时,Excel 文件都会作为数据库表再次读入(即代理的参数值发生变化)。 In the " Parameter Variation Experiment " I entered this code under " after iteration ":在“参数变化实验”中,我在“迭代后”下输入了这段代码:

String tempString = excelFile_DatabasisLinks.getCellStringValue(1, rowCounter, 1);
ModelDatabase modelDB = getEngine().getModelDatabase();
Database myNewFile = new Database(this, "rohdaten2", tempString);
modelDB.importFromExternalDB(myNewFile.getConnection(), "Rohdaten", "rohdaten", true, false);
rowCounter += 1;

I have the code form this anylogic help page.我有这个anylogic帮助页面的代码。 Using a variable to be able to change the path of the file (ie the file) seems to work (anylogic doesn't throw an error).使用变量能够更改文件(即文件)的路径似乎有效(anylogic 不会引发错误)。

In the currently used dummy model, the agents receive their parameters at the source.在当前使用的虚拟模型中,代理从源头接收它们的参数。
At the sink, the parameter values are written via collections into another excel (results) file.在接收器,参数值通过集合写入另一个 excel(结果)文件。

I put obvious pattern into my data files, to see if the data changes, but I always receive the same excel file in my results file.我将明显的模式放入我的数据文件中,以查看数据是否更改,但我总是在我的结果文件中收到相同的 excel 文件。
I read that anylogic copies the excel tables to its temporary files to make simulation runs faster.我读到 anylogic 将 excel 表复制到其临时文件中,以使模拟运行得更快。 I hoped the code above would be a workaround, but it is not.我希望上面的代码是一种解决方法,但事实并非如此。
I'm grateful for any suggestions how to make this work!我很感激任何建议如何使这项工作!

I could not find out what is wrong with the above code or how to get it work.我找不到上面的代码有什么问题或如何让它工作。
However, I found a workaround using the "excelFile "-Block.但是,我找到了使用“excelFile”-Block 的解决方法。
In the main agent (the agent where all other agents live) in the agent actions in "on startup":在“启动时”的代理操作中的主代理(所有其他代理所在的代理)中:

excelFile.readFile();

ensures that the excel file is updated before each run.确保在每次运行之前更新 excel 文件。 The parameters are added via参数通过添加

agent.set_<parametername>(excelFile.getCellBooleanValue( sheet number, row number, column number)

"on exit" in the source.源中的“退出时”。
I hope this helps everyone with a similar problem.我希望这可以帮助每个有类似问题的人。

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

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