swarm-support
[Top][All Lists]
Advanced

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

Sub-swarm schedule activation/swarmContext question


From: Ken Cline
Subject: Sub-swarm schedule activation/swarmContext question
Date: Thu, 19 Jun 1997 19:27:59 -0400 (EDT)

Hi all,

Schedule activation question for y'all:

   I was having a problem activating a sub-swarm's schedule
when the sub-swarm was created *after* my (top level) 
ModelObserver swarm has already been activated. I found a
way to make it work but I'm not sure I understand why it
works...

   The only difference between the version that does not
work and the version the does work is that I changed the
following line (in the sub-swarm's "activateIn" method) 
from:
      [ displaySchedule activateIn: self         ];
to:
      [ displaySchedule activateIn: swarmContext ];

That is, 
   IF I create the sub-swarm after the ModelObserver has
      already been activated,
   AND IF the sub-swarm's displaySchedule is activated
      "in the context of" of the sub-swarm (as is typical of
      other swarms),
   THEN the displaySchedule is *not* executed.

However,
   IF I create the sub-swarm after the ModelObserver has
      already been activated (as before),
   AND IF the sub-swarm's displaySchedule is activated
      "in the context of" of the ModelObserver,
   THEN the displaySchedule *is* executed.

I suspect this has something to do with tying the
sub-swarm's displaySchedule to already active schedule but
I haven't found anything specific in either the
documentation or mailing list archives that clearly explains
(to me) exactly why this is so.


Further description of my application...

Background:
   I've been trying to follow the design philosophy of
keeping the observer object hierarchy separate from the
model/agent object hierarchy.  (An idea I picked up after
reading one of (glen's?) postings.)

   The following diagram sort of shows how I'm trying to
construct the application:

          Observers                 Model/Agents
      ----------------------------------------------
         ModelObserver  -observes->  ModelSwarm
              |                          |
           creates                    creates
              |                          |
              V                          V
         AgentObserver  -observes->    Agent


Details:
   The AgentObserver is *not* automatically created when the
ModelObserver is created, instead the user has the option to
create an AgentObserver via the ModelObserver's probe.

   Everything works as I had expected except that the
AgentObserver's displaySchedule is only executed if the
AgentObserver is created *before* the ModelObserver's
"activateIn" method is called.

   For example this is what happens when the AgentObserver
is created *before* the ModelObserver's "activatedIn" method
is called:
      % app
      Simulation is running in 'GUI/Observer' mode.
      Simulation started on Thu Jun 19 1997 at 15:41:41

           ModelObserver: createBegin method ... 
           ModelObserver: buildProbe method ... 
           ModelObserver: buildObjects method ... 
      < User GUI Action: "Create_Agent_Observer" >
           ModelObserver: Create_Agent_Observer method ... 
           AgentObserver: createBegin method... 
           AgentObserver: buildProbe method... 
           AgentObserver: setAgent method... 
           AgentObserver: buildObjects method... 
           AgentObserver: buildActions method... 
      < User GUI Action: "Go" >
           ModelObserver: buildActions method ... 
           ModelObserver: activateIn method ... 
           AgentObserver: activateIn method... 
      [grin]  [grin]  [grin]  [grin]  [grin]  [grin]  
      < User GUI Action: "Stop" >
      < User GUI Action: "Quit" >

      Simulation completed on Thu Jun 19 1997 at 15:42:42
      %

   Now this is what happens when the AgentObserver is
created *after* the ModelObserver's "activateIn" method
has been called:
      % app
      Simulation is running in 'GUI/Observer' mode.
      Simulation started on Thu Jun 19 1997 at 15:37:52

           ModelObserver: createBegin method ... 
           ModelObserver: buildProbe method ... 
           ModelObserver: buildObjects method ... 
      < User GUI Action: "Go" >
           ModelObserver: buildActions method ... 
           ModelObserver: activateIn method ... 
      < User GUI Action: "Stop" >
      < User GUI Action: "Create_Agent_Observer" >
           ModelObserver: Create_Agent_Observer method ... 
           AgentObserver: createBegin method... 
           AgentObserver: buildProbe method... 
           AgentObserver: setAgent method... 
           AgentObserver: buildObjects method... 
           AgentObserver: buildActions method... 
           AgentObserver: activateIn method... 
      < User GUI Action: "Go" >
      < There should be "[grin]"s here! >
      < User GUI Action: "Stop" >
      < User GUI Action: "Quit" >

      Simulation completed on Thu Jun 19 1997 at 15:40:17
      %

However, if I make the change to AgentObserver's 
"activateIn" method as described above then I am able to get
the AgentObserver's displaySchedule to execute no matter
when the AgentObserver is created.

That is, in the AgentObserver class, I have:

-activateIn: (id) swarmContext {
   [ super           activateIn: swarmContext ];
   [ displaySchedule activateIn: swarmContext ];
   return [ self getSwarmActivity ];
}

instead of:

-activateIn: (id) swarmContext {
   [ super           activateIn: swarmContext ];
   [ displaySchedule activateIn: self         ];
   return [ self getSwarmActivity ];
}


BTW, here's the rest of the relevant code:

ModelObserver.m:
-----------------------------
 
@implementation ModelObserver

+createBegin: (id) aZone {
      ...
   newModelObserver->displayFrequency = 1;
   newModelObserver->agentObserver = NULL;
   [ newModelObserver buildProbe ];
   newModelObserver->activated = FALSE;
      ...
}

-buildObjects {
      ...
   [ controlPanel waitForControlEvent ];
   if ( [controlPanel getState] == ControlStateQuit )
      return self;
      ...
}  

-buildActions {
      ...
   displaySchedule = [ Schedule createBegin: [self getZone] ];
      [ displaySchedule setRepeatInterval: displayFrequency ];
   displaySchedule = [ displaySchedule createEnd ];

   displayActions = [ ActionGroup create: [self getZone] ];
      [ displayActions createActionTo: probeDisplayManager
                              message: M(update)     ];
      [ displayActions createActionTo: controlPanel
                              message: M(doTkEvents) ];

   [ displaySchedule at: 0 createAction: displayActions ];
      ...
}  

-activateIn: (id) swarmContext {
   [ super activateIn: swarmContext ];

   [ modelSwarm      activateIn: self ];
   [ displaySchedule activateIn: self ];

   if ( agentObserver != NULL )
      [ agentObserver activateIn: self ];

   activated = TRUE;

   return [ self getSwarmActivity ];
}


-(void) buildProbe {
      ...
   [ probeMap addProbe:
      [probeLibrary getProbeForMessage: "Create_Agent_Observer"
                               inClass: [self class]]   ];
      ...
}

-(void) Create_Agent_Observer {
      ...
   if ( agentObserver != NULL ) return;

   agentObserver = [ AgentObserver create: [self getZone] ];

   if ( modelSwarm != NULL )
      [ agentObserver setAgent: [modelSwarm getAgent] ];

   [ agentObserver buildObjects ];
   [ agentObserver buildActions ];

   if ( activated == TRUE )
      [ agentObserver activateIn: self ];
}

@end


AgentObserver.m:
-----------------------------

@implementation AgentObserver

+createBegin: (id) aZone {
      ...
   newAgentObserver->displayFrequency = 1;
   newAgentObserver->agent = NULL;
   [ newAgentObserver buildProbe ];
      ...
}

-(void) setAgent: (id <Agent>) anAgent {
   agent = anAgent;
}

-buildObjects {
      ...
   [ probeDisplayManager createProbeDisplayFor: self ];
      ...
}  

-buildActions {
   [ super buildActions ];

   displaySchedule = [ Schedule createBegin: [self getZone] ];
      [ displaySchedule setRepeatInterval: displayFrequency ];
   displaySchedule = [ displaySchedule createEnd ];
        
   displayActions = [ ActionGroup create: [self getZone] ];
      [ displayActions createActionTo: self message: M(grin) ];

   [ displaySchedule at: 0 createAction: displayActions ];
      ...
}

-activateIn: (id) swarmContext {
      ...
   [ super           activateIn: swarmContext ];
   [ displaySchedule activateIn: swarmContext ];
   return [ self getSwarmActivity ];
}

-(void) grin {
   fprintf(stderr,"[grin]  ");
}

-(void) buildProbe {
      ...
}

@end


I also tried different time values to schedule the
"displayAction" at.  For example I also tried:
   [ displaySchedule at: getCurrentTime() createAction: displayActions ];
and
   [ displaySchedule at: (getCurrentTime() + 1) createAction: displayActions ];

but neither of these made a difference (actually the last
attempt raised InvalidArgument errors).

I apologise for putting so much code in this posting but I
was at a loss of how to explain the question clearly in
another way.

Thanks in advance for helping me better understand how the
scheduling mechanisms work.


Ken.

PS: I also welcome any comments about my design or
implementation; I'm sure there are many, many, more ways
which I haven't thought of ...


_________________________________________________________
Ken Cline                             address@hidden
SAIC                                 VOICE (410) 571-0413
Annapolis, MD                          FAX (301) 261-8427





                  ==================================
   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]