代理集中变量值的概率,netlogo

probability for variable value in agentsets, netlogo

我正在尝试使用概率为 NetLogo 中的海龟拥有的变量分配 [0] 或 [1] 个单独的值,但只找到了打印或报告概率输出的方法,而不是使用它们来确定变量值。

示例:

我要求两只海龟检查它们是否要互相交换信息,并且已经分配了一个变量exchangeinfo。如果 exchangeinfo = 0,则不会发生信息交换。如果exchangeinfo = 1,则发生信息交换。

目前我已将 [set exchangeinfo 1] 硬编码为占位符。

但我希望每只乌龟都有 25% 的机会 exchangeinfo = 1,但我不想一次设置一个变量。

有什么建议吗?

@Alan 的评论有效。这是一个超级简单的模型,可以满足您的要求。

turtles-own[exchangeinfo]

to setup
  clear-all
  reset-ticks
  make_turtles
end

to go
  move
  tick
  if (ticks = 1) [inspect turtle 1]
end

to make_turtles
  create-turtles 10
  ask turtles
  [
    set color pink
    set size 2
    set xcor random max-pxcor
    set ycor random max-pycor
    set exchangeinfo 0
  ]
end

to move

  ask turtles
  [right random-float 270
    forward random-float 3
    if ((count (turtles in-radius 2)) > 0)
    [move-to one-of turtles in-radius 2]

  ]

  encounter ;<- this is the function that will decide whether or not to exchange info.

end

to encounter
  ask turtles[
    if (count turtles-here > 0)
    [ifelse (random-float 1 < 0.25)  ;note this is essentially @Alan's answer
      [set exchangeinfo 1]
      [set exchangeinfo 0]
    ]
  ]
end

我假设你会想要某种

ask turtles-here [if (exchangeinfo = 1) [do stuff]]

还有