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: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_RANDOMOnce 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: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: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: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: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:
About the filenames and contents of files:
- 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
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 issuesIf 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 libraryYou 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.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, GATree<int> would become GATreeInt and any occurances of
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
T * var
would be replaced with int * var
.