在NetLogo中简化代理行为

在NetLogo中简化代理行为,netlogo,Netlogo,我试图在NetLogo中模拟避免动物代理和人类代理。首先,我让一个捕食者避免人们使用两种行为,“警惕”和“害怕”。这很有效。但后来我要求猎物(目前有168只,但可能更多)也这样做,模型的速度减慢到了蜗牛的速度。由于我对NetLogo还很陌生,我确信有一种更有效的方法来编码这种行为。有没有关于如何简化这一过程的建议?我相信有更好的办法。谢谢 to avoid-people ;; test if people too close to predator and prey and animals mo

我试图在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 
;;这使得这些动物留在热带森林中,远离人类聚居地。
;;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

我不理解你的代码,但这是你想要的一种方式,我不确定如果特工害怕或小心翼翼地移动,他们应该怎么做,但你可以很容易地改变这些:

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
繁殖[捕食者捕食者]
繁殖[人类]
繁殖[捕食]
乌龟自己的[
警惕的
害怕的
]
设置
清除所有
创建人类5[设置颜色橙色设置形状“人”移动到随机补丁30随机30]
创建猎物5[设置颜色白色设置形状“绵羊”移动到随机补丁30随机30]
创建捕食者5[设置颜色红色设置形状“狼”移动到随机补丁30随机30]
问海龟
[将谨慎设置为false
设错
]
重置滴答声
结束
外带
问海龟
[rt随机5
fd 0.3]
避人
打上钩
结束
避人耳目
还有什么是白天吗?
[
询问捕食者
[如果人类靠近?
[
谨小慎微
如果人类离得太近?[设定为真]
设置标签(单词“小心”、“害怕”)
]
]
询问猎物
[如果人类靠近?
[
谨小慎微
如果人类离得太近?[设定为真]
设置标签(单词“小心”、“害怕”)
]
]
]
到了晚上,他们该怎么办
] 
结束
报告人类离得太近?
有报告吗?半径2内的人类
结束
报告附近有人?
有报告吗?半径为5的人类
结束
报到是哪一天?
报告(节拍模式24>=5和节拍模式24<18)
结束
*更新:


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

如果您可以发布Wary and Fear的代码,并发布耗时太长的代码(用户档案器扩展),我们可能可以帮助您做得更好。我不明白Wary是否是一个函数,您如何设置它?这些是代理的属性吗?这是一门很好的复杂性科学课程,它使用了netlogo,我添加了一些代码来澄清函数。当我添加了
询问猎物[在半径10内设置警惕的人类]
询问猎物[在半径5内设置恐惧的人类]
时,模型的速度变慢了。我猜是因为每一只被捕食的动物都被要求在每一个滴答声中完成每一项功能?试着像这样改变你的人类太近和人类太近:'对人类太近;;将动物飞行起始距离半径中的所有人添加到该代理的代理子集。如果是捕食者?self[在半径飞行起始距离内设置受惊吓的人类]是否为猎物?self[设置半径5内的恐惧人类]结束'
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