2017-07-11 49 views
0

背景:我在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

你看看[GIS擴展](https://ccl.northwestern.edu/netlogo/docs/gis.html)嗎?如果你使用多邊形,你可以捍衛內部和外部的東西。 – delaye

回答

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 

如果這是計算量太大,讓我知道,我可以討論優化。

相關問題