a "generic" problem

Carl Banks imbosol at aerojockey.com
Thu Feb 13 03:10:17 CET 2003

Sean Ross wrote:
> Yes, it does help, thank you. I actually figured out that I needed to use a
> classmethod instead of a staticmethod on my own, but now that I see your
> idea of having the GA generate its own pool, I've decided I like that
> better. I'm not as certain about having the Chromosome define the xover
> method. It's seems like a good idea. I'll consider it some more.

I'll explain my rationale for this a bit.  Basically, crossover
operation depends on the inner details of a Chromosome.  And if those
details change, you have to change the GeneticAlgorithm, too.  (What
would happen if you stuck a tree in there?)  It's usually best to
leave stuff that deals with Chromosome inner details in the

Ideally, GeneticAlgorithm shouldn't need to know anything about the
details of the Chromosome, nor should the Chromosome need to know
anything about the details of the GeneticAlgorithm.  And, if you have
any larger plans, it behooves to you try to keep stuff where it

But, if you have no larger plans, and just want to experiment with
different crossover operations, it might be easier to just make it a
method of GeneticAlgorithm, as you did.

> FYI, I'll be doing GP later this semester, I'd be intersted to hear what
> sort of difficulties you encountered, if any, using Python for this task.

Not many, really.  Python is a great language for this.

> For instance, did you have the programs that were generated be Python
> programs? I was thinking of using Python to generate the programs, but
> perhaps to have the programs be in Scheme(which has a fairly simple syntax).

Well, Scheme's fairly simple syntax won't buy you much; simple syntax
helps simplify input, but not really output.  To illustrate, consider
that it's just as easy to output C code like this:

    return "(%s+%s)" % (subtree[1], subtree[2])

as it is to output Scheme code like this:

    return "(+ %s %s) % (subtree[1], subtree[2])

For one particular problem, I actually output the population as
Fortran code, compiled it into a Python module using distutils,
imported it, and ran it.

I recommend you output in a language that is efficient overall, and
has good error checking if you need that, and not worry too much about
a complicated syntax.

> Although, then I'd have to figure out how to determine whether or not a
> scheme program was good from within a Python program...
> Oh well, I haven't given it a lot of thought yet.


More information about the Python-list mailing list