【问题标题】:probability for variable value in agentsets, netlogo代理集中变量值的概率,netlogo
【发布时间】:2016-11-29 15:56:51
【问题描述】:

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

例子:

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

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

但我希望每只海龟都有 25% 的机会交换信息 = 1,但我不想一次设置一个变量。

有什么建议吗?

【问题讨论】:

  • ask turtles [if (random-float 1 < 0.25) [set exchangeinfo 1]]

标签: attributes probability netlogo


【解决方案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]]

还有

【讨论】:

    猜你喜欢
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2014-04-24
    • 2021-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多