swarm-support
[Top][All Lists]
Advanced

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

Re: Building objects on the fly


From: glen e. p. ropella
Subject: Re: Building objects on the fly
Date: Tue, 11 Mar 1997 13:04:22 -0700

Jae Chan Oh writes:
 > Opps!  You helped me find a bug!
 > I setup the child's genome in createChild randomly, then I try to
 > allocate yet another dna by calling Mate.  I have to call 
 > digital exterminator :-)

Cool!

 > Yes, this is typo. I don't pass a string or an id to setPerson anymore.
 > I pass just an integer iD. So iD is an integer. -- a bad choice for
 > an integer type name right? I was not happy with the name either. :-)

Yep.  iD is a very bad name for an integer in objective C!  But,
then again, who really cares, right?  The important thing is that
it work.

 > Yes, I also have notice it. I changed the "world" in more like the
 > one in heatbugs. I don't have "party" anymore or "door".
 > I have a 2d world -- I wrote a new 2d space class that combines functionality
 > of 2dToroid and DblBuffer. It seem to work. I will be happy to
 > contribute it when all testing is over -- and a"pplList".

Definitely.  If it seems useful, pass it back to us and we'll
put it in the anarchy directory.

 > Here I want to ask a question that always seems to bother me.
 > Now please consider my interface declaration for Person below.
 > 
 > @interface Person: SwarmObject {
[...]
 >   BinChromosome*  dna;
 > }
 > 
 > 
 > Above I declare a ptr to BinChromosome dna within Person.
 > 
 > Now,
 > I could setup "dna" as in the above*2 (:-)) code. That is directly setting up
 > dna without using a method:
 > 
 > i.e. 
 >     dna  = [BinChromosome createBegin: [self getZone]];
 >     [[dna setLength:  (int) (GEN_LENGTH/8)] setRandomInit];
 > 
 > but also, I could setup dna by using local variable and by calling a method: 
 > 
 > i.e.
 >     tempDNA  = [BinChromosome createBegin: [self getZone]];
 >     [[tempDNA setLength:  (int) (GEN_LENGTH/8)] setRandomInit];
 >     //now call a method to setup dna
 >     [setDNA tempDNA]
 > 
 > Then in "-setDNA"
 >     -setDNA: (id) _dna {
 >     dna = _dna;
 >     return self
 >     }
 > 
 > 
 > So which way is better? Do you recommend any particular method? The dilemma 
 > here is that  the dna is a simple type so using an assignment
 > statement would be enough to set it up. Another example is "-setColor" 
 > method.
 > In one sentance the question is: Do I need to use a method to setup a
 > simple variable type declared in  an object or just using an assignemnt 
 > statement is OK? The only reason to using a method in this case, as far as 
 > I can see, is to let other object to be able to setup the simply type via the
 > method. Am I right?

Well, it really depends on what you intend to do with the 
instance variable dna.  For instance, if it's changeable
*after* creation of the object (say after createEnd), then
it might be wise to setup the tempDNA and then send that to
a setDNA: method.

But, if dna is *always* going to be frozen after create and 
you're sure you'll never want to change it, then the other
is better.  First, it cuts down on the number of methods of
the class, which reduces the space and clutter.  Second, it
cuts down on any errors that may ensue from code changes in
the future.

However, in some cases, it's still useful to retain the "setDNA:"
method because you want to be able to do that after "createEnd";
but, you still may want to create and set the "dna" variable 
directly because it's "prettier" or more aesthetically pleasing.
(This is the argument some people will give you, anyway.)

Another reason you might have a setDNA method is if the 
responsibility for setting the "dna" variable lie outside the
individual.  This isn't the case with what you're doing.  But,
in some GA-type apps, the Swarm would actually be responsible
for *effecting* the mutation or crossover *upon* the genome.
Here, it might be useful if the Swarm did whatever it was 
going to do with the tempDNA, then passed it to the individual.

Again, this is a style and modelling choice and I can give you
nothing but opinions.... and you know what they say about opinions.

 > Program received signal SIGSEGV, Segmentation fault.
 > 0x1b29c4 in objc_msg_lookup (receiver=0x3514c0, op=0x281b04) at sarray.h:216
 > sarray.h:216: No such file or directory.
 > (gdb) where
 > #0  0x1b29c4 in objc_msg_lookup (receiver=0x3514c0, op=0x281b04)
 >     at sarray.h:216
 > #1  0x6e474 in _i_Activity_c___run_ (self=0x370540, _cmd=0x281af4)
 >     at Activity.m:471
 > #2  0x1b2fd8 in __objc_init_install_dtable (receiver=0x6e178, op=0x281af4)
 >     at sendmsg.c:245
 > 
 > 
 > Which part of the code do you suggest to look up ? Sorry for too much 
 > detailed 
 > question but I'm still learning about objective-C and SWARM. If you can give
 > me any pointers I would aprreiciated it. I can't quite trace the program 
 > since
 > it crashs in between activities which is not part of my code. -- And I'm sure
 > that it crashs becasue of my code :-)

Hmmm.  I would look at whatever is happening in the top of 
your code.  Since you're in the middle of the "run" method
on an Activity, it implies that one of the actions on whatever
schedule is being traversed has been corrupted.  This could
be an array overrun in another piece of code or it could be
due to a change in some header file without doing a complete
recompile.

So, I would first do a make clean and then recompile.  If 
that doesn't fix it... then I have absolutely no idea.  You
could try to compile with bounds checking; but, I've never
done that with objective c.  The only other possibility might
be to examine all your schedules and action groups and such 
for anything odd looking.  Sorry I can't be of more help.

glen


reply via email to

[Prev in Thread] Current Thread [Next in Thread]