swarm-support
[Top][All Lists]
Advanced

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

Matters of taste or strategy?


From: pauljohn
Subject: Matters of taste or strategy?
Date: Fri, 5 Jun 1998 15:19:20 -0500 (CDT)

Two Swarm Modeling questions:
 
   
  1. I've been comparing code in different programs and I wonder if you
have ever considered this.  The CreateEnd code in an .m file can be
used as a launching point for anything that has to be run only once in
the life of the object.  So, instead of writing a setValue method
in an object and then coding ModelSwarm at buildObjects time to execute
the setValue method, the code that would have been inside the setValue
can just be stuffed into createEnd instead.

It leads to some economical coding, but I wonder if it is "bad form" 
in your eyes. 

For example, I want to create a random number generator to use inside
an object.  I just put the code to create it in the createEnd method.
  Example:
 
-createEnd {
    worldXSize = [world getSizeX];
    worldYSize = [world getSizeY];
    aGenerator = [SWB1 create: [self getZone] setStateFromSeed: 23 ];
    aNormalValue= [NormalDistribution create: [self getZone] 
          setGenerator:  aGenerator
          setMean: 0 setVariance: 1];   
   return self;
}

So, in this object, any methods can call values from aNormalValue.
This saves me the trouble of writing another method for that object
("startRNG" and then going back to ModelSwarm and calling startRNG in
the buildObjects phase).

I know in the sample swarm code projects that this use of createEnd is
avoided, and I wonder why.  Is the problem that my approach is "not
reusable" in other projects?

 2. Anybody create a nice way to randomly select members of a list? 
  If I want to have some action committed on 1000 members out of a list
  of 50000 objects, it seems there ought to be some easier way than
  just cycling through the whole list of 50000, drawing a random
  uniform for each one and picking that one if the random number is
  less than 1/50.   

   Oh, well, just studying for fun!

-- 
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (913) 864-9086
Lawrence, Kansas 66045                FAX: (913) 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]