【发布时间】:2013-12-12 05:10:34
【问题描述】:
我试图在 NetLogo 中模拟从人类代理中避免动物代理。首先,我要求一个捕食者避免使用“警惕”和“害怕”这两种行为的人。这很好用。但后来我要求猎物(现在有 168 只,但可能更多)做同样的事情,模型已经放慢到蜗牛的速度。由于我对 NetLogo 还很陌生,我确信有一种更有效的方法来编码这种行为。有关如何简化此过程的任何建议?我确信有更好的方法来做到这一点。谢谢!
to avoid-people ;; test if people too close to predator and prey and animals moves away if is.
ask predator [
ifelse ticks mod 24 >= 5 and ticks mod 24 < 18 [ ;makes sure the animals respond to people during the daytime
humans-near
ifelse any? wary
[ fd 0 ]
[ ]
humans-too-near
if any? scared
[run-away]
] [set wary 0 set scared 0]]
ask preys [
ifelse ticks mod 24 >= 5 and ticks mod 24 < 18 [
humans-near
ifelse any? wary
[ fd 0 ]
[ ]
humans-too-near
if any? scared
[run-away]
] [set wary 0 set scared 0]]
end
;;Humans-near 和humans-too-near 是函数 ;;警报距离和飞行起始距离是捕食者的滑块,但是猎物的设定值
to humans-near ;;adds all humans in alert-distance radius of animal to an agent subset for that agent.
ask predator [
set wary humans in-radius alert-distance]
ask preys [
set wary humans in-radius 10]
end
to humans-too-near ;;adds all humans in flight-initiation-distance radius of animal to an agent subset for that agent.
ask predator [
set scared humans in-radius flight-initiation-distance]
ask preys [
set scared humans in-radius 5]
end
to run-away ;;Make animal avoid the human closest to it.
set nearest-human min-one-of scared [distance myself]
turn-away ([heading] of nearest-human) max-separate-turn
end
;;这使动物保持在热带森林中,远离人类居住区。
;;Max-separate-turn 是一个滑块,指示捕食者逃离人类的角度
to turn-away [new-heading max-turn]
turn-at-most (subtract-headings heading new-heading) max-turn
ifelse [habitat = typeTrop] of patch-ahead run-distance
[fd run-distance] [turn-away ([heading] of nearest-human) max-separate-turn]
end
to turn-at-most [turn max-turn]
ifelse abs turn > max-turn
[ ifelse turn > 0
[ rt max-turn ]
[ lt max-turn ] ]
[ rt turn ]
end
【问题讨论】:
-
如果您可以发布 Wary 和 Scared 的代码并发布耗时过长的代码(用户分析器扩展),我们或许可以为您提供更好的帮助
-
我不明白如果Wary是一个函数,你怎么设置它?这些是代理的属性吗?
-
这是一门很好的复杂性科学课程,它使用了 netlogo,complexityexplorer.org/online-courses/3/segments/1028
-
我添加了代码以澄清功能。当我添加
ask preys [set wary humans in-radius 10]和ask preys [set scared humans in-radius 5]时,模型变慢了。我猜是因为每只猎物都被要求在每一个滴答声中完成每个功能? -
尝试像这样改变你的人近和人太近:'到人太近;;将动物的飞行起始距离半径内的所有人类添加到代理子集那个代理人。如果是捕食者? self [在半径飞行起始距离内设置害怕的人类] 如果是猎物? self [在半径 5 内设置受惊的人类] 结束'
标签: netlogo