两个海龟品种 _ 一个品种是另一个的变量?
Two Turtles Breeds _ one breed is the variable of the other?
我有一个 Netlogo 问题。如果我有两个不同品种的海龟,一个品种的指定数量的变量之和是否可以成为另一个品种的变量?
这是我的思路。我想模拟多个家庭的用水量,但一个家庭的用水量需要取决于 a) 房屋的固定值(如水龙头用水量)* b) a) a) 使用水龙头的频率人。每个家庭包含 1 人或多人,使用频率因人而异。
使用两个海龟品种的想法可以让我看到一个品种做出的决定如何影响另一个品种。
这是我的伪代码,以帮助说明我的想法(并非旨在成为工作代码)
globals []
breed [People person]
breed [Community household]
People-own [frequency]
Community-own [waterusefacuet HouseholdWaterUse]
;; =================================================================================================================
;; =================================================================================================================
to setup
clear-all
HouseholdCreation
PersonCreation
reset-ticks
end
to go
ask Community [WaterConsumption]
tick
end
;; =================================================================================================================
;; =================================================================================================================
to HouseholdCreation
ask patches [ sprout-Community n of 1 [
set size 1.0 set shape "square" set color blue
set waterusefacuet (1)
] ]
end
to PersonCreation
ask Community [ hatch-People 1 [
set size 0.5 set shape "circle" set color red
set frequency (1 + random 4)
]]
end
to WaterConsumption
Set HouseholdWaterUse (waterusefacuet * (frequency * # of people) )
end
为什么不简单地把每一块地做成一个家庭,让每一块地有一只或多只乌龟(人),然后计算家庭因素作为斑块因素?要定义社区,可以将补丁放入区域(例如,如果 pxcor >= 5 且 pxcor <=8 且 pycor >=3 且 pycor <= 6 设置区域 1)<== 不是代码,只是想法。
您可以设置补丁大小,使每个补丁变小,并指定一个大的补丁区域。
can the sum of a specified number of one breed's variables BE THE VARIABLE of the other breed?
当然可以。
snipsnip 澄清一下:在我的代码中,我不让住在一个家庭的人的用水量成为该家庭的用水量变量。通常我会反对让一个(或多个)代理的状态成为另一个变量的状态的解决方案——除非有很好的理由。让状态相互依赖是危险的,因为您始终必须确保在代理之间同步值。更重要的是,它通常是不必要的。在我的解决方案中,每个人都属于一个家庭,当该家庭计算其总用水量时,它会要求所有居民将当天的用水量发送给他们,然后 returns 所有这些数字的总和。我希望这是有道理的。如果没有,请问。
*< /snipsnip>
不过您需要使用 of
关键字。 of
允许您直接访问来自一个或多个个体代理的 context/perspective 的变量。所以,假设我们有家庭和人,并且人们(因为我们都有不同的用水习惯)有一定的水龙头使用频率。事实上,我们可以让人们从他们独有的正态分布中提取他们每天使用的水量。让我们这样做:
breed [people person]
breed [households household]
people-own [
mean-use-per-day ;; mean use per day
sd-use-per-day ;; standard dev per day
my-household ;; the household to which a person belongs
]
to setup
create-households 10 [
hatch-people random 4 + 1 [ ;; between 1 and 4 people in a household
set mean-use-per-day random 5 + 5 ;; mean 5-9
set sd-use-per-day random-float 3 ;; sd 0.00-2.99
set my-household myself ;; we set the person's household to the household that hatched them
]
]
to-report household-water-use ;; household reporter
report sum [random-normal mean-use-per-day sd-use-per-day] of people with [my-household = myself] ;; this creates a list of water uses based on the random use of each person in the household.
end
为了运行这段代码,你可以简单地调用
show [household-water-use] of households
来自指挥中心。这将为您提供每个家庭的用水清单。或者,如果您只想随机查看某一天某一家庭的用水量,您可以尝试
show [household-water-use] of one-of households
我有一个 Netlogo 问题。如果我有两个不同品种的海龟,一个品种的指定数量的变量之和是否可以成为另一个品种的变量?
这是我的思路。我想模拟多个家庭的用水量,但一个家庭的用水量需要取决于 a) 房屋的固定值(如水龙头用水量)* b) a) a) 使用水龙头的频率人。每个家庭包含 1 人或多人,使用频率因人而异。
使用两个海龟品种的想法可以让我看到一个品种做出的决定如何影响另一个品种。
这是我的伪代码,以帮助说明我的想法(并非旨在成为工作代码)
globals []
breed [People person]
breed [Community household]
People-own [frequency]
Community-own [waterusefacuet HouseholdWaterUse]
;; =================================================================================================================
;; =================================================================================================================
to setup
clear-all
HouseholdCreation
PersonCreation
reset-ticks
end
to go
ask Community [WaterConsumption]
tick
end
;; =================================================================================================================
;; =================================================================================================================
to HouseholdCreation
ask patches [ sprout-Community n of 1 [
set size 1.0 set shape "square" set color blue
set waterusefacuet (1)
] ]
end
to PersonCreation
ask Community [ hatch-People 1 [
set size 0.5 set shape "circle" set color red
set frequency (1 + random 4)
]]
end
to WaterConsumption
Set HouseholdWaterUse (waterusefacuet * (frequency * # of people) )
end
为什么不简单地把每一块地做成一个家庭,让每一块地有一只或多只乌龟(人),然后计算家庭因素作为斑块因素?要定义社区,可以将补丁放入区域(例如,如果 pxcor >= 5 且 pxcor <=8 且 pycor >=3 且 pycor <= 6 设置区域 1)<== 不是代码,只是想法。
您可以设置补丁大小,使每个补丁变小,并指定一个大的补丁区域。
can the sum of a specified number of one breed's variables BE THE VARIABLE of the other breed?
当然可以。
snipsnip 澄清一下:在我的代码中,我不让住在一个家庭的人的用水量成为该家庭的用水量变量。通常我会反对让一个(或多个)代理的状态成为另一个变量的状态的解决方案——除非有很好的理由。让状态相互依赖是危险的,因为您始终必须确保在代理之间同步值。更重要的是,它通常是不必要的。在我的解决方案中,每个人都属于一个家庭,当该家庭计算其总用水量时,它会要求所有居民将当天的用水量发送给他们,然后 returns 所有这些数字的总和。我希望这是有道理的。如果没有,请问。
*< /snipsnip>
不过您需要使用 of
关键字。 of
允许您直接访问来自一个或多个个体代理的 context/perspective 的变量。所以,假设我们有家庭和人,并且人们(因为我们都有不同的用水习惯)有一定的水龙头使用频率。事实上,我们可以让人们从他们独有的正态分布中提取他们每天使用的水量。让我们这样做:
breed [people person]
breed [households household]
people-own [
mean-use-per-day ;; mean use per day
sd-use-per-day ;; standard dev per day
my-household ;; the household to which a person belongs
]
to setup
create-households 10 [
hatch-people random 4 + 1 [ ;; between 1 and 4 people in a household
set mean-use-per-day random 5 + 5 ;; mean 5-9
set sd-use-per-day random-float 3 ;; sd 0.00-2.99
set my-household myself ;; we set the person's household to the household that hatched them
]
]
to-report household-water-use ;; household reporter
report sum [random-normal mean-use-per-day sd-use-per-day] of people with [my-household = myself] ;; this creates a list of water uses based on the random use of each person in the household.
end
为了运行这段代码,你可以简单地调用
show [household-water-use] of households
来自指挥中心。这将为您提供每个家庭的用水清单。或者,如果您只想随机查看某一天某一家庭的用水量,您可以尝试
show [household-water-use] of one-of households