首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NetLogo中的流线型代理行为

NetLogo中的流线型代理行为
EN

Stack Overflow用户
提问于 2013-12-12 05:10:34
回答 1查看 278关注 0票数 2

我试图在NetLogo中模拟动物代理从人类代理中回避的行为。首先,我要求一个捕食者避免使用两种行为,“谨慎”和“害怕”。这个效果很好。但后来,我要求猎物动物(现在有168只,但可能更多)也这样做,模型已经放慢到蜗牛的速度。由于我对NetLogo非常陌生,所以我确信有一种更有效的方法来编写这种行为。关于如何简化这一过程,有什么建议吗?我肯定还有更好的办法。谢谢!

代码语言:javascript
复制
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 

人类近距离和人太近是函数;警报距离和飞行起始距离是捕食者的滑块,但是被捕食者设定的值。

代码语言:javascript
复制
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

这使动物远离人类聚居在热带森林中。

最大分离转弯是一个滑块,指示捕食者逃离人类的角度。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-13 00:46:33

我不理解您的代码,但这是您想要做的一种方法,我不知道如果代理害怕或行动谨慎,应该如何操作,但您可以很容易地更改这些代码:

代码语言:javascript
复制
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

*最新情况:

你的问题是在有两个问内对方,我很高兴你的模型现在运行得更快。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20535526

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档