swarm-support
[Top][All Lists]
Advanced

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

Re: Batch Swarm problems


From: pauljohn
Subject: Re: Batch Swarm problems
Date: Fri, 15 Jun 2001 09:23:18 -0500

Katherine Roberts wrote:
> 
> Hello,
> 
> I'm trying to create a very simple batch swarm, no more complicated than
> that of the heatbugs one. However after in the main() function it has
> created the toplevelSwarm, it crashes - it doesn't even go into the
> buildObjects() method in the batchSwarm class. Is there a special
> convention for the naming of the .scm file, and what exactly should that
> file contain?
> 
> Thanks,
> Katherine
> 
In my opinion, the constuction of .scm files is a bit tricky because
they have an exact syntax that you must follow.  These .scm files are
just specifying parameters for  your project, and you do not have to use
them at all. You can always put parameters in the old fashioned way.  I
prefer to have an arguments class where parameter values are specified,
as described in this tutorial addon I prepared last
year:http://lark.cc.ukans.edu/~pauljohn/ps909/simpleObserverBug3-5.tar.gz. 
I did not try that thing in the last few months, but I believe it still
works fine or can easily be made to work.

I think what you need to understand is that the lispAppArchiver routine
like this:
<quote>
 if ((heatbugModelSwarm = [lispAppArchiver getWithZone: self
                                            key: "modelSwarm"]) == nil)
    raiseEvent(InvalidOperation,
               "Can't find the parameters to create modelSwarm");
</q>
Is just a replacement for the ordinary createBegin createEnd of the
ModelSwarm class.  It causes the parameters in the scm file to be used,
rather than the ones that are typed into ModelSwarm. If you go back to
swarmapps, say version 1.4.1, you will see this in a more ordinary form.
I don't have it handy, but it will be something like

       heatbugModelSwarm = [HeatbugModelSwarm create: self];

Since HeatbugModelSwarm has parameter values in it, this works OK. In my
sims, the model swarm layer gets parameter values from the parameter
object, but the idea is the same.
        
I have built programs with .scm, especially big programs can benefit
from that approach, but I don't see much of an advantage to doing it
that way, especially on a first try or a small program. 

I've been working on a program that has batch mode and no scm
tomfoolery, so let me explain.  Here is my main.m and BatchSwarm.m:

:
#import <simtools.h>     // initSwarm () and swarmGUIMode
#import <simtoolsgui.h>  // GUISwarm
#import "ObserverSwarm.h"
#import "BatchSwarm.h"
#import "MyArguments.h"


int
main (int argc, const char **argv)
{
  id theTopLevelSwarm;

  initSwarmArguments (argc, argv, [MyArguments class]);

  //  printf("MyArguments says: %d \n",[arguments getNumpplArg]);
 
  arguments = (id) arguments;
  
  if (swarmGUIMode == 1)
    {
      theTopLevelSwarm = [ObserverSwarm createBegin: globalZone];
      SET_WINDOW_GEOMETRY_RECORD_NAME (theTopLevelSwarm);
      theTopLevelSwarm = [theTopLevelSwarm createEnd];
    }
  else
    theTopLevelSwarm = [BatchSwarm create: globalZone];
  
  [theTopLevelSwarm buildObjects];
  [theTopLevelSwarm buildActions];
  [theTopLevelSwarm activateIn: nil];
  [theTopLevelSwarm go];

  return 0;
}


And here is my BatchSwarm.m:



#import "NhoodProtestValueGrid.h"       
#import "MyArguments.h"
#import "BatchSwarm.h"
#import "ModelSwarm.h"
#import <simtools.h> // ObjectLoader
#import <analysis.h> // EZGraph

#include <misc.h> // printf

@implementation BatchSwarm

// createBegin: here we set up the default observation parameters.

+ createBegin:  aZone 
{
  BatchSwarm *obj;

  // Superclass createBegin to allocate ourselves.
  obj = [super createBegin: aZone];

  // Fill in the relevant parameters.
  obj->displayFrequency = 1;
  obj->experimentDuration = 100;

  return obj;
}

- buildObjects
{
  [super buildObjects];

  modelSwarm = [ModelSwarm create: self];
  [modelSwarm buildObjects];

  if(displayFrequency)
    {
      numPOneprotGraph = [EZGraph createBegin: self];
      [numPOneprotGraph setGraphics: 0] ;
      [numPOneprotGraph setFileOutput: 1] ;
      numPOneprotGraph = [numPOneprotGraph createEnd] ;
    }

   [numPOneprotGraph createSequence: "P1"
                      withFeedFrom:  [modelSwarm getDiscontentGrid]
                       andSelector: M(getPctProtestingTypeOne)];

  return self;
}  

// Create the actions necessary for the simulation. This is where
// the schedule is built (but not run!)

- buildActions 
{
  [super buildActions];
  
  // First, let our model swarm build its own schedule.

  [modelSwarm buildActions];
  
  if(displayFrequency)
    {
    
      displayActions = [ActionGroup create: self];
      
      [displayActions createActionTo: numPOneprotGraph message:
M(step)];
      
      
      displaySchedule = [Schedule createBegin: self];
      [displaySchedule setRepeatInterval: displayFrequency];
      displaySchedule = [displaySchedule createEnd];
      
      [displaySchedule at: 0 createAction: displayActions];
    }
  
    stopSchedule = [Schedule create: self];
  [stopSchedule at: experimentDuration 
               createActionTo: self 
                message: M(stopRunning)];
  return self;
}  

// activateIn: - get the Swarm ready to run.
- activateIn:  swarmContext 
{
  // First, activate ourselves (just pass along the context).
  [super activateIn: swarmContext];
  
  [modelSwarm activateIn: self];
  

  [stopSchedule activateIn: self];
  if (displayFrequency)
    [displaySchedule activateIn: self];
 
 [stopSchedule activateIn: self];
  return [self getActivity];
}


- go 
{
  //  printf ("You typed `-b', so we're running without graphics.\n");

  if (displayFrequency)
      //      printf ("It is display data every %d timesteps to:
unhappiness.output.\n",

  [[self getActivity] run];

  return [[self getActivity] getStatus];
}


- stopRunning2 
{
  [getTopLevelActivity() terminate]; // Terminate the simulation.
  if(displayFrequency)
    [numPOneprotGraph drop] ;              // Close the output file.

  return self;
}

- stopRunning 
{
     
printf ("%04d RUN %07ld timesteps\n", [(id)arguments
getRunArg],getCurrentTime ());

 [modelSwarm finishLog]; 
 [getTopLevelActivity() terminate]; // Terminate the simulation.    
 if(displayFrequency)
   [numPOneprotGraph drop] ;              // Close the output file.
 return self;
}
@end




-- 
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                FAX: (785) 864-5700

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