【问题标题】:How to let only a certain percentage of turtles die every 10 ticks?如何让每 10 刻只有一定比例的海龟死亡?
【发布时间】:2019-05-08 18:12:24
【问题描述】:

在这里尝试了所有适用的解决方案都无济于事后,我仍然想看看是否有人可以帮助我。

我有一种乌龟(性工作者)沿着一个布尔变量 [trust?] 划分,并且希望每 10 次使这两种类型中的一种有一定百分比/一定数量(不是那么重要)退出模型 [死亡]刻度数。

我尝试了以下方法但失败了:

试图让一半退出,但是:杀死全部或大部分,而不是一半。

ask n-of (count sexworkers / 2) sexworkers [ die ]

这个有效,但杀死了太多人。如果任何给定的补丁上有超过 2 名性工作者,那么除了一个之外,所有人都会死。我可以将其设置为百分比吗?

ask patches with [count sexworkers-here >= 2]
[ ask one-of sexworkers-here [ ask other sexworkers-here[die]]
]

这也杀死了每 10 个滴答声对我来说太多了

ask sexworkers with [trust?][ if ticks - birth-tick > 10 [die] ]

;所有信任的性工作者都会在超过 10 个蜱虫时死亡

应该杀死一定的百分比,但由于布尔属性而不是基于数字的属性而缺少报告变量

ask min-n-of (0.5 * count sexworkers with [trust?]) sexworkers with [trust?] [XXXXXXREPORTERXXXX]
[die]

【问题讨论】:

    标签: netlogo die


    【解决方案1】:

    您的第一个代码是正确的。在新模型中试试这个看看:

    to testme
      clear-all
      create-turtles 150 [set color red setxy random-xcor random-ycor]
      print count turtles
      ask n-of (count turtles / 2) turtles [ die ]
      print count turtles
    end
    

    您将问题描述为代码杀死了太多。我怀疑你多次调用它。例如,试试这个版本:

    turtles-own [trust?]
    
    to testme
      clear-all
      create-turtles 150
      [ set color red
        setxy random-xcor random-ycor
        set trust? random-float 1 < 0.1
      ]
      print count turtles
      print count turtles with [trust?]
      ask turtles with [trust?]
      [ ask n-of (count turtles / 2) turtles [ die ]
        print count turtles
      ]
    end
    

    它指定 10% 的海龟具有真正的信任?然后要求每只乌龟杀死一半还活着的乌龟。你做过类似的事情吗?

    【讨论】:

    • 非常感谢!在 ask n-of 之前,我没有将第一个 ask turtles 与 [trust?] 包括在内,就是这样!现在运行顺利!
    • @MiraFey - 如果 JenB 的回答解决了您的问题,请单击他们回答顶部附近的小复选标记,将此问题标记为已关闭。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多