swarm-support
[Top][All Lists]
Advanced

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

Re: Displaying before running: SUCCESS


From: Sven Thommesen
Subject: Re: Displaying before running: SUCCESS
Date: Sat, 12 Jul 1997 18:03:43 -0500

At 06:14 PM 7/11/97 +0200, Nelson Minar wrote:
>Several of my students have a very natural question - they want to
>display the state of the world at time 0. That way they can see the
>initial conditions of the system.
>
>However, I can't figure out how to make that happen with the standard
>ModelSwarm / ObserverSwarm split. The problem is both schedules have
>an action at time 0. But it's magic behind the scenes which actions
>happen first.
>
>Back when we designed this whole mess we talked a lot about making
>sure that people could specify relative ordering of actions in these
>circumstanecs. Is that possible in this case? If so, how?
>


Looks like success here! Nothing like spending all Saturday fiddling with
this kind of stuff -- but solving problems *is* fun!

The standard sequence of things (in heatbugs and clones) is:

modelSwarm buildActions:
        spaces do diffusion, evaporation, update
        agents do step
        spaces do update

displaySchedule, which contains displayActions:
        heatDisplay         does display        (heat values)
        heatbugDisplay      does display        (heatbugs)
        worldHeatRaster     does drawself       (updating the raster)
        probeDisplayManager does update
        controlPanel        does doTkEvents

after all of which I had put my startHaltingSchedule.

What we *want* is the displayActions, minus doTkEvents, to take place
*before anything else*, and then we halt the sim.

So, I created a new schedule containing all the display actions except
doTkEvents, and activated this schedule the very first, followed by my
startHaltingSchedule, *before* letting modelSwarm activate. 

When I did that, the effect was the desired one! :-)

I have appended to this message an excerpt of my ObserverSwarm, showing
most of methods -buildActions and -activateIn. 

Let me know if this works for anyone else.

Cheers,
--Sven

// --------------------------------------------------------------
// Sven Thommesen <address@hidden>
//
// Excerpt from ObserverSwarm.m
// showing a way to halt the display at t=0 so as to see
// the initial configuration.
//

