2014-02-19 1 views
1

나는 동물의 영토를 재배하고 있습니다. 동물 영토는 확장 과정에서 다른 동물 영토의 일부를 쪼갤 수 있습니다. 따라서 하나의 인접한 영토가 아닌 두 개 이상의 클러스터 (즉, 연결되지 않은 클러스터)를 포함 할 수 있습니다. 이것은 아래의 모델에서 발생합니다. 영토를 인식하고 영토가 하나의 인접한 클러스터로 유지되도록 셀 클러스터 (또는 단일 연결되지 않은 셀)가 가장 작은 클러스터를 출시하고 싶습니다. 나는 이걸 어디서부터 시작해야할지 모르겠습니다. 어떤 도움이라도 좋을 것입니다.NetLogo가 패치 세트에서 격리 된 패치를 출시합니다.

breed [animals animal] 
breed [homeranges homerange] 

animals-own 
[ 
    Name 
    orig 
    territory 
    food 
    status 
] 

patches-own 
[ 
    owner 
    prey 
] 

to setup 
    clear-all 
    random-seed 2234 
    ask patches 
    [ 
    set owner nobody 
    set prey 2 
    set pcolor scale-color (black) prey 1 4 
    ] 

    let $colors [brown orange violet sky lime] 
    let $Name ["t6" "t7" "t8" "t9" "t10"] 
    let $status [0 0 0 0 5] 
    ask n-of 5 patches 
    [ 
    sprout-animals 1 
    [ 
     set shape "circle" 
     set orig patch-here 
     set territory patch-set orig 
     set status item who $status 
     set size 0.3 + 0.1 * status 
     set color item who $colors 
     set pcolor color 
     set Name item who $Name 
     set owner self 
    ] 
    ] 
    reset-ticks 
end 

to go 
    if all? animals [food >= 350] [ stop ] 
    if ticks = 70 [ stop ] 
    expand 
    tick 
end 

to expand ; animals procedure 

    repeat 10 
    [ 
    ask animals 
    [ 
     let vacant no-patches 
     let subord no-patches 
     let target nobody 
     let new-patches no-patches 
     let status-of-calling-tiger status ; 
     let calling-tiger self ; 

           ; If territory not yet good enough: 
     if food < 500 
     [ 
     ask territory 
     [ 
      ; Add unoccupied neighbor patches as potential targets: 
      set vacant (patch-set vacant neighbors with [owner = nobody]) 

      ; Add occupied neighbor patches as potential targets if their tiger has a lower status than me: 
      set subord (patch-set subord neighbors with [owner != nobody and [status] of owner < status-of-calling-tiger]) 
     ] 

     ask subord [ set pcolor red ] 

             ; Set of all potential targets: 
     set new-patches (patch-set new-patches vacant subord) 

     ; Choose as target the one potential target with highest prey: 
     if any? new-patches 
     [ 
      ask new-patches 
      [ifelse any? vacant 
      [ifelse any? subord 
       [ifelse [prey] of max-one-of vacant [prey] = [prey] of max-one-of subord [prey] 
       [set target max-one-of vacant [prey]] 
       [set target max-one-of new-patches [prey]] 
       ] 
       [set target max-one-of vacant [prey]] 
      ] 
      [set target max-one-of subord [prey]] 
      ] 
      move-to target 
      if-else member? target subord 
      [ set shape "triangle" ] ; so you can see that the target patch was from "subord" 
      [ set shape "circle" ] ; or from "vacant" 
     ] 

     ;ifelse any? target with [owner != nobody] 
     if target != nobody 
     [ 
      ; Add target patch to territory of the current animal: 
      set territory (patch-set territory target) ; this is the territory of the calling tiger 

      let old-owner [owner] of target; this needs to be memorized 

             ; Tell target patch that is has new owner: 
      ask target [ set owner calling-tiger ] 

      ; Tell the original owner of the target patch to remove the target patch from its territory: 
      if old-owner != nobody ; 
      [ 
      ask old-owner 
      [ 
       set territory territory with [ owner != calling-tiger ] 
      ] 
      ] 
     ] 
     set food sum [prey] of territory 
     ] 
    ] 
    ] 

    ask animals 
    [ 
    ask territory 
    [ 
     set pcolor [color] of myself 
     set plabel (word [status] of owner [status] of myself) 
    ] 
    if food < 10 [die] 
    ] 
end 

답변

1

패치 클러스터 예를 들어, NetLogo 모델 라이브러리의 코드 예제 섹션에는 인접한 패치 클러스터를 식별하는 코드가 있습니다. 핵심 코드는 다음과 같습니다.

patches-own [cluster] 

to setup 
    ... 
    ask patches [ set cluster nobody ] 
    ... 
end 

to grow-cluster ;; patch procedure 
    ask neighbors4 with [(cluster = nobody) and 
    (pcolor = [pcolor] of myself)] 
    [ set cluster [cluster] of myself 
    grow-cluster ] 
end 

그러나 나머지 예제도 참조하십시오.

유스 케이스에서는 클러스터를 성장시키기 위해 임의로 "시드"를 배치하는 대신 동물이 서있는 패치에서 클러스터를 성장시키기 시작합니다.

+0

클러스터 예제는 연속적으로 클러스터를 확장하는 데 도움이되지만이 예제에서는 클러스터가 다른 동물에 의해 분리 되었기 때문에 더 이상 인접하지 않음을 인식하고 제거하는 방법을 볼 수 없습니다. 고립 된 부분. 격리 된 부분이 더 작은 클러스터 (즉, 단일 셀뿐만 아니라)이고 따라서 4 개의 빈 이웃을 가지지 않는 예가있을 수있다. 내가 놓친 게 있니? – user2359494

+1

당신은 '성장 클러스터'의 목적을 오해했습니다. 그것은 클러스터를 아무것도 만들지 않습니다. 이미 존재하는 클러스터를 식별합니다 _. 패치 클러스터 예에서 클러스터 경계는 패치 색상으로 결정됩니다. 그러나 클러스터를 하나의 단위로 지정하기 위해, 우리는 연속적인 동일한 색의 패치만을 포함하는 패치 세트를 만들고자합니다. 이것이 바로 '성장 클러스터'입니다. –

+0

나는 "어느 것이 든 세포의 클러스터가 가장 작다"라고 말하지는 않았지만 그것은 더 어려운 문제이다. 한 번에 한 걸음 더 나아가시기 바랍니다. 동물이 이미 서있는 모든 클러스터가 새로운 영역이되도록 코드를 작성하는 것이 더 쉬울 것입니다. 먼저 작동 시키십시오. 그러면 가장 큰 클러스터에 머무르기 위해 동물이 선택적으로 다른 패치로 이동하도록 수정하는 것에 대해 생각하십시오. –

관련 문제