英文:
Anylogic: reading excel cells value for dynamic parameters definition
问题
大家好,
这是我的问题。
我正在创建一个Anylogic模型,试图使其尽可能灵活。这意味着我正在直接从Excel电子表格中提取一些时间值。
为了创建一个延迟循环,每次都会逐行更改其值,我创建了一个参数和一个变量,它们的工作方式如下:
row_index(变量)的初始值为4
参数的默认值为- excel_spreadsheet.getCellNumericValue("Sp_A", row_index, 6)
但是,一旦我运行我的模拟,就会发生以下情况:
第0行(基于1的索引)不存在
我的目标是每当延迟结束时更新row_index,依此类推。
我尝试在启动模拟后更新参数值(从零开始),例如在队列的进入时,但我得到了另一个错误。
我该如何解决这个问题?
非常感谢大家的帮助,
Ale
英文:
Cheers Everyone,
here is my problem.
I'm creating an Anylogic model trying to make it as flexible as possible. This means that I'm feeding some time values directly from an Excel spreadsheet.
In order to create a delay loop that changes its value every time by going row by row, I created a parameter and a variable that work like this:
row_index (variable) with initial value 4
parameter with default value - excel_spreadsheet.getCellNumericValue("Sp_A", row_index, 6)
But as soon as I run my simulation this happens:
The row #0 (1-based) does not exist
My goal is to update the row_index every time that my delay is over and so on.
I tried to update the parameter value (starting from zero) after starting the simulation (for example on the on enter of a queue) but I got another error.
How can I solve this issue?
Thank you all in advance,
Ale
答案1
得分: 1
- 除了直接将代码写入参数的“默认值”中,将其设置为任意数字,并在其他地方设置值。例如,在代理的“启动时:”操作中写入
myParameter = excel_spreadsheet.getCellNumericValue(1, row_index, 6);
。 - 如果不需要参数的特殊功能,请使用变量而不是参数。
编辑:这只解决了启动时的错误。当row_index更改时,您还需要手动更新参数/变量的值。
英文:
I found two solutions
- Instead of writing the code directly to the 'Default value' of your parameter, set it to an arbitrary number and set the value somewhere else. For example write
myParameter = excel_spreadsheet.getCellNumericValue(1, row_index, 6);
in the 'On startup:' action of the agent. - Use a Variable instead of a Parameter (if you don't need the special capabilities of parameters).
EDIT: This only solves the error on startup. You need to manually update the parameter/variable value too when the row_index is changed
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论