Anylogic:读取Excel单元格的值以定义动态参数

huangapple go评论133阅读模式
英文:

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

  1. 除了直接将代码写入参数的“默认值”中,将其设置为任意数字,并在其他地方设置值。例如,在代理的“启动时:”操作中写入myParameter = excel_spreadsheet.getCellNumericValue(1, row_index, 6);
  2. 如果不需要参数的特殊功能,请使用变量而不是参数。

编辑:这只解决了启动时的错误。当row_index更改时,您还需要手动更新参数/变量的值。

英文:

I found two solutions

  1. 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.
  2. 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

huangapple
  • 本文由 发表于 2023年7月10日 17:09:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76652287.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定