2016-10-18 3 views
2

"Railsback & Grimm 2012"를 사용하여 Netlogo에서 ABM을 만드는 방법을 가르쳐 왔습니다. "가상"회랑 다음에 나비에 관한 문제가 있습니다. 기본 아이디어는 나비가 높이 차이를 가이드로 사용하여 교합을 위해 오르막길로 이동한다는 것입니다. 나비가 사용하는 패치의 수를 나비가 시작 패치에서 최종 패치로 날아가는 평균 거리 이상으로 나누는 복도의 폭을 계산해야합니다.Netlogo : 시작 패치와 종료 패치 사이의 평균 거리 측정

plot corridor-width 

내가 오류 메시지가 읽

to-report corridor-width 

    let patches-visited count patches with [used?] 
    let mean-distance mean [distance start-patch] of turtles 
    report patches-visited/mean-distance 

내가 다음 명령을 사용하여 인터페이스의 플롯을 만들어 : 나는 내가 이런 식으로 코딩하고이 복도의 폭을 세우고 고민하고 있습니다 :

0으로 나눕니다. 오류 관찰자가 실행하는 동안/버튼 '설정'내가 믿는

에 의해 호출 플롯 '복도 폭'펜 '기본'갱신 절차 설정에 의해 호출 코드에 의해 호출 된 프로 시저 CORRIDOR 폭에 의해 호출에 문제가있다 방법을 코딩 오전 distance start-patch하지만 웹 서핑을하고 여러 코드를 보았고 내 실수를 발견 할 수 없습니다. 내 전체 코드는 다음과 같습니다.

globals [ q ]     ;; q is the probability that butterfly moves directly to highest patch 
turtles-own [ start-patch ] 
patches-own [ elevation used? ]  ;; patches property of elevation and whether the patch has been used by butterfly or not. 

to setup 
    ca 

    ;; Let's create patches and asign them an elevation and color by using ask patches statement 

    ask patches 

    [ 
    ;; Elevation decreases linearly with distance from the center of hills. Hills are at (30,30) and 
    ;; (120,120) coordinates. The first hill is 100 units high whereas the second one is 50 
    let elev1 100 - distancexy 30 30 
    let elev2 50 - distancexy 120 100 

    ifelse elev1 > elev2 
    [ set elevation elev1 ] 
    [ set elevation elev2 ] 

    set pcolor scale-color green elevation 0 100 

    set used? false 
    ] 

    ;; Create 50 butterflies 

    crt 50 

    ask turtles [ 

    set size 6 

    ;; set their initial location as their initial patch 

    setxy random-pxcor random-pycor 

    set start-patch patch-here 


    ;; have the butterfly draw its path with the pen-down statement 
    pen-down 
] 

    reset-ticks 

    ;; Initialize the q parameter 
    set q 0.4 

end 

;; The master schedule 

to go 

    ask turtles [ move ] 
    plot corridor-width 
    tick 
    if ticks >= 1000 

    [ 
    let final-corridor-width corridor-width 
    write "Corridor width: " print final-corridor-width 
    ;export-plot "Corridor width" (word "Corridor-width-output-for-q-" q ".csv") 
    stop 

    ] 

end 

;; let's code the butterfly procedure of movement 

to move 

    if elevation >= 
    [ elevation ] of max-one-of neighbors [ elevation ] 
    [ stop ] 

    ifelse random-float 1 < q    ;; Decide whether to move to the highest sorrounding 
              ;; patch with p=q 

    [ uphill elevation ]      ;; move deterministically uphill 
    [ move-to one-of neighbors ]    ;; or move randomly 

    set used? true 

end 

to-report corridor-width 

    let patches-visited count patches with [used?] 
    let mean-distance mean [distance start-patch] of turtles 
    report patches-visited/mean-distance 

end 

답변

1

평균 거리가 0 일 때 어떻게됩니까?

let mean-distance mean [distance start-patch] of turtles 

기본적으로 설치시 모든 거북이의 시작 패치를 현재 패치로 설정합니다. 따라서 모든 거북이가 출발점으로부터 얼마나 멀리 떨어져 있는지 물어 보면 0 단위 멀리 떨어져 있습니다.

따라서 [distance start-patch] of turtles은 모두 0의 목록으로 채워집니다.

따라서 모든 0의 목록의 평균은 0이며 0으로 나누기 오류가 발생합니다.

아마이 상황에서, 당신은 내 실수가 무엇인지 설명 주셔서 감사합니다 @matttsap 그래서

ifelse mean-distance = 0 
[ report 0] 
[report patches-visited/mean-distance] 
+0

... 대신 0을보고 싶다. 내 거북이가 실제로 움직이기 때문에 시작과 끝 패치 사이의 어떤 거리에서도 0이 없어야합니다. 내가 코딩하려고 시도한 것은 매 실행 후 내 거북이의 시작과 끝 패치 사이의 평균 거리를 얻는 것이 었습니다. 이 목적을 위해 코드를 수정해야하는 방법에 대해 조언 해 주실 수 있습니까? – AnnK

+0

요점은 모든 틱 (문제가 발생한 지점의 시작 부분 포함)에서 평균 거리를 계산한다는 것입니다. 단일 지점 만 원한다면 매틱마다 평균 거리를 표시하지 않고 대신에 시뮬레이션에 대한 정지 기준을 정의하고 중지 기준 [show corridor-width] 또는 무언가 이것과 비슷합니다. – mattsap