2014-01-16 76 views
1

在設置中,我將創建一個命令,用於生成具有隨機維度的隨機數集羣。每個羣集將由代理(農民)管理。每一個斑塊都代表着農民可以用不同種子種植的潛在作物。這將是值得使用的半徑功能?如果你需要更多的細節問我。NetLogo - 創建一個集羣作爲一個由烏龜管理的集羣

非常感謝您的回答,這正是我需要的!現在我還有一個問題,我按照你的建議實施了這個計劃,現在我展示了一個像你這樣的世界,但我不知道如何讓我的經紀人(農民)在他們的農場規模的每一個補丁上採取行動。在我的模擬中,農民只在一個補丁上採取行動。我嘗試了不同的方式來擴展代理的功能(功能補丁集),但每次在程序運行期間出現錯誤。 正如Marzy先前的帖子所建議的,我包含了我的模型的代碼。 主要問題是將「培養」程序(在代碼的底部)擴展到屬於農民的每個補丁。

非常感謝您

turtles-own [ 
    profit-from-fuel 
    profit-from-food 
    expected-fuel-sell-price 
    expected-food-sell-price 
    profit 
    farm 
    farm-size 
    ;risk-attitude-food 
    ;risk-attitude-fuel 
] 


patches-own [ 
    fuel-yeld 
    food-yeld 
    land-sustainability 
    water-level 
    belongs-to 

] 

globals  [ 
    fuel-sell-price 
    food-sell-price 
    governs   
    ] 


to setup   
clear-all 
clear-all-plots 
create-farmers 
setup-land 
reset-ticks 

    ask turtles 
    [  set-farm-in-radius farm-size ] 

set fuel-sell-price 30 ;+ random 2 + random -2 
set food-sell-price 30 ;+ random 2 + random -2 

end 


to create-farmers 


create-turtles 30 

[ 
set shape "person farmer" 
setxy random-pxcor random-pycor 
set profit-from-fuel 0 ; indicizzazione del profitto iniziale a 0 
set profit-from-food 0 ; indicizzazione del profitto iniziale a 0 

set farm-size random 5 + 1 
set label farm-size 
] 
end 


to setup-land 

ask patches [set belongs-to nobody] 

ask patches 
    [ 

    set pcolor 3 
    set food-yeld 10000 
    set fuel-yeld 10000 
    set land-sustainability random 5 
    set water-level random 3 
    ] 

    end 


to set-farm-in-radius [d] 
move-to one-of patches with [not any? other patches in-radius d with [belongs-to != nobody]] 
set farm patches in-radius farm-size 
ask farm [set belongs-to myself] 
let c random 6 + 61 
ask farm [set pcolor c] 
end 


to set-farm-distance [d] 
    move-to one-of patches with [not any? other patches with [belongs-to != nobody and distance myself < d]] 
    set farm patches with [distance myself < d] 
    ask farm [set belongs-to myself] 
    let c random 6 + 61 
    ask farm [set pcolor c] 
end 



to go 

    tick 

    ask turtles [ 

    set expected-fuel-sell-price fuel-sell-price + random 5 + random -5   
    if expected-fuel-sell-price < 0 [set expected-fuel-sell-price 1] 
    set expected-food-sell-price food-sell-price + random 5 + random -5 
    if expected-food-sell-price < 0 [set expected-food-sell-price 1] 
    set profit profit-from-fuel + profit-from-food 
    if profit = 0 [ set profit 1 ] 
    ] 


    set fuel-sell-price fuel-sell-price + random 5 + random -5 
    if fuel-sell-price < 0 or fuel-sell-price = 0 [set fuel-sell-price 1 ]  
    set food-sell-price food-sell-price + random 5 + random -5 
    if food-sell-price < 0 or food-sell-price = 0 [set food-sell-price 1]  



    ask turtles [ 

    cultivate 

    set profit profit-from-food + profit-from-fuel 
    ;if water-level > 0.95 [ set profit profit - (profit * (2/profit)) ] valutare se inserire anche una failing probability 
    ] 




if ticks = Duration [ stop ] 
if ticks > Duration [stop] 

end 

