NetLogo-创建集群作为由乌龟管理的服务器场 [英] NetLogo - Creation of a cluster as a farm manage by a turtle
问题描述
在设置中,我将创建一个命令,该命令生成具有随机维数的随机数量的群集.每个群集将由代理(农民)进行管理.每个补丁都代表农民可以使用不同类型的种子进行耕种的潜在作物.值得使用半径函数吗?如果您需要更多详细信息,请问我.
In the setup I would create a command that generate a random number of cluster with a random dimension. Each cluster it would be managed by an agent (farmer). Every single patch represent a potential crop that farmer can cultivate with a different type of seeds. It would be worth use the function in-radius? If you need more details ask me.
非常感谢您的回答,这正是我所需要的!现在,我还有另一个问题,我按照您的建议实施了该程序,现在我展示了一个像您一样的世界,但是我不知道如何让我的经纪人(农民)对他们农场规模的每个片区采取行动.在我的模拟中,农民仅对一个补丁进行操作.我以另一种方式尝试扩展代理程序的功能(功能补丁集,),但是每次在该过程运行过程中遇到错误时,都会执行此操作. 正如Marzy在上一篇文章中所建议的那样,我包括了我模型的代码. 主要问题是将耕种"过程(在代码底部)扩展到属于农民的每个补丁.
Thank you very much for your answers, it's exactly what I need! Now I've another question, I implemented the program as you suggest and now I displaying a world like your, but I don't know how to make my agent (the farmer) act on every patch of their farm-size. In my simulation farmer act only on one patch the one they are on. I tried in a different way to extend the action of my agent (function patch-set, ) but everytime I got an error during the running of the procedure. As suggested in the previous post by Marzy I include the code of my model. The main problem is to extend the procedure "to cultivate" (at the bottom of the code) to each patches who belongs-to a farmer.
非常感谢
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
新版本_ _ __ _ __ ----
new 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
推荐答案
正如Seth所说的,它与stackoverflow中的其他问题类似,这是更相关的答案:
As Seth said its similar to other questions in stackoverflow, here is more related answer:
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
在下面的设计中使用距离结果,我为每个补丁设置了varibele Emirates_to,以在plabel中显示谁拥有该补丁,以便您可以更好地看到它.
And using distance results in following design, I have set the varibele belongs_to of each patch which shows who owns that patch in plabel so you can see it better.
更新:当您要对服务器场的每个补丁进行更改时,应ask farm []
Update: When you want to make a change on every patch of a farm you should 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]
这篇关于NetLogo-创建集群作为由乌龟管理的服务器场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!