swarm-support
[Top][All Lists]
Advanced

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

Re: Want to delete item from list. Can't understand archived notes


From: Ken Cline
Subject: Re: Want to delete item from list. Can't understand archived notes
Date: Tue, 21 Jul 1998 04:09:21 -0400 (EDT)

On Fri, 17 Jul 1998, Chimera wrote:

> In your case, I wonder if you could just:
> 
>   index = [invitationsList begin: [self getZone]];
>   removeIndex=[invitationsList begin: [self getZone]];
>   while (( aRecruiter = [index next]) )
>   {
>      proposal= [aRecruiter getProposal];
>      disutility = [self distFromIdeal: proposal];
>      if( disutility < bestValue )
>      {
>         bestValue=disutility;
>         bestAlternative=aRecruiter;
>         removeIndex=index;
>      }
>   }
>
>   [invitationsRanking addLast: bestAlternative];
>   [removeIndex remove];
>   //  Remember to drop indexes
>   [removeIndex drop];
>   [index drop];
> 

I haven't try this code either, but it seems like the line
"removeIndex=index;" would cause a bug.  Maybe it should be
"removeIndex=[index copy:[self getZone]];" or perhaps
"[removeIndex setOffset: [index getOffset]];".

You might try breaking the code into several parts:

#define MAX_IDEAL 100000.0

-(double) getValueFor: (id) aRecruiter {
   return [ self distFromIdeal: [(Recruiter *)aRecruiter getProposal] ];
}

-(int) getMinOffsetFrom: (id <List>) aList {
   id <Index> index    = NULL;
   id         element  = NULL;
   int        offset   = 0;
   double     min      = MAX_IDEAL;
   double     value    = MAX_IDEAL;

   index = [ aList begin: [self getZone] ];
   while ( (element = [index next]) != NULL ) {
      value = [self getValueFor: element];
      if ( value <= min ) {
         min = value;
         offset = [ index getOffset ];
      }
   }
   [ index drop ];
   return offset;
}

-(void) moveBestFrom: (id <List>) invitations
                  To: (id <List>) rankings     {
   id <Index> index = NULL;

   index  = [ invitations begin: [self getZone] ];
   [ index setOffset: [self getMinOffsetFrom: invitations] ];
   [ rankings addLast: [index remove] ];
   [ index drop ];
}

Taken together these methods should be equivalent to Doug's
implementation, I just broke it up to emphasize the separate
parts of the algorithm, ie determining the element's
relative value, finding the minimum value, and moving an
element from one list to another.


_________________________________________________________
Ken Cline                             address@hidden
SAIC                                 VOICE (410) 571-0413
Annapolis, MD                          FAX (301) 261-8427



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