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

Netlogo:相同品种变量的值不会求和。这些值是通过Levelspace从连接到turtles的模型创建和更新的,netlogo,Netlogo,我目前正在使用Levelspace创建一个多级ABM。在父模型中,我试图对同一品种的多只海龟的一个变量的值求和。海龟的数量由不同品种自己的变量决定。每个turtle的变量从通过Levelspace连接的各自子模型接收其值 当前,父模型可以从子模型接收值。我已经编写了一个代码,让父模型海龟选择代表子模型的特定海龟,让那些被选择的海龟不断更新从各自子模型收到的变量总数,并在每个刻度处显示每个更新的总数 我的问题是将每个更新的子模型总数相加为父模型中的一个总数,该父模型在每次勾选后更新。以下是迄今为止

我目前正在使用Levelspace创建一个多级ABM。在父模型中,我试图对同一品种的多只海龟的一个变量的值求和。海龟的数量由不同品种自己的变量决定。每个turtle的变量从通过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
      ]
有谁能指导我如何解决这个问题吗

谢谢

鲁迪

该模型有三个级别,由几个通过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
设置过程中没有“全部清除”,因为“全部清除”会清除从图形用户界面父模型接收到的所有信息

以下是go过程的一部分,该部分运行模型并从各自的子模型中收集Team 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
因此,每个团队的值变量从单独的Levelspace连接的子模型平均分数全局变量接收其值。然后,我用下面的代码对每个团队输入的每个勾号的值的总和进行求和

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
将各个团队的价值总和合计为一个数字是一项挑战。 还有更多的代码,但我相信这是与我试图解决的问题相关的代码

谢谢


鲁迪

当我建议你问一个新问题时,我还问了levelspace代码,因为它似乎在那里断裂。您有求和的代码,但它无法正确检索输入。如果您在没有levelspace的情况下运行此代码,并且变量值中有一些数字,那么它是否有效?将levelspace代码添加到原始问题中。当我建议您提出新问题时,我也要求使用levelspace代码,因为它似乎在哪里中断。您有求和的代码,但它无法正确检索输入。如果您在没有levelspace的情况下运行此代码,并且变量值中有一些数字,那么它是否有效?将levelspace代码添加到原始问题中。
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