2017-10-15 92 views
0

我正在建模一個城市景觀,用於觀察運動,其中補丁等同於建築物並具有不同的影響值。我需要使用計算的東西,如每個補丁值的記者函數:netlogo:有補丁使用記者計算影響力值

(its own influence) plus (the influence of neighbors) divided by the 
distance to a specific turtle (max-one-of distance myself) 

龜然後將朝着具有最高影響值的補丁移動,但沿着街道定義。

我是新使用netlogo並已完全卡住。

我已經包括了我到目前爲止的一部分,但我無法弄清楚如何編寫將計算每個補丁影響值(圓錐體內)的記者函數,以便海龜可以朝着最好的選擇。

to setup-influence-field 
    ask patches with [pcolor = green] [set influence commercial-influence] 
    ask patches with [pcolor = orange] [set influence production-influence] 
    ask patches with [pcolor = yellow] [set influence domestic-influence] 
    ask patches with [pcolor = pink] [set influence religious-influence] 
    ask patches with [pcolor = blue] [set influence public-influence] 
end 

to go 
    move-serapis 
end 

to move-serapis 
    ask serapis [set-procession-heading] 
    repeat 2 [ ask serapis [ fd .25 ] display ] 
    tick 
end 

;;;;; the reporter values are need for this part of the code so that the turtles (serapis) can move towards the patches with the highest influence value;;;; 
    to set-procession-heading 
     let direction patches in-cone 4 40 with [influence-field > 0] 
     if any? influence-field 
      [face max-one-of influence-field] ;;;; face towards the highest computed influence value 
     ifelse any? patches with [pcolor = black] in-cone 1 25 
     [process] 
    end 

任何幫助將不勝感激!

回答

1

我不認爲這是完全正確的,我不能測試它,但它應該啓動你,也許有人在這裏可以解決它,如果你讓我們知道錯誤。

to set-procession-heading 
    let direction-targets patches in-cone 4 40 with [influence-field > 0] 
    if any? direction-targets 
    [ face max-one-of direction-targets [ influence-amount self ] ] 
end 

to-report influence-amount [ target-node ] 
    report ([ influence-field ] + sum [ influence-field] of neighbors)/distance target-node 
end 

我所做的是設置一個單獨的過程來報告計算結果。該過程需要一個參數(名爲target-node),因爲您需要能夠傳遞受影響的烏龜的身份。一旦你有了這個過程,那麼你可以簡單地將潛在方向的代理集合傳遞給計算過程,並選擇最大值。