Netlogo:相同品种变量的值不会相加这些值是通过Levelspace从连接到海龟的模型创建和更新的

问题描述

我目前正在使用Levelspace创建多级ABM。在父模型中,我试图将同一品种的多个海龟的一个变量的值求和(海龟的数量由不同的品种拥有的变量确定)。每只乌龟的变量从通过Levelspace连接的各自子模型中获取其值。

当前,父模型可以从子模型接收值。我编写了一个代码,其中有一个父模型乌龟选择代表子模型的特定乌龟,让这些选定的乌龟不断更新其变量总计(从它们各自的子模型接收),并在每个刻度上显示每个更新的总计。

我的问题是将每个更新的子模型总数汇总为在每个刻度之后更新的父模型中的总数。这是到目前为止的代码

ask turtle 0 [
    if breed = Epics
    [
      let closteams Teams with [AsgnEpic = "Epic 1"]
      foreach sort-on [who] closteams
      [
        the-closeteams -> ask the-closeteams [show reduce + [Value] of the-closeteams]
      ]
    ]
  ]

我在foreach块中添加一个变量,并试图求和,但仅收到0作为输出(请参见下面的代码):

foreach sort-on [who] closteams
      [
        the-closeteams -> ask the-closeteams [show reduce + [Value] of the-closeteams]
        let vartot sum [value] of closteams
      ]

有人可以指导我如何解决此问题吗?

谢谢

鲁迪

   ----------------------------------UPDATED INFO-----------------------------------

该模型具有三个级别,其中包括通过Levelspace扩展连接的几个模型。

顶层是父模型。父模型是使用Extrawidget扩展创建的图形用户界面模型。用户在此父模型中输入信息以自定义模型。该图形用户界面模型通过Levelspace将所有输入的信息发送到第二个模型(第一级子模型)。第二个模型是用户运行模型的地方。

这是第二个模型(第一个子模型)中设置过程的一部分。它创建了史诗和团队(团队通过Levelspace调用了自己的子模型(第二级子模型))

to setup
  ls:reset
  let n length TotEpics
  let horizontal-interval (world-width / n)
  foreach n-values n [ [i] -> i ] [ [i] ->
    create-Epics 1 [
      set label item i TotEpics
      set color item i ColorEpics
      set shape "Box"
      setxy (min-pxcor - 0.5 + horizontal-interval * (0.5 + who)) 15
      set size 8
    ]
  ]
 let o length TN1
  foreach n-values o [ [i] -> i ] [ [i] ->
    create-Teams 1 [
      set label item i TN1
      set color color
      set Members item i TM1
      set AsgnEpic item i Epic1
      set Value []
      set xcor -16
      set ycor 12 + i * -7
      set size 4.5
      ls:create-interactive-models 1 "Problem_Solving.nlogo"
      set model-id last ls:models
      ls:hide model-id
    ]
  ask Teams [
    if AsgnEpic = "Epic 1" [
      create-link-with epic 0
      set xcor [xcor] of epic 0
      set ycor [ycor - 8] of epic 0
      set color blue ]
      while [any? other turtles-here] [if can-move? 2 [set heading 180 fd 5 set 
      color blue + 2]]
    if model-id = 0
      [
      ls:let name label
      ls:let mem Members
      ls:let AE AsgnEpic
    ls:ask 0 [
      set Number-of-Agents mem
      set Epic AE
      setup ]
    ]
    if model-id = 1
      [
      ls:let name label
      ls:let mem Members
      ls:let AE AsgnEpic
    ls:ask 1 [
      set Number-of-Agents mem
      set Epic AE
      setup ]
    ]
     ;this is repeated several times with the model-id number and ask number 
     ;increasing incrementally to accommodate multiple teams
  ]
reset-ticks

end

设置过程中没有“全部清除”,因为“全部清除”清除了从“图形用户界面”父模型收到的所有信息。

下面是运行过程的一部分,该过程运行模型并从各自的子模型中收集Teams“ Value”变量的输入:

to go
ask Teams
    [
    if model-id = 0 [ls:ask 0 [go] set Value lput [average-score] ls:of 0 Value
     ]
    if model-id = 1 [ls:ask 1 [go] set Value lput [average-score] ls:of 1 Value
     ]
    ;this is repeated several times with the model-id number increasing 
    ;incrementally to accommodate multiple teams
]
Value-of-Stories1
tick
end

因此,每个团队的“ Value”变量从一个单独的Levelspace连接的子模型“ average-score全局变量接收其值。然后,我用下面的代码对每个滴答滴答输入的每个团队的总价值求和。

to Value-of-Stories1
ask turtle 0 [
    if breed = Epics
    [
      let closteams Teams with [AsgnEpic = "Epic 1"]
      foreach sort-on [who] closteams
      [
        the-closeteams -> ask the-closeteams [show reduce + [Value] of the- 
        closeteams]
      ]
    ]
  ]
end

将各个团队的“价值”合计为一个数字是一个挑战。 还有更多代码,但我相信这是与我要解决的问题有关的代码

谢谢

鲁迪

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)