swarm-support
[Top][All Lists]
Advanced

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

EZBin questions


From: Lindsay Hood
Subject: EZBin questions
Date: Fri, 6 Feb 1998 08:50:20 +0000

I have some questions about using the EZBin and EZDistribution classes for
calculating a spatial distribution function.

The canonical pseudocode for this would be

for (i=0; i<N; i++) {
  for (j=i+1, j<N; j++) {
    calc dist object_i to object_j;
    bin appropriately;
    ...
  }
}

Using the EZBin class, one can get close to this by doing all NxN distances

for (i=0; i<N; i++) {
  set origin  to be object_i;
  [sdf update];
}

The problem with this is

I really would like to pass arguments to the probedSelector used in the update.
 The code for doing the update in EZBin.m looks like

- update
{
  id iter, obj;
  char type0 = sel_get_type (sel_get_any_typed_uid (sel_get_name
(probedSelector)))[0];

  iter = [collection begin: [self getZone]];
  while ((obj = [iter next]))
    {
      int i;
      double v;

      if (type0 == _C_DBL)
        v = (* ((double (*) (id, SEL, ...))[obj methodFor: probedSelector]))
(obj, probedSelector);
      else if (type0 == _C_FLT)
        v = (double)(* ((float (*) (id, SEL, ...))[obj methodFor:
probedSelector])) (obj, probedSelector);
      else
        v = (double)(* ((int (*) (id, SEL, ...))[obj methodFor:
probedSelector])) (obj, probedSelector);

So it looks like we can pass varargs to the probedSelector, but how do we do
that from the interface supplied for EZBin? - setProbedSelector only takes a
method name, whereas I would really like to have something like

  setProbedSelector(calcDistanceX:x Y:y);

My solution to this has been to add some extra state to the object and set that
separately instead of passing arguments -

  for (i=0;i<N;i++) {
    object = [objectList atOffset: i];
    [object getX:&xO Y:&yO];
    // now use these coords as the origin for each distance calc
    for (j=0;j<N;j++) {
      object2 = [objectList atOffset: j];
      [object2 setOriginX:xO Y:yO];
    }
    // having set the origin, update the SDF (for this object)
    [rdf update];
  }

This extra state is appearing in an object when it "really shouldn't", ie it is
needing for my observation of the system rather than the object's view of the
world.

The alternative is to make my own EZDistribution subclass, but looking at the
code for update that would require me to actually know the implementation
details of the library and modify appropriately.  This of course goes against
the grain of OO inheritance, especially as these are "system" libraries.

I assume the update code is so messy because you want to call the
probedSelector as a function rather than a mthod to save some overhead.

Am I missing something obvious?



-- 
Lindsay Hood                            Ph:    +61 (2) 6272 3011
Bureau of Resource Sciences             Fax:   +61 (2) 6272 4687
Dept Primary Industries and Energy      email: address@hidden



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