Installation Instructions for Matthew's GA Library

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)

There are two things to build: the library and the examples.

Unix compilation:

First, edit the makefiles in the 'examples' and 'ga' directories. The makefiles have comments in them about what needs to be editted. You may have to edit the config.h header file. It has preprocessor directives set up for some of the compilers/OSes on which I have been able to test. You can either define the pre-processor directives using the -D option to your compiler (use the DEFINES macro in the makefile), or #define them in config.h.

For example, if your compiler does not understand templates and your machine does not have random and srandom, the DEFINES line in the makefile would be:

DEFINES = -DNO_TEMPLATES -DNO_RANDOM
Once you have editted the makefiles, 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.

By default the makefiles are configured for use with the g++ compiler. The default location for the GA library headers is /usr/local/include and default location for the library itself is /usr/local/lib.

MacOS compilation:

The distribution contains a directory called projects with CodeWarrior project files. In this directory you will find a project file for the library and a stationery project file for the examples. You should compile the library first (the example project file uses it), then use the examples stationery to create a project for each example.

Be sure to set the includes path so that <> is treated like "" and the directory in which the GAlib headers are located is searched before the system includes. Also, set the compiler to use strict ANSI compilation.

If, for some reason, you cannot use the project files, try importing the TEXT version of the project files. If that fails, see the custom compilation section. When you edit the config.h file, use preprocessor directives similar to those defined for __MWERKS__

DOS compilation:

The distribution contains a directory called projects with Borland 4.5 project files. In this directory you will find a project file for the library and an examples project file with a number of targets in it. You should compile the library first (the targets in the examples project file use it), then use the examples project to build each example.

Use the large memory model. When you compile the library by itself, use a library page size of 32. Be sure to set the includes path so that the directory in which the GAlib headers are located is searched. Also, set the compiler to use strict ANSI compilation.

If, for some reason, you cannot use the project files, try importing the makefiles. If that fails, see the custom compilation section. When you edit the config.h file, use preprocessor directives similar to those defined for __BORLANDC__

Custom compilation:

Edit the config.h file. You should read the comments in config.h so that you know what the machine- and compiler-specific options are. You can set these options either by #define-ing the macros in config.h or by defining them using your compiler's pre-processor directives. I have put a few compiler-specific #defines in config.h, but I don't know the characteristics of all the compilers, nor do I know the compiler-specific preprocessor directives (such as __GNUG__).

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 and which files you should not compile. The ga directory contains some source files that should not be compiled!

GAlib contains a 'types.h' file specific to the library that might be confused with the <sys/types.h> file depending on how you define the includes path and where the sys/types.h header is located on your platform.

Which files are needed in the library:

You must compile the following files:
error.C ga.C genome.C objective.C population.C random.C scaling.C selector.C sort.C statistics.C

You may compile any of the following groups (but any group must include all of the files listed for that group):

1DBinaryString:
binstr1.ch.C binstr1.xs.C binstr1.op.C binstr.C
2DBinaryString:
binstr2.ch.C binstr2.xs.C binstr2.op.C binstr.C
3DBinaryString:
binstr3.ch.C binstr3.xs.C binstr3.op.C binstr.C
Binary-to-Decimal:
binstr1.ch.C binstr1.xs.C binstr1.op.C binstr.C bin2dec.C bin2dec.ph.C
1DArray:
array1.ch.C array1.xs.C
2DArray:
array2.ch.C array2.xs.C
3DArray:
array3.ch.C array3.xs.C
String:
array1.ch.C array1.xs.C string.ch.C string.op.C
List:
list.ch.C list.xs.C listtmpl.C listbase.C
Tree:
tree.ch.C tree.xs.C treetmpl.C treebase.C

Do not compile the following files:

creators.C array1.op.C array2.op.C array3.op.C list.op.C tree.op.C

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 array1.ch.C, array1.xs.C, array2.ch.C, array2.xs.C, array3.ch.C, array3.xs.C, list.ch.C, list.xs.C, listtmpl.C, tree.ch.C, tree.xs.C, treetmpl.C)

To illustrate partial compilation of the GAlib sources, here is how you would compile example 10. Example 10 uses the binary-to-decimal genome, so to build this example we must include all of the core files, all of the files from the Binary-to-Decimal group, and all of the ex10 sources. Here is the list:

core library files
error.C ga.C genome.C objective.C population.C random.C scaling.C selector.C sort.C statistics.C
binary-to-decimal files
binstr1.ch.C binstr1.xs.C binstr1.op.C binstr.C bin2dec.C bin2dec.ph.C
example source files
ex10.C

About the filenames and contents of files:

All of the #include lines in GAlib are of the form "#include <ga/ga.h>". I assume that the GA library header and template source files will be kept in the same directory. For MacOS and DOS this has been replaced with "#include <ga.h>". Use your compiler's preferences to configure the search path to include the "ga" directory for including header files.

The *.op.* files define the initialization, mutation, and crossover operators. The *.ch.* files define the basic interface for each type of genome. The *.xs.* files define the crossover site objects and behaviours for each type of genome.

The DOS filenames are derived from the UNIX filenames described above. I have simply shortened the names by removing 'extra' periods and catenating to 8+3 characters. Also, .C has been replaced with .cpp for both the MacOS and DOS distributions. For example, binstr1.ch.C is binstr1.ch.cpp (MacOS) and binstr1c.cpp (DOS) and tree.op.C is tree.op.cpp (MacOS) and treeop.cpp (DOS).

I have included some source code for showing how to customize the creators for template classes. The creators.C file shows how to specialize the template classes so that the genomes will have default initializers, mutators, and crossovers of your choice (rather than GANoInitializer, etc). Do not try to compile creators.C - it will not compile!

Also, do not try to compile any of the template operators files (such as tree.op.C). These files contain a macro that the compiler will choke on. Either make a copy of the .op.C file then do your specialization by replacing the macro with the type for which you are specializing, or use the operators file by including the .op.h file as shown in the examples. For example, if you want to do your own Tree mutator for a GATree<char> you could start with the code for the TreeSwapNode mutator in tree.op.C, replace TREE_TYPE with char, then modify the mutator to behave as you want it to.

Template instantiation issues

If your compiler uses the Cfront automatic instantiation model (code repositories) you should not have to do anything special.

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 .C files. If your compiler uses this method of template instantiation, you do not need to compile any of the template .C files (array1.ch.C, array1.xs.C, list.ch.C, list.xs.C, listtmpl.C, etc).

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).

Compiling specific parts of the library

You can build only part of the library (and thus save space for certain OSes that are limited to 640K) by editting the config.h file. By default, everything is included in the library. When you edit the config.h file you can tell the compiler to strip out the parts of the library that you do not plan to use. You must compile all of the files for the core parts of the library (config.h will weed out the parts you do not want), but you do not have to compile all of the genome files. To use only selected genomes, compile only the files related to the genome(s) that you want to use (see the groups above for which files go with which genomes). Some genome classes may have special support files. Any derived class needs the files that go with the class(es) from which it was derived.

What to do if your compiler does not understand templates

If your compiler does not support templates, get one that does :)

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:

array1.ch.C array1.xs.C
array2.ch.C array2.xs.C
array3.ch.C array3.xs.C
string.ch.C string.op.C
list.ch.C list.xs.C listtmpl.C listbase.C
tree.ch.C tree.xs.C treetmpl.C treebase.C
If 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, GATree<int> would become GATreeInt and any occurances of T * var would be replaced with int * var.


21 September 1995