swarm-support
[Top][All Lists]
Advanced

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

Re: Sleeping Beauty ...


From: donalson
Subject: Re: Sleeping Beauty ...
Date: Sat, 07 Nov 1998 05:37:43 -0800

Unless I'm mistaken, (which unfortunatly, is all too often) you are
talking about an asynchronous schedule.  It can easly be done in Swarm.
I use one that involves "doubles" for the time so I use schedules with
concurrent groups where the schedule id is the integer part of the time
and the sub-schedule id is the fractional part.  Given that, here is how
I do it:

1.)  I keep track of each event that an agent schedules for itself with
a generic structure:

struct eventTime {

   double    time;
   timeval_t schedTime;
   timeval_t subSchedTime;
   id        eventId;
   id        subSchedId;
   };

2.)  I set up the schedule as follows:

//Concurrent Async Schedule

  subschedType = [Schedule customizeBegin: [self getZone]];
  [subschedType setAutoDrop: 1];
  subschedType = [subschedType customizeEnd];

  concGroupType = [ConcurrentSchedule customizeBegin: [self getZone]];
  [concGroupType setAutoDrop: 1];
  concGroupType  = [concGroupType customizeEnd];

  eventSchedule = [Schedule createBegin: [self getZone]];
  [eventSchedule setAutoDrop: 1];
  [eventSchedule setConcurrentGroupType: concGroupType];
  eventSchedule = [eventSchedule createEnd];


3.)  An agent can now schedule an action to itself for example:


-scheduleMove
{

// How long before the agent moves again
   moveEvent.time=movementRate;

//Take moveEvent.time and add it to the present system time.  Then break
it down into the
//int and fract parts and make them into the id's "moveEvent.schedTime"
and //"moveEvent.subSchedTime"

// Note "make SystemTime is pretty ugly due to the use of concurrent
schedules so I am not including it.
//Ask me if you are interested.

   moveEvent.subSchedTime=[myModel makeSystemTime: moveEvent.time
scheduleTime: &moveEvent.schedTime];

   moveEvent.subSchedId=[eventSchedule insertGroup: (id)
moveEvent.schedTime];

   moveEvent.eventId=[moveEvent.subSchedId at: moveEvent.subSchedTime
createActionTo: self message: M(move)];


timeToMove=(double)moveEvent.schedTime+(double)moveEvent.subSchedTime/precison;

   return self;
}

4.)  Now, if an agent wants to remove one of its own actions, say the
agent dies prior to its scheduled move time:

-die
{
id nullEvent;

 //  Adult Aphytis dies

   [myCell removeAdultAphytis: self];
   [myCell incrementNumberOfAphytisDeaths];
   [myStats decrementAdultAphytis];
   nullEvent=[eventSchedule remove: moveEvent.eventId];
   [nullEvent drop];
   if( parasitizeEvent.eventId != nil )
   {
      nullEvent=[eventSchedule remove: parasitizeEvent.eventId];
      [nullEvent drop];
   }
   myStats->totalEvents++;
   [self drop];
   return nil;
}

It is much simpler if you don't require concurrent schedules.  I use
them because I use a complete event driven simulation.  This has the
additional advantage that you don't have to worry about randomizing
multiple events that occur during the same time period.  Unfortunatly,
it also means that the event times must be fine grained enough that each
one can be unique, even for a long simulation of say over 1 million time
steps.  This requires a fair number of decimal places, potentially more
than contained in an id.  Luckly for me, I got into Swarm in fairly
early beta and Roger Burkhart was kind enough to come up with the
concurrent group scheduling construct for me.  Thanks again Roger :-)

Hope this helps...

Cheers,

   D3

xueyue wrote:

>  Once an object is created, it can be scheduled when and what actions
> should be executed, and also these actions can be terminated at a
> given time.
> Here my question is: can we dynamically schedule an agent's
> activities? For example, suppose an agent's activities will take place
> during a time space [t1 t2], and during other time, the agent is doing
> nothing. If t1 and t2 are fixed, the activities can be scheduled at
> initial time, however, if t1 and t2 vary
> day by day, how do solve the problem?  To answer this question, we
> need: (1) the agent itself is able
> to schedule its own activities, (2) the agent can send
> schedules to a top level swarm in which all agents'
> schedules exists, (3) the agent is able to request the top level swarm
> to cancel its old schedules and put new schedules into it. In this
> way, the agent's schedule is dynamical and when the agen does not have
> any activities during a time period, the top level do not need to look
> at the agent until the sleeping time is finished.  Hence, the
> computational time can be greatly reduced in some simulation system
> where each agent is only active in  a short period in each day.
> There might be answers to my questions, if anyone knows, please kindly
> let me know.
>
> --
> Dr Xueyue Huang
> Center for Transport Studies
> Imperial College
> London SW7 2BU
>
> (+44) 171 594 6037
>
>

--
*********************************************************************
* Doug Donalson                 Office: (805) 893-2962
* Ecology, Evolution,           Home:   (805) 961-4447
* and Marine Biology            email address@hidden
* UC Santa Barbara
* Santa Barbara Ca. 93106
*********************************************************************
*
*   The most exciting phrase to hear in science, the one that
*   heralds new discoveries, is not "EUREKA" (I have found it) but
*   "That's funny ...?"
*
*       Isaac Asimov
*
*********************************************************************



                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

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