Hello,
I'm in the process of developing a discrete-time population dynamics
model of an insect. I am building up from a simple model, in which
agents simply reproduce then die or die without reproducing, in each time
step. To schedule this, I used buildActions from simpleObserverBug2
in the tutorial as a template:
if (survive == 1)
{
for (i=0; i < [myModel getFecundity]; i++)
{
[self giveBirth]; // New agents are
assigned a "survive" value, then get added to mothList
}
[myModel removeMoth: self]; // I get removed from
mothList
[self drop];
puts("I gave birth, then died.");
fflush(stdout);
}
else if (survive == 0)
{
[myModel removeMoth: self]; // I get removed from
mothList
[self drop];
puts("I died before giving birth.");
fflush(stdout);
}
return self;
}
The step code has two problems, I think, which need to be fixed.
One, since offspring get added to the same list as their parents, they
too get sent the step message in the same time step as do their
parents. What I really want is for offspring to get added to the
list in the following time step. Two, the program crashes following
the first moth removal (see below). I'm less sure about what causes
this - possibly a conflict between the createActionForEach call and the
call to removeMoth from mothList?
There are two possible solutions to these problems which I can think of
given my limited programming knowledge. One, I can put offspring
into a temporary list, then dump them back into the main list at each
time step. This doesn't seem efficient, nor does it solve the crash
problem caused by moth removal. Two, the schedule can be made
dynamic, kind of like the one used in Mousetrap? I'm not sure about
how to build this sort of schedule for this situation.
Does anyone have advice on how to deal with this kind of scheduling
issue? Examples you can point me to? Or maybe there's a much
simpler approach which is escaping me?