to cultivate 


    ifelse land-sustainability < 2.1 or water-level = 1 
    [ set pcolor green set profit-from-food food-sell-price * (((food-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 
    ] 

    [ 
    let utility-from-food ((food-yeld * expected-food-sell-price * land-sustainability)^risk-attitude)/risk-attitude 
    let utility-from-fuel ((food-yeld * expected-fuel-sell-price * land-sustainability)^(1 - risk-attitude))/(1 - risk-attitude) 


    ifelse utility-from-food < utility-from-fuel 
    [ 
    set pcolor red 
    set profit-from-fuel fuel-sell-price * (((fuel-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 
    ] 

    [ 
    set pcolor green 
    set profit-from-food food-sell-price * (((food-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 
    ] 

] 



end 

新version_ _ __ _ __ ----

to cultivate 
ifelse land-sustainability < 2.1 or water-level = 1 
[ 
    set profit-from-food food-sell-price * (((food-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 
set food 1 
    ] 
[ 
    let utility-from-food ((food-yeld * expected-food-sell-price * land-sustainability)^risk-attitude)/risk-attitude 
    let utility-from-fuel ((food-yeld * expected-fuel-sell-price * land-sustainability)^(1 - risk-attitude))/(1 - risk-attitude) 
    ifelse utility-from-food < utility-from-fuel 
    [ 
    set profit-from-fuel fuel-sell-price * (((fuel-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 
    set fuel 1 
    ] 
    [ 
    set profit-from-food food-sell-price * (((food-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 
    set food 1 
] 
    ] 
    ask farm [ 
    if food = 1 [set pcolor green] 
    if fuel = 1 [set pcolor red] 
] 
    end 
+1

其更好地包括一些代碼,問究竟是什麼在半徑的問題可能是好的,但你需要什麼樣的集羣? – Marzy

+1

這看起來非常類似於http://stackoverflow.com/questions/20533159/spacing-agents-in-netlogo-based-on-territory-size和http://stackoverflow.com/questions/20831832/define-home-區烏龜/和http://stackoverflow.com/questions/19326781/adding-patch-clusters-in-a-landscape和http://stackoverflow.com/questions/20336364/how-to-create-cluster-patches - 即-DO-不重疊之間,它們。我建議看看那些;他們應該幫助你解決你的問題和/或制定一個更具體的問題。請注意,在Stack Overflow上,您可以編輯自己的問題以改進它並添加更多詳細信息。 –

+1

正如附註,你應該在'setup'結尾調用'reset-ticks',在'go'結尾調用'tick'。 –

回答

0

正如賽斯表示,其類似於計算器等問題,在這裏更多相關答案:

turtles-own [farm farm-size] 
patches-own [belongs-to] 

to setup 
    clear-all 
    ask patches [set belongs-to nobody] 
    create-turtles 9 
    [ 
    set farm-size random 5 + 1 
    set label farm-size 
    ] 
    ask turtles 
    [ 
    set-farm-in-radius farm-size 
    ] 
    ask patch -8 14 [set plabel "set-farm-in-radius"] 
end 

to set-farm-in-radius [d] 
    move-to one-of patches with [not any? other patches in-radius d with [belongs-to != nobody]] 
    set farm patches in-radius farm-size 
    ask farm [set belongs-to myself] 
    let c random 8 + 21 
    ask farm [set pcolor c] 
end 


to set-farm-distance [d] 
    Move-to one-of patches with [not any? other patches with [belongs-to != nobody and distance myself < d]] 
    set farm patches with [distance myself < d] 
    ask farm [set belongs-to myself] 
    let c random 8 + 21 
    ask farm [set pcolor c] 
end 

enter image description here

並使用下面的設計距離的計算結果,我已經設置了varibele belongs_to的這表明誰擁有在PLABEL補丁這樣可以更好地看到每個補丁的。

enter image description here

更新:當你想改變在一個農場的每一個補丁,你應該ask farm []

to cultivate 


    ifelse land-sustainability < 2.1 or water-level = 1 
    [ 
    ask farm [ 
    set pcolor green 
    ] 
    set profit-from-food food-sell-price * (((food-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 

    ] 
    [ 
    let utility-from-food ((food-yeld * expected-food-sell-price * land-sustainability)^risk-attitude)/risk-attitude 
    let utility-from-fuel ((food-yeld * expected-fuel-sell-price * land-sustainability)^(1 - risk-attitude))/(1 - risk-attitude) 


    ifelse utility-from-food < utility-from-fuel 
    [ ask farm [ 
    set pcolor red 
    ] 
    set profit-from-fuel fuel-sell-price * (((fuel-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 

    ] 
    [ 
    ask farm [ 
    set pcolor green ] 
    set profit-from-food food-sell-price * (((food-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 
    ] 

] 



end 

更新:

to cultivate 

    ifelse land-sustainability < 2.1 or water-level = 1 
    [ 

    set profit-from-food food-sell-price * (((food-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 

    ask farm [ 
     set food 1 

    ] 


    ] 

    [ 
    let utility-from-food ((food-yeld * expected-food-sell-price * land-sustainability)^risk-attitude)/risk-attitude 
    let utility-from-fuel ((food-yeld * expected-fuel-sell-price * land-sustainability)^(1 - risk-attitude))/(1 - risk-attitude) 


    ifelse utility-from-food < utility-from-fuel 
    [ 

     set profit-from-fuel fuel-sell-price * (((fuel-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 

     ask farm [ 
     set fuel 1 


     ] 
    ] 
    [ 

     set profit-from-food food-sell-price * (((food-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 

     ask farm [ 
     set food 1 

     ] 

    ] 
    ] 



end 

to recolor-farm 
     if food = 1 [set pcolor green ] 
     if fuel = 1 [set pcolor red] 
end 

添加ask farm [recolor-farm]培養

+0

我試圖讓代理管理他們自己的修補程序,但是使用我的代碼,代理僅對它們所在的修補程序執行操作。我把我的代碼放在原始評論中,我怎樣才能以代理可以管理的方式實施代碼(決定哪種類型的農場)他們擁有的所有補丁? – user3204387

+1

'培養......問農場......' –

+0

非常感謝,現在我看到農場的整個補丁變成了同樣的顏色。我試圖找出讓農場的每一個補丁都有不同顏色的方法。我認爲在模型中,每個農民都決定自己農場的每一個領域(補丁)培養哪種產品。問我是否需要更多細節。 – user3204387

0

你的答案第二部分:

to cultivate 
ifelse land-sustainability < 2.1 or water-level = 1 
[ 
    set profit-from-food food-sell-price * (((food-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 
ask farm 
[ 
set food 1 
] 
    ] 
[ 
    let utility-from-food ((food-yeld * expected-food-sell-price * land-sustainability)^risk-attitude)/risk-attitude 
    let utility-from-fuel ((food-yeld * expected-fuel-sell-price * land-sustainability)^(1 - risk-attitude))/(1 - risk-attitude) 
    ifelse utility-from-food < utility-from-fuel 
    [ 
    set profit-from-fuel fuel-sell-price * (((fuel-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 
ask farm 
[ 
    set fuel 1 ] 
    ] 
    [ 
    set profit-from-food food-sell-price * (((food-yeld)^(1 - alfa)) * (((water-level)^(1 - gamma)) * ((land-sustainability)^(gamma))^alfa)) 

    ask farm [ 
     set food 1] 

] 
    ] 
    ask farm [ 
    if food = 1 [set pcolor green] 
    if fuel = 1 [set pcolor red] 
] 
    end 
+0

嗨,我嘗試了新的程序,但結果是一樣的......如果一個農民決定種植哪種植物,他將他農場的所有補丁都變成同一種顏色。也許我在我的解釋中錯過了一些東西,如果你需要關於模型的更多細節問我。非常感謝您的寶貴時間。 – user3204387

+0

您設定食品和燃料價值的條件與每個補丁無關,他們只考慮農民的一些利潤,您應該根據與補丁相關的條件改變食物或燃料的價值而不是農民。 – Marzy

+0

好的,所以我需要在補丁自身的環境中移動食物利潤和燃料利潤的變量? – user3204387

相關問題