在尝试了所有适用的解决方案后,我仍然想看看是否有人能帮我。
我有一种类型的海龟(性工作者(,沿着布尔变量[trust?]划分,并希望使两种类型之一的某个百分比/某个数量(不那么重要(每10次退出模型[die]。
我尝试了以下操作,但失败了:
试图让一半退出,但是:杀死全部或大部分,而不是一半:
ask n-of (count sexworkers / 2) sexworkers [ die ]
这一个有效,但杀死了太多人。如果任何一个补丁上有两个以上的性工作者,除一个外,其他人都会死亡。我可以将其设置为百分比吗
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]
您的第一个代码是正确的。在一个新的模型中试试看:
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%的海龟拥有真正的信任?然后要求每只海龟杀死一半还活着的海龟。你做了那样的事吗?