SimpleGeneticAlgorithm implementation (was Re: Aha! How to get rid of Blocks in Smalltalk.)

Dean_Swan at Mitel.COM Dean_Swan at Mitel.COM
Mon Apr 24 16:49:48 UTC 2000



From:  Dean Swan at MITEL on 04/24/2000 12:49 PM

On 04/22/2000, "Lex Spoon" <lex at cc.gatech.edu> wrote:

>Well, to be fair, most of your examples are to:do: loops.  The part that
>isn't, the evaluationBlock stuff, could actually be changed to a regular
>method pretty easily.  Just define a class with an
>evaluate:inPopulation: method.  In fact, this might even be *easier* to
>read, because 7-8 lines of code will end up in a named method in a named
>class.

Lex,

     Could you elaborate on this, please?  The "evaluationBlock" stuff is tricky
because the "population" is stored in a 'Form' so I could use BitBlt to do the
genetic operators.  The 'evaluationBlock' needs to take a chromosome, which is a
one pixel high by "population width" Form extracted from the population.  It is
made up of a number of "fields" of varying bit widths, which are concatenated to
form the chromosome.  The evaluationBlock needs to parse these fields back out
of the chromosome, so that it can reconstitute the numeric values of the various
fields.  This is currently solved by the evaluationBlock sending
'fieldAt:width:' to the instance of SimpleGeneticAlgorithm, which returns an
integer value that can then be scaled and offset appropriately.

     Modifying the 'evaluatePopulation' method to use an "evaluate: chromosome
inPopulation: populationForm" message send would require the definition of a new
class for every kind of problem that you wanted to used the GA on, presumably as
a subclass of some abstract class like "ChromosomeEvaluator". Also,
'SimpleGeneticAlgorithm>>evalutatePopulation' would have to become
'evaluatePopulationUsing: EvaluatorObject'.

     The problem I see with this is that the 'fieldAt:width:" method still needs
to be defined someplace.  It could go in the abstract class
"ChromosomeEvaluator", but this bothers me because it doesn't really do anything
with instance variables of "ChromosomeEvaluator" (which would probably not have
any instance variables anyway!).  I could subclass 'Form' with a
'ChromosomePopulation' class and define 'fieldAt:width:' there, but now the
whole thing is getting spread across an awful lot of classes, and new classes
are being defined just to avoid using a block.

     I personally am opposed to gratuitous creation of new classes.  I think it
is contrary to one of Dan Ingalls' original design principles of making the
whole system simple enough to be understood by a single person.  Squeak alread
defines about 1200 different classes in the base image, which I think is an
awful lot of different "kinds of things" to understand.

     I've attached the 'SimpleGeneticAlgorithm' class as a Zipped fileout if you
want to play with it.

                                         -Dean
                                         dean_swan at mitel.com

(See attached file: SimpleGeneticAlgorithm.zip)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SimpleGeneticAlgorithm.zip
Type: application/zip
Size: 3015 bytes
Desc: .ZIP File
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20000424/8d9cdddb/SimpleGeneticAlgorithm.zip


More information about the Squeak-dev mailing list