[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Vacation
From: |
Manor Askenazi |
Subject: |
Vacation |
Date: |
Fri, 26 Jul 96 19:58:07 MDT |
Aloha!
Just a short email to say that the help-desk will be closed again until
the 6th of August... I hope some of the more experienced beta-testers
amongst you will cover for us during this period :-)
So that you don't feel completely cheated by this defection into
vacation-land, I am posting three new classes which you can add to
your installation of Swarm without having to recompile everything
from scratch: EZGraph, UName and Entropy.
Also, I'd like to report that our local development version of Swarm
now has scrollbars on the Probes, a -batchmode flag, and a basic
framework for loading objects from files (more on this when I return).
See y'all soon,
Manor.
PS> The EZGraph class is meant to reduce the need for dozens of objects
just to get a few graphs going. It is used as follows...
Example code from heatbugs:
---------------------------
// Create the graph widget to display unhappiness.
unhappyGraph = [EZGraph createBegin: [self getZone]];
[unhappyGraph setTitle: "Unhappiness of bugs vs. time"];
[unhappyGraph setAxisLabelsX: "time" Y: "unhappiness"];
unhappyGraph = [unhappyGraph createEnd] ;
[unhappyGraph createAverageSequence: "average unhappiness"
withFeedFrom: [heatbugModelSwarm getHeatbugList]
andSelector: M(getUnhappiness)] ;
[unhappyGraph createMinSequence: "minimum unhappiness"
withFeedFrom: [heatbugModelSwarm getHeatbugList]
andSelector: M(getUnhappiness)] ;
[unhappyGraph createMaxSequence: "maximum unhappiness"
withFeedFrom: [heatbugModelSwarm getHeatbugList]
andSelector: M(getUnhappiness)] ;
------------------------------------------------------------------------
In order to add the first two classes, you will need to drop the following
four files into ..whatever../swarm/src/simtools and edit the makefile as
follows:
----------------------
SWARMHOME=../..
LIBNAME=simtools
OBJECTS=<<<loads of .o files...>>> EZGraph.o UName.o
HEADERS=<<<loads of .h files...>>> EZGraph.h UName.h
include $(SWARMHOME)/Makefile.lib
<<<loads of make rules>>>
EZGraph.o: EZGraph.m EZGraph.h
UName.o: UName.m UName.h
----------------------
Also you will need to edit the simtools.h file as follows:
----------------------
<<<loads of #import lines>>>
#import <simtools/EZGraph.h>
#import <simtools/UName.h>
----------------------
Now simply type make.
The files to add are:
=============================== UName.h ====================================
// Swarm library. Copyright (C) 1996 Santa Fe Institute.
// This library is distributed without any warranty; without even the
// implied warranty of merchantability or fitness for a particular purpose.
// See file LICENSE for details and terms of copying.
// Unique Name Generator -> used to create names (using a base string "critter"
// it generates "critter1", "critter2", etc. etc.
#import <swarmobject.h>
@interface UName : SwarmObject {
int counter ;
id baseString ;
}
+create: aZone setBaseName: (char *) aString ;
+create: aZone setBaseNameObject: aStringObject ;
-setBaseName: (char *) aString ;
-setBaseNameObject: aStringObject ;
-(char *)getNewName ;
-getNewNameObject ;
-resetCounter ;
@end
============================================================================
=============================== UName.m ====================================
// Swarm library. Copyright (C) 1996 Santa Fe Institute.
// This library is distributed without any warranty; without even the
// implied warranty of merchantability or fitness for a particular purpose.
// See file LICENSE for details and terms of copying.
#define __USE_FIXED_PROTOTYPES__ // for gcc headers
#import <stdlib.h>
#import <string.h>
#import <collections/String.h>
#import "UName.h"
@implementation UName
+ create: aZone setBaseName: (char *) aString{
id obj;
obj = [super createBegin: aZone] ;
[obj setBaseName: aString] ;
[obj createEnd] ;
return obj ;
}
+ create: aZone setBaseNameObject: aStringObject{
id obj;
obj = [super create: aZone] ;
[obj setBaseNameObject: aStringObject] ;
[obj createEnd] ;
return obj ;
}
-resetCounter {
counter = 0 ;
return self ;
}
-setBaseName: (char *) aString {
baseString = [String create: [self getZone] setC: aString] ;
return self ;
}
-setBaseNameObject: aStringObject {
baseString = aStringObject ;
return self ;
}
-createEnd {
if(!baseString){
fprintf(stderr,
"No Base Name was given when creating a UName object...\n") ;
exit(-1) ;
}
[super createEnd] ;
[self resetCounter] ;
return self ;
}
-(char *)getNewName {
id aCopy ;
char suffix[11] ;
char *result ;
aCopy = [self copy] ;
sprintf(suffix,"%d",counter) ;
counter++ ;
[aCopy appendC: suffix] ;
result = strdup([aCopy getC]) ;
[aCopy drop] ;
return result ;
}
-getNewNameObject {
id aCopy ;
char suffix[11] ;
aCopy = [self copy] ;
sprintf(suffix,"%d",counter) ;
counter++ ;
[aCopy appendC: suffix] ;
return aCopy ;
}
@end
============================================================================
=============================== EZGraph.h ==================================
// Swarm library. Copyright (C) 1996 Santa Fe Institute.
// This library is distributed without any warranty; without even the
// implied warranty of merchantability or fitness for a particular purpose.
// See file LICENSE for details and terms of copying.
// Simple Graph Object -> encapsulates many of the low-level objects
// required to get graphs to work...
#import <swarmobject.h>
@class EZGraph;
@class EZSequence;
@class EZAverageSequence;
@interface EZGraph : Widget {
id sequenceList ;
id theGraph ;
// int graphics ;
char * suffix ;
char * xLabel ;
char * yLabel ;
char * title ;
}
// -setGraphics: (int) state ;
// -setSuffix: (char *) aSuffix ;
-setTitle: (char *) aTitle ;
-setAxisLabelsX: (char *) xl Y: (char *) yl ;
-createEnd ;
-getGraph ;
-createSequence: (char *) aName
withFeedFrom: anObj
andSelector: (SEL) aSel ;
-createAverageSequence: (char * ) aName
withFeedFrom: aList
andSelector: (SEL) aSel ;
-createTotalSequence: (char *) aName
withFeedFrom: aList
andSelector: (SEL) aSel ;
-createMinSequence: (char *) aName
withFeedFrom: aList
andSelector: (SEL) aSel ;
-createMaxSequence: (char *) aName
withFeedFrom: aList
andSelector: (SEL) aSel ;
-createCountSequence: (char *) aName
withFeedFrom: aList
andSelector: (SEL) aSel ;
-step ;
@end
@interface EZSequence : ActiveGraph {
// FILE *theFile ;
}
-step ;
@end
@interface EZAverageSequence : SwarmObject {
id theAverager ;
id theGrapher ;
}
-setAverager: anAverager ;
-setGrapher: aGrapher ;
-step ;
@end
============================================================================
=============================== EZGraph.m ==================================
// Swarm library. Copyright (C) 1996 Santa Fe Institute.
// This library is distributed without any warranty; without even the
// implied warranty of merchantability or fitness for a particular purpose.
// See file LICENSE for details and terms of copying.
#import <collections.h>
#import <tkobjc.h>
#import "EZGraph.h"
@implementation EZGraph
+createBegin: aZone {
id obj ;
obj = [super createBegin: aZone] ;
// [obj setSuffix: ""] ;
[obj setTitle: ""] ;
[obj setAxisLabelsX: "" Y: ""] ; //find out what happens if I forget this!
// [obj setGraphics: 1] ;
return obj ;
}
/*
-setGraphics: (int) state {
graphics = state ;
return self ;
}
-setSuffix: (char *) aSuffix {
suffix = aSuffix ;
return self ;
}
*/
-setAxisLabelsX: (char *) xl Y: (char *) yl {
xLabel = xl ;
yLabel = yl ;
return self ;
}
-setTitle: (char *) aTitle {
title = aTitle ;
return self ;
}
-createEnd {
// if(graphics){
theGraph = [BLTGraph create: [self getZone]];
[theGraph title: title] ;
[theGraph axisLabelsX: xLabel Y: yLabel];
[theGraph pack];
// }
sequenceList = [List create: [self getZone]] ;
return self ;
}
-getGraph {
return theGraph ;
}
-createSequence: (char *) aName
withFeedFrom: anObj
andSelector: (SEL) aSel {
id aSeq ;
id anElement ;
anElement = [theGraph createElement] ;
[anElement setLabel: aName] ;
aSeq = [EZSequence createBegin: [self getZone]] ;
[aSeq setDataFeed: anObj] ;
[aSeq setElement: anElement] ;
[aSeq setProbedSelector: aSel] ;
[aSeq createEnd] ;
[sequenceList addLast: aSeq] ;
return self ;
}
-createAverageSequence: (char *) aName
withFeedFrom: aList
andSelector: (SEL) aSel {
id aSeq ;
id anAverager ;
id aGrapher ;
id anElement ;
anElement = [theGraph createElement] ;
[anElement setLabel: aName] ;
anAverager = [Averager createBegin: [self getZone]];
[anAverager setList: aList];
[anAverager setProbedSelector: aSel];
anAverager = [anAverager createEnd];
aGrapher = [ActiveGraph createBegin: [self getZone]];
[aGrapher setElement: anElement];
[aGrapher setDataFeed: anAverager];
[aGrapher setProbedSelector: M(getAverage)];
aGrapher = [aGrapher createEnd];
aSeq = [EZAverageSequence create: [self getZone]] ;
[aSeq setAverager: anAverager] ;
[aSeq setGrapher: aGrapher] ;
[sequenceList addLast: aSeq] ;
return self ;
}
-createTotalSequence: (char *) aName
withFeedFrom: aList
andSelector: (SEL) aSel {
id aSeq ;
id anAverager ;
id aGrapher ;
id anElement ;
anElement = [theGraph createElement] ;
[anElement setLabel: aName] ;
anAverager = [Averager createBegin: [self getZone]];
[anAverager setList: aList];
[anAverager setProbedSelector: aSel];
anAverager = [anAverager createEnd];
aGrapher = [ActiveGraph createBegin: [self getZone]];
[aGrapher setElement: anElement];
[aGrapher setDataFeed: anAverager];
[aGrapher setProbedSelector: M(getTotal)];
aGrapher = [aGrapher createEnd];
aSeq = [EZAverageSequence create: [self getZone]] ;
[aSeq setAverager: anAverager] ;
[aSeq setGrapher: aGrapher] ;
[sequenceList addLast: aSeq] ;
return self ;
}
-createMinSequence: (char *) aName
withFeedFrom: aList
andSelector: (SEL) aSel {
id aSeq ;
id anAverager ;
id aGrapher ;
id anElement ;
anElement = [theGraph createElement] ;
[anElement setLabel: aName] ;
anAverager = [Averager createBegin: [self getZone]];
[anAverager setList: aList];
[anAverager setProbedSelector: aSel];
anAverager = [anAverager createEnd];
aGrapher = [ActiveGraph createBegin: [self getZone]];
[aGrapher setElement: anElement];
[aGrapher setDataFeed: anAverager];
[aGrapher setProbedSelector: M(getMin)];
aGrapher = [aGrapher createEnd];
aSeq = [EZAverageSequence create: [self getZone]] ;
[aSeq setAverager: anAverager] ;
[aSeq setGrapher: aGrapher] ;
[sequenceList addLast: aSeq] ;
return self ;
}
-createMaxSequence: (char *) aName
withFeedFrom: aList
andSelector: (SEL) aSel {
id aSeq ;
id anAverager ;
id aGrapher ;
id anElement ;
anElement = [theGraph createElement] ;
[anElement setLabel: aName] ;
anAverager = [Averager createBegin: [self getZone]];
[anAverager setList: aList];
[anAverager setProbedSelector: aSel];
anAverager = [anAverager createEnd];
aGrapher = [ActiveGraph createBegin: [self getZone]];
[aGrapher setElement: anElement];
[aGrapher setDataFeed: anAverager];
[aGrapher setProbedSelector: M(getMax)];
aGrapher = [aGrapher createEnd];
aSeq = [EZAverageSequence create: [self getZone]] ;
[aSeq setAverager: anAverager] ;
[aSeq setGrapher: aGrapher] ;
[sequenceList addLast: aSeq] ;
return self ;
}
-createCountSequence: (char *) aName
withFeedFrom: aList
andSelector: (SEL) aSel {
id aSeq ;
id anAverager ;
id aGrapher ;
id anElement ;
anElement = [theGraph createElement] ;
[anElement setLabel: aName] ;
anAverager = [Averager createBegin: [self getZone]];
[anAverager setList: aList];
[anAverager setProbedSelector: aSel];
anAverager = [anAverager createEnd];
aGrapher = [ActiveGraph createBegin: [self getZone]];
[aGrapher setElement: anElement];
[aGrapher setDataFeed: anAverager];
[aGrapher setProbedSelector: M(getCount)];
aGrapher = [aGrapher createEnd];
aSeq = [EZAverageSequence create: [self getZone]] ;
[aSeq setAverager: anAverager] ;
[aSeq setGrapher: aGrapher] ;
[sequenceList addLast: aSeq] ;
return self ;
}
-step {
[sequenceList forEach: M(step)] ;
return self ;
}
@end
@implementation EZSequence
/*
-setFile: (FILE *) aFile {
theFile = aFile ;
return self ;
}
*/
-step {
[super step] ;
// if(theFile)
// fprintf(theFile, "%g\n", [self doubleDynamicCallOn: dataFeed]) ;
return self ;
}
-(void) drop {
[super drop] ;
// fclose(theFile) ;
}
@end
@implementation EZAverageSequence
-setAverager: anAverager {
theAverager = anAverager ;
return self ;
}
-setGrapher: aGrapher{
theGrapher = aGrapher ;
return self ;
}
-step {
[theAverager update] ;
[theGrapher step] ;
// if(theFile)
// fprintf(theFile, "%g\n", [theAverager doubleDynamicCallOn: dataFeed]) ;
return self ;
}
-(void) drop {
[super drop] ;
[theAverager drop] ;
[theGrapher drop] ;
// fclose(theFile) ;
}
@end
============================================================================
In order to add the last class, you will need to drop the following
two files into ..whatever../swarm/src/swarmobject and edit the makefile
as follows:
----------------------
SWARMHOME=../..
LIBNAME=swarmobject
OBJECTS=<<<loads of .o files...>>> Entropy.o
HEADERS=<<<loads of .h files...>>> Entropy.h
include $(SWARMHOME)/Makefile.lib
<<<loads of make rules>>>
Entropy.o: Entropy.m Entropy.h
----------------------
Also you will need to edit the simtools.h file as follows:
----------------------
<<<loads of #import lines>>>
#import <swarmobject/Entropy.h>
----------------------
Now simply type make.
The files to add are:
=============================== Entropy.h ==================================
// Swarm library. Copyright (C) 1996 Santa Fe Institute.
// This library is distributed without any warranty; without even the
// implied warranty of merchantability or fitness for a particular purpose.
// See file LICENSE for details and terms of copying.
#import <swarmobject/MessageProbe.h>
// Entropy object.
@interface Entropy : MessageProbe {
double entropy;
id list;
}
-setList: (id) list;
-createEnd;
-update;
-(double) getEntropy;
@end
============================================================================
=============================== Entropy.m ==================================
// Swarm library. Copyright (C) 1996 Santa Fe Institute.
// This library is distributed without any warranty; without even the
// implied warranty of merchantability or fitness for a particular purpose.
// See file LICENSE for details and terms of copying.
#define __USE_FIXED_PROTOTYPES__ // for gcc headers
#import <math.h>
#import <collections.h>
#import <swarmobject/Entropy.h>
@implementation Entropy
-setList: (id) l {
list = l;
return self;
}
-createEnd {
if (list == nil)
[InvalidCombination raiseEvent: "Entropy created without a list\n"];
return [super createEnd];
}
-update {
id iter, obj ;
double maximum ;
int count ;
entropy = 0.0;
count = [list getCount] ;
if(!count)
return self;
maximum = log( 1.0 / ((double) count)) ;
obj = [list first];
[self updateMethodCache: obj];
// Ok, we have cached our function to call on each object - do it.
// note that we don't do lookup for each step: this code only works
// if the list is homogeneous.
iter = [list begin: zone];
while ((obj = [iter next]) != nil) {
double v = [self doubleDynamicCallOn: obj];
if(v > 0.0)
entropy += v * log(v) ;
}
[iter drop] ;
entropy /= maximum ;
return self;
}
-(double) getEntropy {
return entropy;
}
@end
========================================================================
- Vacation,
Manor Askenazi <=