The distribution comes in three flavors: UNIX, MacOS, and DOS. The source code for all flavors is the same; they differ only in the names of the files. The UNIX version is tarred and compressed (.tar.gz), the MacOS version is a Stuffit self-extracting archive in HQX format (.sea.hqx), and the DOS version is in ZIP format (.zip). Included in the distribution is the complete documentation in html format.
There are two things to build: the library and the examples.
Be sure to read over the section about template instantiation if your compiler starts to choke and spew errors. Most errors people encounter are linker errors and are typically due to template instantiation problems.
Once the makefiles are configured, do a 'make' in the base directory. If you want to install the library on your system, do a 'make install'. There is also a 'make remove' option to remove the library should you decide you do not want it installed on your system. The makefiles determine where the library will be installed.
Adding the string genome or real number genome source files to a project may cause the compilation to fail (depending on your compiler). They are designed to be included by other source files rather than being compiled themselves. They contain specializations of template classes.
The FTP site contains project files for some mac compilers. Each of these expands to a projects directory that contains stationery for creating the examples and a sample project for creating the library. You can either build the library then link to it from subsequent projects, or you can include specific GAlib files in each new project that you create.
If you cannot get the library to build right out-of-the-box, you may need to edit config.h to tailor GAlib to your OS/compiler configuration. When you edit config.h, use directives similar to those defined for __MWERKS__
Adding the string genome or real number genome source files to a project may cause the compilation to fail (depending on your compiler). They are designed to be included by other source files rather than being compiled themselves. They contain specializations of template classes.
Note that, by default, the library is configured to use the system's 'rand' random number generator when compiled with the Borland compiler. This is because I've had problems with the better RNGs (ran2) in 16-bit mode. If you are compiling a 32-bit application and you're using a Borland compiler, you should edit config.h so that USE_RAND is not defined. In any event, be sure to check the integrity of the random number generator by building and running the randtest example as soon as you build the library.
The FTP site contains project files for some PC compilers. You can either build the library then link to it from subsequent projects, or you can include specific GAlib files in each new project that you create.
If you cannot get the library to build right out-of-the-box, you may need to edit config.h to tailor GAlib to your OS/compiler configuration. When you edit config.h, use directives similar to those defined for __BORLANDC__
Be sure to set the includes path so that your compiler knows where to look for the GAlib header files. Also, be sure the compiler is using a strict ANSI compilation mode.
You can either compile a library or only the parts of GAlib that you need. In either case, see the listing below to determine which files you will need.
Which files are needed in the library:
gaerror.C garandom.C GABaseGA.C GAGenome.C GAParameter.C GAPopulation.C GAScaling.C GASelector.C GAStatistics.C
You may compile any of the following groups, depending on which parts you need in your program. But any group must include all of the files listed for that group:
- Simple Genetic Algorithm
- GASimpleGA.C
- Steady-State Genetic Algorithm
- GASStateGA.C
- Incremental Genetic Algorithm
- GAIncGA.C
- Deme Genetic Algorithm
- GADemeGA.C
- 1DBinaryString Genome:
- GA1DBinStrGenome.C GABinStr.C
- 2DBinaryString Genome:
- GA2DBinStrGenome.C GABinStr.C
- 3DBinaryString Genome:
- GA3DBinStrGenome.C GABinStr.C
- Binary-to-Decimal Genome:
- GABin2DecGenome.C gabincvt.C GA3DBinStrGenome.C GABinStr.C
- 1DArray Genome:
- GA1DArrayGenome.C GAAllele.C
- 2DArray Genome:
- GA2DArrayGenome.C GAAllele.C
- 3DArray Genome:
- GA3DArrayGenome.C GAAllele.C
- String Genome:
- GA1DArrayGenome.C GAAllele.C
- Real Number Genome:
- GA1DArrayGenome.C GAAllele.C
- List Genome:
- GAListGenome.C GAListBASE.C GAList.C
- Tree Genome:
- GATreeGenome.C GATreeBASE.C GATree.C
Do not compile the real genome source file or the string genome source file! These are specializations of template classes and should be included once (and only once) in one of your source files. If you are using a real number genome, include real.h in any file that refers to a real number genome and include GARealGenome.C in one (and only one) location in your code. GARealGenome.C contains a specialization of the one-dimensional array class, so by including it in a single location you will tell the compiler to use the specialization rather than the generic template code. Do not include it more than once. The string genome is also a specialization of the one-dimensional array genome, so to use it you should follow the same guidelines (but include the string genome header and source rather than the real number genome header and source).
If your compiler uses the Borland automatic instantiation model (see the section about template instantiation) then you need not compile any of the source files that contain template code. These include GAAllele.C GA1DArrayGenome.C, GA2DArrayGenome.C, GA3DArrayGenome.C, GAListGenome.C, GAList.C, GATreeGenome.C, GATree.C)
About the filenames and contents of files:
The DOS filenames are derived from the UNIX filenames described above. I have simply shortened the names to 8+3 characters.
If your compiler uses the Borland automatic instantiation model (all template code must be in the header files), then define the BORLAND_INST macro. This will cause all of the header files with template classes to include the associated source files. If your compiler uses this method of template instantiation, you do not need to include any of the template source files in your project.
If your compiler does not do automatic instantiation (for example, g++ 2.6.8) then define the NO_AUTO_INST macro. This will force an instantiation in the source files that specialize template classes (for example, the GAStringGenome). Note that there are (at least) two different syntaxes for forcing instantiation. The GNU compiler likes 'template class' before the forced instantiation, but the Borland compiler does not.
The symptoms of no automatic instantiation are linker warnings about member functions not being found (or defined) for template classes (e.g. GAAlleleSet
If you use the string genome, be sure to include the string genome header file in the source code that refers to string genomes. Similarly, if you use the real number genome then be sure to included the header file for that genome. You must also include the corresponding source file in one (and only one) of your code segments if you use one of these genomes. The string and real number genomes are treated differently than the other genomes in GAlib because they are specializations of template classes. They are not included in the ga.h header so that they will not force instantiations where they are not needed.
Compiling specific parts of the library
What to do if your compiler does not understand templates
You can compile the library by defining the NO_TEMPLATES preprocessor directive. If you do this, you can use only the BinaryString genomes (1D, 2D, and 3D). All of the other genomes are implemented as template classes. If you define the NO_TEMPLATES directive then you should not compile the following files:
GAAllele.C GA1DArrayGenome.C GA2DArrayGenome.C GA3DArrayGenome.CIf you need one of the template genome types but do not have a compiler that understands templates, you can modify the template files by hand. You will have to create a file for each type that you want to instantiate. If you will be instantiating only one type, remove <T> and replace T with the type you are going to instantiate. If you will be instantiating more than one type then you will have to replace <T> with an appropriate name and replace T with the type. For example, to create an instance of an 'int' version of the tree object, GATree<int> would become GATreeInt and any occurances of 'T * var' would be replaced with 'int * var'.
GAListGenome.C GAListBASE.C GAList.C
GATreeGenome.C GATreeBASE.C GATree.C