GA in a more literal sense

Started by
15 comments, last by flangazor 21 years, 4 months ago
Timkin,

quote:Each of the genes should not contain information about how to encode or decode the chromosome, unless you want to dedicate a particular gene to that function.


Well, it would be nice to have encoding and decoding functions generated for me since it would be such a common task.

Failing that, I suppose I could use fup''s template.

Thanks, everyone, for your insight.

-flang
Advertisement
quote:Original post by flangazor
Well, it would be nice to have encoding and decoding functions generated for me since it would be such a common task.


I don''t see how you''re going to get automatically generated encoding and decoding functions?! You''re going to have to write them yourself... at least at some level of your class heirarchy!

Timkin
Timkin, have you used QT before?
QT: I can think of several expansions of that abbreviation... could you elaborate please?

Cheers,

Timkin
QT, the windowing library.

http://doc.trolltech.com/3.0/

It has a signals and slots way of doing things:

http://doc.trolltech.com/3.0/signalsandslots.html

It does this by having a precompiler that generates code for functions that are designated for use as slots, or signals:


A minimal C++ class declaration might read:


class Foo
{
public:
Foo();
int value() const { return val; }
void setValue( int );
private:
int val;
};

A small Qt class might read:


class Foo : public QObject
{
Q_OBJECT
public:
Foo();
int value() const { return val; }
public slots:
void setValue( int );
signals:
void valueChanged( int );
private:
int val;
};


I was of the opinion that something in the same vein could be done for data members for use in Genetic Algorithms. Determine which values are part of a chromosome, and encode them using a generated function that was generated by the precompiler by looking at which data members are designated to be part of the chromosome.
Aha! I think I understand you now.

You''re looking for some sort of automatic system that will take any given class, or part of a class, and create a chromosome to represent it, right? Or more specifically, create the functions and data that will represent it.

Basically, the problem you have is that while QT''s signals and slots are pretty standard across all classes, the representation you might want to use for GAs would change from situation to situation. You might have limits on what valid chromosomes are, you might want to choose normal binary or grey code, etc.

Probably the best way is to instead use some sort of template class which can take any basic type and encode it. You can use policy classes to specify the encoding methods etc. A generic encoding function could probably be written using sizeof() to make sure that you know how many bits you''re working with, although really you should use the constants in the numeric_limits class in the <limits> header.

Alternatively, have you looked at GALib? It is "free for any use, commercial or otherwise" and might suit your needs as a lot of the functionality you may need is already there.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
Yeah. Finally I got someone on my page. ;-)

I am usually pretty good at asking questions.. sorry it took so long this time.

wrt GALib, I know if it, but I haven''t tried using it. I saw a link to it on ai-depot.com. I was hoping to work pretty much from scratch as a learning excersise.

After I make some progress, I will try GALib and compare my results with it''s results.

I will try your templating method. I read about using limits in Scott Meyer''s book, but have long since returned it to the library.

Cheers,
-flang

This topic is closed to new replies.

Advertisement