在我的模型中,海龟有两种性别,男性有两种潜在的策略。女性计算设定半径中的男性数量。
我希望女性根据两种男性战术的相对频率来衡量从男性组中选择的概率(无需替换)。
我已经有了从男性(matingPoolProbAnad
和matingPoolProbRes
)中选择概率的代码,但我不知道如何实现它,尽管rnd
扩展似乎是要走的路,特别是rnd:weighted-n-of size agentset [ reporter ]
。
三件事情很复杂(1)男性可以与一个以上的雌性交配,但(2)只有一个给定的雌性和(3)雌性只能与最多五个雄性交配。
to count-mates ; ask the females to count the number of males in a 10 patch radius & then
; determine the frequency of the resident males in their patch
ask turtles with [sex = "female"]
[
if any? turtles with [sex = "male"] in-radius 10
[ set potentialMates turtles with [sex = "male"] in-radius 10
ifelse any? potentialMates with [anadromousM = 1]
[ set FA count potentialMates with [anadromousM = 1] / count potentialMates ]
[ set FA 0]
ifelse any? potentialMates with [anadromousM = 0]
[ set FR count potentialMates with [anadromousM = 0] / count potentialMates ]
[ set FR 0]
]
]
end
to mating-pool-prob ; negative frequency dependency which is based on the number of male
; resident turtles
ask turtles with [sex = "female"]
[
ifelse (FA = 1) and (FR = 0)[
set matingPoolProbAnad 1
set matingPoolProbRes 0
]
[ifelse (FA > 0) and (FR < 1)
[
set matingPoolProbRes exp(a - b * (FR - c ))/(1 + exp(a - b * (FR - c)))
set matingPoolProbAnad 1 - matingPoolProbRes
]
[
set matingPoolProbAnad 0
set matingPoolProbRes 1
]
]
]
end
答案 0 :(得分:1)
这个例子可能接近你所得到的,但显然需要改编自这个玩具版本。这种设置使75%的男性采用策略A,其余采用策略B,并为所有海龟提供一个空的代理人组合开始:
breed [ males male ]
breed [ females female ]
turtles-own [ mates ]
males-own [ strategy ]
females-own [ max-mate-count mate-count ]
to setup
ca
ask n-of 200 patches [
sprout-males 1 [
ifelse random-float 1 < 0.75 [
set strategy "A"
set color orange
] [
set strategy "B"
set color violet
]
]
]
ask n-of 50 patches with [ not any? turtles-here ] [
sprout-females 1 [
set color green
]
]
ask turtles [
set mates ( turtle-set )
]
reset-ticks
end
使用while循环让每个女性迭代评估她可用的男性的策略比例,然后将它们添加到她的伴侣中。名单。评论中有更多细节:
to choose-mates
ask females [
; set a cap on possible mates for females; 5, or the number
; available within the radius if less than 5
let availa-males males in-radius 10
let n-max count availa-males
set max-mate-count ifelse-value ( n-max < 5 ) [ n-max ] [ 5 ]
; Until a female has chosen up to her maximum number of mates:
while [ mate-count < max-mate-count ] [
; determine which available males are not already in her 'mates' agentset
set availa-males availa-males with [ not member? self [mates] of myself ]
; assess the proportion of B strategy in remaining available males
let prop_B ( count availa-males with [ strategy = "B" ] ) / n-max
; example probability choice, just meant to choose B males
; with a frequency disproportionate to availability
let proba_B ifelse-value ( prop_b * 2 < 0.6 ) [ prop_b * 2 ] [ 0.6 ]
; use a random float to determine which strategy type is chosen
set mates ( turtle-set mates ifelse-value ( random-float 1 < proba_B )
[ one-of availa-males with [ strategy = "B" ] ]
[ one-of availa-males with [ strategy = "A" ] ] )
; count the current mates to break the while loop once
; the maximum number of mates is reached
set mate-count count mates
]
; have the female's males add her to their own mates agentset
ask mates [
set mates ( turtle-set mates myself )
]
]
end
检查&#39; B&#39;男性的选择与他们的可用性不成比例:
to check-values
let all-mates map [ i -> [strategy] of i ] [mates] of females
print word "Average proportion of 'B' mates chosen: " mean map b-proportion all-mates
print word "Actual proportion of 'B' males: " ( ( count males with [ strategy = "B" ] ) / count males )
end
to-report b-proportion [ input_list ]
let tot length input_list
let nb length filter [ i -> i = "B" ] input_list
report nb / tot
end
我并非100%确定您之后的情况 - 也许您可以使用rnd
软件包来清理循环。
编辑以回复评论
如果你像这样修改`choose-mates的结尾:
...
...
; have the female's males add her to their own mates agentset
ask mates [
set mates ( turtle-set mates myself )
]
if n-max < count mates [
print "Fewer available males than mates"
]
]
end
您的go
看起来像是:
to go
choose-mates
end
您可以根据需要多次运行setup
和go
,并且您永远不会看到打印输出&#34;可用的男性比配偶少#34;
to repeat-1000
repeat 1000 [
setup
go
]
end
我跑了几次,从来没有计算availa-males
小于mates
的数量。但是,如果您在不允许females
重置其mates
代理集的情况下添加移动,则会开始看到它 - 例如,尝试运行几次:
to go
choose-mates
ask turtles [ fd 1 ]
end
现在,因为海龟在移动,你有一些情况,females
从前一个函数调用中保持其配偶,然后移动到availa-males
较少的空间。快速简便的解决方法是让雌性每次都清除配偶。你这样做取决于你的模特目标(女性选择配偶的频率如何?他们只会忘记以前的配偶吗?等等),但这是一个非常简单的方法:
to go
ask turtles [ set mates ( turtle-set ) ]
choose-mates
ask turtles [ fd 1 ]
end
现在你可以随心所欲地运行它,并且不应该看到&#34;可用的男性少于配偶&#34;打印输出。