-buildActions {
   SEL sel1;
   unsigned dataMode, test;
   char *  heatName = "STATE.heat";
   char * lightName = "STATE.light";
   char * waterName = "STATE.water";

  [super buildActions];
 
// 1. Let the spaces and bugs to their thing: 

  [fashionbugModelSwarm buildActions];

// 1b. Let dataLogger update its time base:

  timeDisplaySchedule = [Schedule createBegin: [self getZone]];
  [timeDisplaySchedule  setRepeatInterval: 1];
  timeDisplaySchedule = [timeDisplaySchedule createEnd];
  [timeDisplaySchedule at: 0 
           createActionTo: dataLogger 
                  message: M(updateSimTime)];


// 2a. Determine the frequency of Averager updating:

   // see method -initState

// 2b. Have the Averagers collect data from the bugs:

  averagerActions = [ActionGroup create: [self getZone]];

  [averagerActions createActionTo: generatedIAAverager message: M(update)];
  [averagerActions createActionTo: activatedFLAverager message: M(update)];
  [averagerActions createActionTo:   unhappyFLAverager message: M(update)];
  [averagerActions createActionTo:   unhappyFFAverager message: M(update)];
 
  averagerUpdateSchedule = [Schedule createBegin: [self getZone]];
  [averagerUpdateSchedule setRepeatInterval: averagerUpdateFrequency];
  averagerUpdateSchedule = [averagerUpdateSchedule createEnd];
  [averagerUpdateSchedule at: averagerUpdateFrequency-1 
                createAction: averagerActions];
 
// 3. Create actions to make swarms, spaces and agents output data:

      // <.. stuff deleted ..>

  // Now put those actions into a schedule:

  dataSamplingSchedule = [Schedule createBegin: [self getZone]];
  [dataSamplingSchedule setRepeatInterval: dataSamplingFrequency];
  dataSamplingSchedule = [dataSamplingSchedule createEnd];
  [dataSamplingSchedule at: dataSamplingFrequency-1 
                  createAction: dataSamplingActions];

// 4. Display spaces and bugs and Averager graphs: 

  displayActions = [ActionGroup create: [self getZone]];

  // Display water and waterbugs on water raster:
  [displayActions createActionTo: waterDisplay         message: M(display)];
  [displayActions createActionTo: waterbugDisplay      message: M(display)];
  [displayActions createActionTo: worldWaterRaster     message: M(drawSelf)];

  // Display light and lightbugs on light raster:
  [displayActions createActionTo: lightDisplay         message: M(display)];
  [displayActions createActionTo: lightbugDisplay      message: M(display)];
  [displayActions createActionTo: worldLightRaster     message: M(drawSelf)];

  // Display heat and heatbugs on heat raster:
  [displayActions createActionTo: heatDisplay          message: M(display)];
  [displayActions createActionTo: heatbugDisplay       message: M(display)];
  [displayActions createActionTo: worldHeatRaster      message: M(drawSelf)];

  // Display all bugs on the worldRaster:
  [displayActions createActionTo: worldAgentRaster     message: M(erase)];
  [displayActions createActionTo: waterbugBDisplay     message: M(display)];
  [displayActions createActionTo: lightbugBDisplay     message: M(display)];
  [displayActions createActionTo: heatbugBDisplay      message: M(display)];
  [displayActions createActionTo: worldAgentRaster     message: M(drawSelf)];

  // Display the 4 graphs on the BLTgraph window:

  [displayActions createActionTo: generatedIAGrapher  message: M(step)];
  [displayActions createActionTo: activatedFLGrapher  message: M(step)];
  [displayActions createActionTo:   unhappyFLGrapher  message: M(step)];
  [displayActions createActionTo:   unhappyFFGrapher  message: M(step)];

  // Update probes:

  [displayActions createActionTo: probeDisplayManager  message: M(update)];

// displaySchedule updates the displays every t (if displayFrequency=1):

  displaySchedule = [Schedule createBegin: [self getZone]];
  [displaySchedule setRepeatInterval: displayFrequency];
  displaySchedule = [displaySchedule createEnd];
  [displaySchedule at: displayFrequency-1 
         createAction: displayActions];

// startDisplaySchedule executes once (at start of t=0), see -activateIn
  startDisplaySchedule = [Schedule create: [self getZone]];
  [startDisplaySchedule at: 0
              createAction: displayActions ];

// Update the tk event scheduler (check the control panel):
// (separated out from displayActions)

  tkEventSchedule = [Schedule createBegin: [self getZone]];
  [tkEventSchedule  setRepeatInterval: displayFrequency];
  tkEventSchedule = [tkEventSchedule createEnd];
  [tkEventSchedule at: displayFrequency-1 
       createActionTo: controlPanel 
              message: M(doTkEvents)];

// 5a. Halt display at start, to see initial configuration:
//     (a one-time action, in the middle of time period 0)
  
  startHaltingSchedule = [Schedule create: [self getZone]];
  [startHaltingSchedule at: 0
            createActionTo: controlPanel 
                   message: M(setStateStopped)];

// 5b. Create a schedule to halt the display now and then: 

  if (haltingFrequency > 0) {

  haltingSchedule = [Schedule createBegin: [self getZone]];
  [haltingSchedule  setRepeatInterval: haltingFrequency];
  haltingSchedule = [haltingSchedule createEnd];
  [haltingSchedule at: haltingFrequency-1 
       createActionTo: controlPanel 
              message: M(setStateStopped)];

  } // if no halting, don't create schedule

// 6. Finally, create a schedule to stop at end of time:

  if (endOfSimTime > 0) {

 stopActions = [ActionGroup create: [self getZone]];
 [stopActions createActionTo:  heatDumper message: M(fileTo:): (id)  heatName];
 [stopActions createActionTo: lightDumper message: M(fileTo:): (id) lightName];
 [stopActions createActionTo: waterDumper message: M(fileTo:): (id) waterName];
 [stopActions createActionTo: controlPanel message: M(setStateStopped)];

  stopSchedule = [Schedule create: [self getZone]];
//  [stopSchedule at: (endOfSimTime - 1)
//    createActionTo: controlPanel 
//           message: M(setStateStopped)];

  [stopSchedule at: (endOfSimTime -1) createAction: stopActions];

  } // if no end of time, don't create schedule

  // Note: we merely halt execution  with setStateStopped,
  // rather than use [getTopLevelActivity() terminate] as in
  // the batch swarm; this way the user can see the final
  // state of graphs and bug displays and dismiss the sim manually.


// Now take care of varprobe/graph/bugdisplay placement:

  [self placeWidgets];

  return self;
}  

-activateIn: (id) swarmContext {

  [super activateIn: swarmContext];

// 4x. //
  [   startDisplaySchedule activateIn: self ];   // <-- update the display

// 5a. //
  [   startHaltingSchedule activateIn: self ];   // <-- halt & wait for 'go'

// 1a. bugs and spaces //
  [   fashionbugModelSwarm activateIn: self ];

// 1b. //
  [    timeDisplaySchedule activateIn: self ];

// 2b. //
  [ averagerUpdateSchedule activateIn: self ];

// 3. //
  if (modeOfDataOutput > 0) 
  [   dataSamplingSchedule activateIn: self ];

// 4. //
  [        displaySchedule activateIn: self ];
  [        tkEventSchedule activateIn: self ];

// 5b. //
  if (haltingFrequency > 0)
  [        haltingSchedule activateIn: self ];

// 6. //
  if (endOfSimTime > 0)
  [           stopSchedule activateIn: self ];

  return [self getSwarmActivity];
}

// 
// ------------------------------------------------------------


reply via email to

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