Newsgroups: comp.ai.genetic
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!news.alpha.net!uwm.edu!spool.mu.edu!howland.reston.ans.net!pipex!uknet!pcl!clemenr
From: clemenr@westminster.ac.uk (Ross Clement)
Subject: Re: how do I do "fitness-proportionate" selection?
Message-ID: <D4BG3G.Kq7@westminster.ac.uk>
Organization: University of Westminster
References: <3h8v33$pij@decaxp.harvard.edu>
Distribution: usa
Date: Mon, 20 Feb 1995 20:40:25 GMT
Lines: 39

In article <3h8v33$pij@decaxp.harvard.edu> mlevin@scws4.harvard.edu (Michael Levin) writes:
>
>Hi all -
>
>   I am doing a GA. In any given generation, once I have evaluated all
>of the individuals, and sorted them by fitness, I end up with the T top
>individuals, which will be used to create the next generation's
>population (of size N, where T is some percentage of N). Now, I want
>to randomly choose individuals from among these T, such that the
>probability of choosing an element is proportional to its fitness
>(relative to the best and worst elements in T). What is a good
>algorithm for this?  If anyone has ideas, C code, or pointers to
>existing routines (perhaps as part of a public-domain package or
>something) please email to mlevin@scws4.harvard.edu. Thanks.

What I do is this:

(i) Add up the total fitness of the population
(ii) Generate a random number between 0 and the total fitness
(iii) Run through the chromosomes again keeping a running total of
      how much "fitness" I've seen so far.
(iv) Select the first chromosome where the running total exceeds the
     random number.

Note, do the selection AFTER you've added the individual fitness to
the running total. E.g. if you add fitness[4] to the running total and
it exceeds the random number, then select chromosome 4.

This method works for both integer and real fitnesses (though you
have to be able to generate real random numbers for the latter), but all
fitnesses must be >= 0. A fitness of 0 will never be selected.

This method is pretty simple to implement, but is O(n) for the number
of chromosomes. I would not be surprised if there were faster methods
of doing it.

Cheers,

Ross-c
