2013-12-12 31 views
2

我試圖在NetLogo中模擬避免來自人類代理的動物代理。首先,我問一個單一的掠奪者避免使用兩種行爲,「謹慎」和「害怕」。這很好。但後來我問獵物動物(現在有168個人,但可能還有更多人)也這樣做,模型已經放慢到蝸牛的速度。由於我對NetLogo相當陌生,我確信有一種更有效的方式來編碼這種行爲。有關如何簡化此過程的任何建議?我相信有更好的方法來做到這一點。謝謝!在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 

;;人類-附近,人類太接近的功能 ;;報警距離和飛行出現距離是捕食者滑塊但獵物設定值

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 

;;這使動物在熱帶森林裏遠離人類居住。
;;馬克斯 - 獨立 - 又是一個滑塊支配的捕食者運行從人

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 
+0

如果您可以發佈Wary and Scared的代碼併發布需要很長時間的代碼(用戶配置文件擴展),我們可能會更好地幫助您 – Marzy

+0

我不明白Wary是一個函數,您如何設置它?這些代理的屬性是? – Marzy

+0

這是一個很好的使用netlogo的複雜性科學課程,http://www.complexityexplorer.org/online-courses/3/segments/1028 – Marzy

回答

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問對方內線,我很高興你的模型現在跑得更快。