【问题标题】:Create a variable to count from 1 to n in AnyLogic在 AnyLogic 中创建一个从 1 计数到 n 的变量
【发布时间】:2021-07-31 23:03:12
【问题描述】:

我希望在 AnyLogic 中添加一个变量以每小时从 1 计数到 217,以便用作设置参数行引用的选择条件。

我假设我需要使用事件或状态图,但是我真的很想知道确切的内容并且在网上找不到任何东西。

如果您有任何建议,请告诉我,任何帮助将不胜感激

谢谢你, 塔什

【问题讨论】:

    标签: variables parameters count anylogic


    【解决方案1】:

    在这种情况下不需要状态机,因为这可以通过计算或定时事件来实现。 AnyLogic 有time() 函数,它以模型时间测量单位的形式将模型启动后的时间返回为 double

    例如:如果模型时间单位是 seconds 并且它已经运行了 2 小时 2 分 10 秒,那么 time(SECOND) 将返回 7330.0(它总是一个 double价值)。一小时的 1/217 对应于大约 3600/217 = 16.58 秒。此外,java 有一个方便的函数 Math.floor() 向下舍入 double 值,所以 Math.floor(8.37) = 8.0.

    组装起来:

       // how many full hours have elapsed from the start of the model
       double fullHrsFromStart = Math.floor(time(HOUR));
       // how many seconds have elapsed in the current model hour
       double secondsInCurrentHour = time(SECOND) - fullHrsFromStart * 3600.0;
       // how many full 16.58 (1/217th of an hour) intervals have elapsed
       int fullIntervals = (int)(secondsInCurrentHour / 16.58);
    

    这可以打包成一个函数随时调用,速度非常快。

    或者:可以创建一个 Event,它每 16.58 秒将一些 count 增加 1,当计数达到 217 时,将其重置为 0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-20
      • 2023-03-13
      • 2022-01-18
      • 1970-01-01
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      相关资源
      最近更新 更多