2013-12-12 2 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와 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)는 서로 내부에 물어 가지고 있었다, 나는 그들이 두려워하거나 경계로 이동하면 에이전트가 작동해야하지만, 쉽게이를 변경하는 방법을 확실하지 이제 귀하의 모델이 더 빨리 실행됩니다.