【问题标题】:Streamline agent behavior in NetLogo简化 NetLogo 中的代理行为
【发布时间】: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


【解决方案1】:

我没看懂你的代码,但这是一种做你想做的事的方法,我不确定代理在害怕或谨慎移动时应该如何表现,但你可以很容易地改变这些:

Breed [predators predator]
Breed [Humans Human]
Breed [Preys Prey]

turtles-own [
  wary
  scared
]


to setup
  Clear-all
  Create-humans 5 [Set color orange set shape "person" move-to patch random 30 random 30]
  Create-Preys 5[Set color white Set shape "Sheep" move-to patch random 30 random 30]
  Create-predators 5 [set color red Set shape "wolf" move-to patch random 30 random 30]
  ask turtles
  [set Wary false
    Set Scared False
  ]
  reset-ticks
end


to go
  ask turtles
  [rt random 5
    fd 0.3]
  avoid-people
  tick
end

to avoid-people
  ifelse is-day?
  [
    ask predators 

    [ if humans-near?
      [
        set wary true
        if humans-too-near? [Set Scared true]
        set label  (word wary "," Scared )
      ]
    ]
    Ask Preys 
    [ if humans-near?
      [
        set wary true
        if humans-too-near? [Set Scared true]
        set label  (word wary "," Scared )
      ]
    ]


  ]


  [; what they should do when its night time
    ] 



end 

to-report humans-too-near?
  report any? humans in-radius 2
end


to-report humans-near?

  report any? humans in-radius 5
end

to-report is-day?
  report (ticks mod 24 >= 5 and ticks mod 24 < 18)
end

*更新:

您的问题在于彼此之间有 2 个问题,我很高兴您的模型现在运行得更快。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多