本文介绍了代理集中变量值的概率,netlogo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use probability to assign [0] or [1] individual values for a turtles-own variable in NetLogo, but have only found ways of printing or reporting probability outputs rather than using them to determine a variable value.

示例:

我要让两只乌龟检查它们是否要彼此交换信息,并分配了一个变量exchangeinfo.如果exchangeinfo = 0,则不会发生任何信息交换.如果exchangeinfo = 1,则发生信息交换.

I am asking two turtles to check whether they each want to exchange information with each other, and have assigned a variable exchangeinfo. If exchangeinfo = 0, then no information exchange happens. If exchangeinfo = 1, then information exchange occurs.

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

Currently I've hard-coded [set exchangeinfo 1] as a placeholder.

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

But I'd like each turtle to have a 25% chance of exchangeinfo = 1, but I do not want to set variables one at a time.

有什么建议吗?

推荐答案

@Alan的评论将起作用.这是一个超级简单的模型,可以满足我的要求.

@Alan's comment will work. Here is a super simple model that will do what I think you're asking.

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]]

也是

这篇关于代理集中变量值的概率,netlogo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 20:13