Netlogo:识别线性特征之外的所有补丁

时间:2017-07-11 21:13:45

标签: netlogo

背景:我在NetLogo中建模区域选择。海龟占据了道路划分的景观。每只乌龟选择其领土中心,然后建立一个领土。乌龟根据所有权价值为其领土选择补丁,所有权价值取决于食物与旅行费用。旅行费用包括距离,还应包括到达补丁是否需要穿越道路。

目标:我希望每只海龟都能识别出需要越过道路才能从领土中心到达补丁的所有补丁。然后乌龟应该为这些补丁分配更高的成本。每只乌龟将占据景观的不同部分,因此这些成本将特定于每只乌龟。 如何做到这一点?

示例:这里有两只乌龟的景观: enter image description here

示例代码:我已经添加了一些内容,以便了解如何为每只乌龟保留道路成本的方法,但不知道这些是怎样的将被计算或在建立地区时有更好的方法来保存这些信息:

patches-own
[ owner  ;; turtle who claims patch for territory
  benefit  ;; i.e., food 
  primary-feature  ;; either "road" or null

  ;; Need a way to calculate and remember road-related patch costs for each turtle,
  ;; which are based on whether the turtle must cross a road to reach the patch. 
  ;; Perhaps this could be a patch variable tied to each turtle as follows:
  road-costs-to-turtle-1 
  road-costs-to-turtle-2 
  ;; etc...? If so, these would be calculated after turtle chooses a territory center.
]

turtles-own
[ start-patch  ;; my territory center
  destination  ;; my next patch to claim
  territory  ;; patches I own
]

to go
     pick-center
     pick-patch
end    

to pick-center
     setxy random-xcor random-ycor
     set start-patch (patch-here)
     ;; Turtle selects a patch for its territory center. Turtle will next need
     ;; to calculate costs for patches based on whether a patch requires crossing 
     ;; a road to reach it. I'm at a loss for how to identify all patches beyond 
     ;; roads from the turtle's perspective, however.
end

to pick-patch
    if patch-here = start-patch [ set destination highest-value ]
    ;; Turtle travels to and adds patches to its territory once reaches destination.
end

to-report highest-value            
     let available-destinations (patch-set [neighbors4] of territory) with [owner = nobody]   
     report max-one-of available-destinations ([benefit-to-me / cost-to-me]) 
end

to-report benefit-to-me
     report benefit ;; i.e., food value of patch
end

to-report cost-to-me
     let road-cost ;;<--??? 
     ;; Not sure how to identify if patches are past a road and thus costlier.
     ;; If this is a patches-own variable, then the coding may be something like:
     if who = 1 [let road-cost road-cost-to-turtle-1] ;; etc. 

     report distance [start-patch] of myself + road-cost
end

1 个答案:

答案 0 :(得分:2)

虽然建议使用GIS是一个很好的建议,但我认为你可能还想要一种方法来做到这一点。一种简单但计算密集的方法是“增长”乌龟的领土,直到它无法进一步发展:

to-report claim-territory [ current-territory ]
  let territory-size count current-territory
  ; Combine all non-road neighbors of the current territory with the current territory
  set current-territory (patch-set
    current-territory
    ([ neighbors4 with [ primary-feature != "road" ] ] of current-territory)
  )
  ifelse count current-territory > territory-size [
    report claim-territory current-territory
  ] [
    report current-territory
  ]
end

这将报告与current-territory中未与道路相交的所有补丁。然后在调用pick-center

之后调用它
set territory claim-territory (patch-set start-patch)

然后,要获得补丁的费用:

to-report cost [ target-patch ]
  ifelse member? target-patch territory [
    ; Compute and report cost of in territory patch
  ] [
    ; Compute and report cost of out of territory patch
  ]
end

如果这太计算密集,请告诉我,我可以讨论优化。