问题
I have a simulation with two sexes, males and females. Females select from a group of males and produce offspring. Multiple males can mate with a single female and females produce multiple offspring. When they reproduce, the parents die but there is some inheritance of traits which are turtles-own
variables.
I had help here in getting the females to choose from the pool of available males (availa-males
). But the problem is that the mates
variable doesn't work after the first round of mating. It stays as an agent-set
of length 0. Hope you can help; I can clarify if anything isn't clear.
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
回答1:
Your female "daughters" inherit the mate-count
from their mothers. Since mate-count
is a logical trigger for the while
loop in choose-mates
, try having the daughters reset their mate-count
when they are hatched:
...
[ set breed females
set color blue
set mate-count 0
...
Additionally, females die immediately after reproducing- the only females left after go
has been called will not yet have called the choose-mates
procedure.
You might also consider separating out choose-mates
and reproduce
into separate ask females
calls in your go
procedure. As it is, female one chooses mates and reproduces, which removes herself and her mates from the world. Then, female two chooses mates, which not only will not include the mates of female 1 but may include the spawn of female one. It might be better to do something like:
ask females [
choose-mates
]
ask females [
reproduce
]
来源:https://stackoverflow.com/questions/50947716/how-to-create-multiple-generations-of-reproduction-where-mates-are-selected-in-t