NetLogo从补丁集中释放孤立的补丁

时间:2014-02-19 09:01:53

标签: 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 个答案:

答案 0 :(得分: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

但是,请参阅示例的其余部分。

在您的使用案例中,您不会随意放置“种子”来种植群集,而是开始在动物所在的小块中种植群集。