swarm-support
[Top][All Lists]
Advanced

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

Re: example of probes


From: Benedikt Stefansson
Subject: Re: example of probes
Date: Fri, 25 Apr 1997 15:36:26 -0700

Hi,

Peter Deadman asked about examples of attaching probes to your own
agents. Here is my current implementation in a class called
SimpleDataSet, which is created for the purpose of gathering data on an
arbitrary variable from all agents in a collection of agents, and pipe
this to an ascii file, where each line corresponds to a period and each
column to the data from the particular agent for that period.

I should also explain that instances of SimpleDataSet are created by a
superagent called DataFile, which attaches a probe to a method on each
of the corresponding agents which checks if they were active in a given
period; this allows SimpleDataSet to put a " . " field in the
corresponding column in the outfile if there is no data for this agent
for a given period.

I copied the code below and adde some simple comments

@implementation SimpleDataSet

-setDataSet: (char *) t withFeedFrom: d andSelector: (SEL) s {
 title=t;
 theCollection=d;
 theSelector=s;

 return self;
}

---
Comment: You would call the method -setDataSet:withFeedFrom:andSelector
as:

[simpleDataSet setDataSet: "some name" withFeedFrom: aCollection
andSelector: M(aMethod)];

Of course the method aMethod has to be defined in the underlying agents.

---

-setManager: (id) tO {
 theManager=tO;
 return self;
}

----
This simplifies the "is agent inactive?" update - the superagent
DataFile creates one probe for the method that will reveal agent
activity/inactivity, so that each SimpleDataSet does not have to create
two probes, one for the data we are interested in, one for the "is agent
inactive?" question.
---

-createEnd {

 round=0; // Keeps track of the time variable
 theFile=fopen(title,"w"); // The file to print to

 if(!theFile){
      fprintf(stderr,"Unable to open %s as an outfile!\n",title);
      return nil ;
   }

// Here the probe is created. MessageProbe is a class from the
// probe library
  probe=[MessageProbe createBegin: [self getZone]];
  [probe setProbedSelector: theSelector];
  probe=[probe createEnd];


 return self;
}

---
And the following is my particular "step" function for the SimpleDataSet
class - invoked
by the superagent DataFile - just to give you an example of how the
probe works in practice.
---

-step {
 id index,theMember;
 int data=0;
 int dataA=0,dataB=0;

 // Start by printing the # of the current round
 round++;
 fprintf(theFile,"%4d| ",round);

 // Now iterate through the collection and ask
 // for the data, then print it to the outfile
 index=[theCollection begin: [self getZone]];
 while((theMember=[index next])) {
      data=[probe doubleDynamicCallOn: theMember];
      if([theManager checkDeath: theMember]==1) {
       fprintf(theFile," .  "); // Member inactive
          } else {
           fprintf(theFile,"%3d ",data);
      }
 }
 [index drop];

 // Carriage return
 fprintf(theFile,"\n");

 return self;
}

----
Note the statement
    if([theManager checkDeath: theMember]==1)

Here the SimpleDataSet instance checks with the DataFile superagent to
see if the particular member of the agent collection is "dead" (I chose
this frivolous term to mean inactive). The corresponding method in the
DataFile class (which is pointed to by the instance variable theManager)
is:

-(int)checkDeath: (id) anAgent {
 // If the user didn't set a death probe
 // we just assume that agents are always active
 if([deathProbe doubleDynamicCallOn: anAgent]==1) return 1;
 else return 0;
}

I.e. if the deathProbe returns 1, meaning active, then theManager
returns 1, else 0.

@end

That's it more or less. I hope this helps you along.

Regards,
-Benedikt

----------------
Benedikt Stefansson                 address@hidden
Center for Computable Economics     Tel. (310) 825-1777
Department of Economics, UCLA       Fax. (310) 825-9528
Los Angeles, CA 90095-1477          http://cce.sscnet.ucla.edu


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