Netlogo:避障 - 告诉乌龟走最短路径

时间:2017-03-06 02:57:34

标签: netlogo

模型详细信息我正在尝试在NetLogo中对区域选择进行编码。 Turtle 0选择一个领土中心,并建立一个领土。它根据食物的价值选择补丁,按距离打折(食物/#补丁远离领土中心),按折扣价值的顺序选择补丁。它在满足总食物需求时停止。选择的补丁不必连接到区域,但是当乌龟走到选定的补丁时应该连接。这些补丁被添加为旅行走廊,以使该地区保持连续。在Turtle 0完成建立其领土之后,Turtle 1发芽并重复该过程以选择其自己的区域,然后是Turtle 2,依此类推。其他海龟无法获得属于海龟领地的补丁。

问题应将现有地区视为障碍。海龟需要识别并绕过这些障碍物,使用尽可能短的路径到达目的地地块。

在我目前的代码中,海龟将在现有区域的另一侧选择补丁,因为它们只是穿过它。然而,他们不会增加一个旅行走廊去那里,因为那里的补丁已经拥有了。

有什么方法可以告诉海龟,如果他们遇到拥有的补丁(现有地区),他们必须使用尽可能短的距离,以便他们可以建立到所选补丁的旅行走廊?我意识到这是一个复杂的问题,如果计算实际距离(连接问题:NetLogo: measure real travel distances around obstacles before choosing destination),则更加如此。我一直在讨论这个问题,所以任何想法都有帮助。提前谢谢!

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   

      if patch-here = _destination  ;; add the patch once reached
        [ claim-patch _destination ]

      if patch-here != _destination   
        [ if owner = nobody [claim-travel-patch ]]  ;; add a travel patch while walking to selected patch
        [ if owner != nobody [avoid-obstacle]]  ;; or avoid the obstacle of existing territories
    ]

    [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 claim-travel-patch [_patch]
     ask _patch [set owner myself]
     set pcolor [yellow] 
     ;; etc....
end

to avoid-obstacle
     ;; need to identify some means of going around owned patches
     ;; ideally this will use the shortest route possible....
     ;; but even if not shortest route, any ideas for identifying a new path
     ;; to avoid the obstacle and reach the destination patch?
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 patches with [owner = nobody]  
     report max-one-of available-destinations [benefit-to-me / cost-to-me]          
end

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

to-report cost-to-me
     report distance myself   ;; later, this will hopefully account for actual travel costs (non-euclidean distance), including around other territories. I think this is complicated, so ignoring for now in this question.
end

0 个答案:

没有答案