swarm-support
[Top][All Lists]
Advanced

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

Re: problems with using index


From: Paul Johnson
Subject: Re: problems with using index
Date: Tue, 1 Feb 2000 08:14:37 -0600 (CST)


On Tue, 1 Feb 2000, Xiaodong Li wrote:

> 
> Can anyone here enlighten me?  
> 
> I have been looking at the Breeder 2.0.... The following is a part of it.
> 
> ======================================================
>     // Kill the worst mutProb, and substitute them by the siblings of the
>     // others
>     i = 0; 
>     index = [ popList begin: [self getZone]];
>     [index setLoc: End];
> 
>     printf("killQuant is: %d and popSize is %d\n", killQuant, popSize);
> 
>     while( ( i < killQuant) && (stiff = [index prev] ) ){
>       if ( verbose ) {
>       printf("[%s %f]\n", [stiff getID], [stiff getFitness] );
>       }
>       [stiff drop];           // Eliminate gen
>       [index remove];
>       i++;
>     }
>     [index drop];
> =======================================================

I think the problem is caused by dropping the element then trying to
remove it.

Probably better to delete the [stiff drop]; and rewrite the part inside
the loop as 
     id obj;
     obj=[index remove];
     [obj drop];
     i++;

If there is  a danger of nil items in your list already, you might try
running this program with the newest swarm snapshot. It has a great (for
me) feature: any messages to nil cause a runtime error. Hence, if a nil
sneaks into your list, and you remove it and then send it a drop message,
the swarm lib will tell you so.


> 
> "After a current member is removed, there is no member at the current index
> location, but a subsequent next or prev message will continue with the same
> member that would have been accessed had the current member not been
> removed. An InvalidIndexLoc error is raised if the index is not positioned
> at a current member."
> 
> What does it mean in the above "a subsequent next or prev message will
> continue with the same member..."?
It means if your index is on item 7, and you remove item seven, then the
"next" command will give you the object after 7's position, the one that
would have been 8.

> I thought it has been removed, but why
> can it still be accessed?
I think your dropping of the object while it is still in the list causes
this problem.

> The other thing puzzling me is that around the above code, the author of
> Breeder 2.0 actually changed the variable "popSize" to doubled its original
> size (eg., from 100 to 200). I am just wondering why.???
> 

Now my question to ask you: Can you show me some code that uses the
Breeder library?  

Paul Johnson 
lost my sig again


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