NetLogo:在选择目的地之前测量障碍物周围的实际行程距离

时间:2017-03-20 22:32:02

标签: netlogo

我在Netlogo中建模区域殖民化。 Turtle 0选择一个区域中心,然后通过按值的顺序添加补丁来构建区域。价值取决于收益/成本,其中收益是补丁中的食物数量,成本是距离中心的距离。一旦总和补丁值达到阈值,Turtle 0就会完成构建其区域。接下来,Turtle 1发芽并重复该过程以选择其自己的区域,然后选择Turtle 2,依此类推。重要的是,新龟应避免穿越其他地区,不能选择已经拥有的补丁。

问题:海龟需要绕过已经拥有的补丁。补丁的价值(收益/成本)应根据所需的实际旅行距离准确计算成本,而不是欧几里德距离。

IMAGE: As a visual, here is one result from running this model. The turtle in lime green has a huge territory that required traveling over other territories and did not account for actual travel costs around what should be considered obstacles.

如何根据所需的实际行程距离(即在现有家庭范围的障碍物周围)对龟进行编码以使海龟按实际价值顺序挑选补丁?有些代码如下。有任何想法吗?提前谢谢!

patches-own [
    benefit   ;; ranges 0.1-1 and represents food available in the patch
    owner ]   ;; patches are owned once selected for a territory

turtles-own 
   [ sum-value ]   ;; sum of values of patches in my territory   

globals [threshold = 25]

to setup
    ask patches [ set owner nobody ]
end

to go 
    ask turtles [build-territory]
    tick
end

to build-territory
     if sum-value > threshold [stop] ;; keeps picking patches for territory until I've met my threshold
     pick-patch
     reproduce  ;; sprouts a new hatchling when done building territory
end 

to pick-patch
    let _destination highest-value  ;; this is calculated in reporters, below
    ifelse _destination != nobody [
    face _destination forward 1   ;; turtle will need to avoid obstacles here, haven't figured that out yet.
      if patch-here = _destination
        [ claim-patch _destination ]
    ]
    [stop] ;; if there is no _destination
end

to claim-patch [_patch]
     ask _patch [set owner myself]
     set sum-value sum-value + (benefit / (distance start-patch))
     set pcolor [color] of self
     ;; etc....
end

to reproduce
  if sum-value > threshold [ ask patch 75 75 [sprout 1 ] ]
end    

;;;; --reporters for calculations:-- 

to-report highest-value  ;; calculates value, benefit / cost.
     let available-destinations edge-patches  
     report max-one-of available-destinations [benefit-to-me / cost-to-me]          
end

to-report edge-patches  ;; constrains to searching along edge of territory so it remains contiguous.
     report (patch-set [neighbors4] of territory) with [owner = nobody]
end   

to-report benefit-to-me
     report mean [benefit] of patches in-radius 2   ;; this is basically a moving windows analysis to find a cluster of high-benefit patches.
end

to-report cost-to-me
     report distance myself   ;; this is where turtle needs to account for actual travel costs (non-euclidean distance), including around other territories. how to accomplish?
end

0 个答案:

没有答案