我模拟了两个性别,男性和女性。雌性从一组雄性中选择并产生后代。多个雄性可以与一个雌性交配,雌性产生多个后代。当它们繁殖时,父母死亡,但是turtles-own
变量的特征有一些继承。
我有help here让女性从可用的男性(availa-males
)中进行选择。但是问题是mates
变量在第一轮交配后不起作用。它保持为长度为0的agent-set
。希望您能有所帮助;我可以澄清一下是否不清楚。
to go
if ticks mod 364 = 0 [set year year + 1]
ask turtles [
set mates ( turtle-set )
fd 1
set age ticks
]
ask females [
choose-mates
reproduce
]
tick
end
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
set availa-males males in-radius 5
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 [ anadromous = 0 ] ) / 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 [ anadromous = 0 ] ]
[ one-of availa-males with [ anadromous = 1 ] ] )
; 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 )
]
if n-max < count mates [
print "Fewer available males than mates"
]
set a_threshM [a_threshM] of mates
]
end
to reproduce
ask females with [count mates > 0] [hatch 2 [
set mother myself
set motherThresh [a_threshF] of mother
set fatherThresh sum n-of 1 [a_threshM] of mother
ifelse random 2 = 1 [set breed males
set color red
set a_threshM (motherThresh + fatherThresh) / 2 + (random-normal 0 sqrt(0.5 * Va))
set e_threshM random-normal 0 (sqrt(Ve))
set z_threshM a_threshM + e_threshM
set condM random-normal mu_cond sqrt(V_cond)
ifelse(condM > z_threshM) [set anadromous 0] [set anadromous 1]
setxy random-xcor random-ycor
]
[set breed females
set color blue
set a_threshF (motherThresh + fatherThresh) / 2 + (random-normal 0 sqrt(0.5 * Va))
set e_threshF random-normal 0 (sqrt(Ve))
set z_threshF a_threshF + e_threshF
set condF random-normal mu_cond sqrt(V_cond)
ifelse(condF > z_threshF) [set anadromous 0] [set anadromous 1]
setxy random-xcor random-ycor
]
] ask mates [die]
die]
end
答案 0 :(得分:2)
您的女性“女儿”从母亲那里继承mate-count
。由于mate-count
是while
中choose-mates
循环的逻辑触发器,因此,在孵化后,尝试让子节点重置其mate-count
:
...
[ set breed females
set color blue
set mate-count 0
...
另外,雌性在繁殖后立即死亡-调用go
之后剩下的唯一雌性将尚未调用choose-mates
过程。
您还可以考虑在choose-mates
过程中将reproduce
和ask females
分成单独的go
调用。实际上,女性选择伴侣并繁殖,这使她和她的伴侣脱离了世界。然后,雌性二选择伴侣,不仅将不包括雌性1的伴侣,而且可能包括雌性1的产卵。最好执行以下操作:
ask females [
choose-mates
]
ask females [
reproduce
]