swarm-support
[Top][All Lists]
Advanced

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

Questions


From: Holger Perlt
Subject: Questions
Date: Wed, 22 Aug 2001 09:03:43 +0200

Hello,

I have following simple problems (all are extensions from the
simpleObserverBug...)

1. Graphical representations of data:
-------------------------------------

With the following code the average of numbers of a list (from
getBugList and getnumEat (a
method of Bug to get the number of food pieces eaten))
is represented as a curve:

(in ObserverSwarm.m)

- buildObjects
{

***************

 avgEatGraph = [EZGraph createBegin: [self getZone]];
  [avgEatGraph setTitle: "Avg. # of Eating"];
  [avgEatGraph setAxisLabelsX: "Cycle" Y: "Avg. Eat"];
  avgEatGraph = [avgEatGraph createEnd];
  [avgEatGraph createAverageSequence: "avgNumEat"
                  withFeedFrom: [modelSwarm getBugList]
                  andSelector: M(getnumEat)];

***************
}

- buildActions
{

*****************

[displayActions createActionTo: avgEatGraph message: M(step)];

****************
}


How can I show two or more curves inside one window? E.g. one has
two buglists and I want to show both averages at the same time.

2. More than one BugSwarm:
--------------------------

I wanted to bring into the play two independent BugSwarms - each with
its
BugList. I did it with the following steps:

in Bug.m: ( to give the two bug sorts different colors (green and blue))

- drawSelfOn: (id <Raster>)r
{
  [r drawPointX: xPos Y: yPos Color: 2];
  return self;
}

- drawSelfOn1: (id <Raster>)r
{
  [r drawPointX: xPos Y: yPos Color: 3];
  return self;
}

in ModelSwarm.m:



- buildObjects
{

*************************

 // Now, create a bunch of bugs to live in the world

  bugList = [List create: self];

  for (y = 0; y < worldYSize; y++)
    for (x = 0; x < worldXSize; x++) 
      if ([uniformDblRand getDoubleWithMin: 0.0 withMax: 1.0] <
bugDensity)
        {
          aBug = [Bug createBegin: self];
          [aBug setWorld: world Food: food];
          aBug = [aBug createEnd];
          [aBug setX: x Y: y];
          [aBug setEat: 0 Y: 0];
          
          [bugList addLast: aBug];
          numList++;
        }

//here the second bug sort (up to now no check whether the
//the site is free or occupied by the first bug sort)

  bugList1 = [List create: self];

  for (y = 0; y < worldYSize; y++)
    for (x = 0; x < worldXSize; x++)
      if ([uniformDblRand getDoubleWithMin: 0.0 withMax: 1.0] <
bugDensity1)
        {
          aBug = [Bug createBegin: self];
          [aBug setWorld: world Food: food];
          aBug = [aBug createEnd];
          [aBug setX: x Y: y];
          [aBug setEat: 0 Y: 0];

          [bugList1 addLast: aBug];
          numList1++;
        }

*****************************

}

- buildActions
{
****************

 modelActions = [ActionGroup create: self];
  [modelActions createActionForEach: bugList    message: M(step)];
  [modelActions createActionForEach: bugList1    message: M(step)];

***************
}

in ObserverSwarm.m:

- buildObjects
{

*************

colorMap = [Colormap create: self];
  [colorMap setColor: 0 ToName: "black"];
  [colorMap setColor: 1 ToName: "red"];
  [colorMap setColor: 2 ToName: "green"];
  [colorMap setColor: 3 ToName: "blue"];

//this part should prepare the display of both bug sorts in green and
blue - but it does 
//show only one sort

bugDisplay = [Object2dDisplay createBegin: self];
  [bugDisplay setDisplayWidget: worldRaster];
  [bugDisplay setDiscrete2dToDisplay: [modelSwarm getWorld]];
  [bugDisplay setObjectCollection: [modelSwarm getBugList]];
  [bugDisplay setDisplayMessage: M(drawSelfOn:)];   // draw method
  bugDisplay = [bugDisplay createEnd];

bugDisplay1 = [Object2dDisplay createBegin: self];
  [bugDisplay1 setDisplayWidget: worldRaster];
  [bugDisplay1 setDiscrete2dToDisplay: [modelSwarm getWorld]];
  [bugDisplay1 setObjectCollection: [modelSwarm getBugList1]];
  [bugDisplay1 setDisplayMessage: M(drawSelfOn1:)];   // draw method
  bugDisplay1 = [bugDisplay1 createEnd];




***************
}

- buildAction
{ 
*****************

[displayActions createActionTo: bugDisplay   message: M(display)];

// should I add the line [displayActions createActionTo: bugDisplay1  
message: M(display)];  ????

********************
}

I know that my code is very in efficient - but I would like to extend
the methods and ...   step by step.
Could you comment my attempts?

Holger

-- 
PD Dr. habil. Holger Perlt
Diplomphysiker/Geschäftsführer
Reinforcement Control GmbH
Karl-Heine-Str. 99
04229 Leipzig
Germany
Phone:  ++49 (0)341 9410370
Fax:    ++49 (0)341 9410372
http://www.reinforcement.de

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