制作一个包含时间变量的列表,然后选择其中一个元素

时间:2015-10-13 17:36:10

标签: list variables random netlogo

嗨我正在做一个模型,我需要使用时间变量的值来制作元素列表。这是我用来定义时态变量的代码

to react
  ask  cells
   [
   let Ai1 count turtles with [color = blue and xcor < -13 and ycor > -26] 
   let Ai2 count turtles with [color = blue and xcor < -13 and ycor < -27] 
   let Ai3 count turtles with [color = blue and xcor > -12 and xcor < 11 and ycor > -26]
   let Ai4 count turtles with [color = blue and xcor > -12 and xcor < 11 and ycor < -26]
    let Ai5 count turtles with [color = blue and xcor > 11 and ycor > -26]
    let Ai6 count turtles with [color = blue and xcor > 11 and ycor < -26]
  let Aimax list  (Ai1 Ai2 Ai3 Ai4 Ai5 Ai6)
   set calories (44.5 * random Aimax)
     ]
  end

所以我需要列出Ai1 ... Ai6的值,然后选择ramdomly这6个值中的一个,在下一个时间变量Aimax的乘法中使用它,那么这样做是否可行?如果我使用随机命令,它可以在列表中使用? Tks for reading。

2 个答案:

答案 0 :(得分:1)

one-of会从列表中选择一个随机项:

set calories (44.5 * one-of Aimax)

答案 1 :(得分:0)

不要这样做。您正在让每个单元格计算所有计数,这只需要确定一次。你还重复过滤你的乌龟颜色为蓝色。如果我们坚持你的界限,我们可以写

to-report countblues
  let blues (turtles with [color = blue])
  let counts (list
    count blues with [xcor < -13 and ycor > -26] 
    count blues with [xcor < -13 and ycor < -27] 
    count blues with [xcor > -12 and xcor < 11 and ycor > -26]
    count blues with [xcor > -12 and xcor < 11 and ycor < -26]
    count blues with [xcor > 11 and ycor > -26]
    count blues with [xcor > 11 and ycor < -26]
    )
  report counts
end

to react
  let counts countblues
  ask  cells[
    set calories (44.5 * one-of counts)
  ]
end

请注意,如果您的海龟永远不会改变颜色,您可以将blues转变为全局颜色,尽管这样会有很小的收益,并且每个全球都有参考透明度的成本。