swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Synchronous scheduling


From: D. D. Donalson
Subject: Re: Synchronous scheduling
Date: Sat, 21 Apr 2001 18:13:55 -0700

HJ,
 
Send me the code.
 
D4
----- Original Message -----
Sent: Saturday, April 21, 2001 6:04 PM
Subject: Synchronous scheduling

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:

- buildActions
{
  [super buildActions];

  modelActions = [ActionGroup create: self];
  [modelActions createActionForEach: mothList message: M(step)];

  modelSchedule = [Schedule createBegin: self];
  [modelSchedule setRepeatInterval: 1];
  modelSchedule = [modelSchedule createEnd];
  [modelSchedule at: 0 createAction: modelActions];

  return self;
}

[In MOTH.M:]

- step
{
unsigned i;

  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?

      0 [main] NCP 1141 handle_exceptions: Exception: STATUS_ACCESS_VIOLATION
    647 [main] NCP 1141 stackdump: Dumping stack trace to NCP.EXE.stackdump

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?

Thanks very much in advance.
Ho Jung Yoo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]