MOGAL

MOGAL

Introduction

MOGAL is a Multi-Objective Genetic Algorithm Library. It provides a framework for writing genetic algorithms which can be run in a distributed way. Furthermore, these genetic algorithms can be multi-objective, meaning that several fitness measures can be optimized at the same time.

License

The license which applies to this library is the LGPL. You can find the full version in the file LICENSE.LGPL which is included in the library archive. The short version is the following:

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
 USA.

Usage

Starting a genetic algorithm, both locally and in a distributed way, is done using an instance of the mogal::GeneticAlgorithm instance. One of the overloaded versions of mogal::GeneticAlgorithm::run will start the optimization, and when it is finished, the same instance will store the best solution(s). This class implements the core structure of a genetic algorithm: start with a random population and keep producing new populations until a stopping criterion is met. The inner workings of a specific genetic algorithm must be implemented by deriving your own class from mogal::GAFactory. The classes mogal::GAFactorySingleObjective and mogal::GAFactoryMultiObjective are derived from the mogal::GAFactory class, and will make it easier to start your own genetic algorithm.

The script createGATemplate.sh which is included in this package can be used to create a framework for your genetic algorithm. When this is run, it will produce an overview of the functions which will need to be implemented. Note that if you're only going to run the genetic algorithm locally, many of these functions will not need a decent implementation. On the other hand, if distributed calculation is desired, some additional code will need to be written to serialize the information in a genome.

Examples

The examples subdirectory contained in the source code package contains some examples which can help you to get started.

Single-objective example

The file single.cpp illustrates how a simple, single-objective genetic algorithm can be implemented using the library. Since no code is provided to serialize the genome information, this example can't be run in a distributed way.

To compile the example:

 g++ -o single single.cpp `pkg-config --cflags --libs mogal`

Multi-objective example

The file multi.cpp shows how a multi-objective genetic algorithm can be implemented with the help of the library. Again, no code is provided for distributed calculation of the genome fitness values.

To compile this example:

 g++ -o multi multi.cpp `pkg-config --cflags --libs mogal`

Distributed calculation example

Non-MPI example

The files distmain.cpp, distmodule.cpp, distparams.cpp and distparams.h are part of an example which illustrates how the genome fitness calculation can be distributed.

To compile the main program:

 g++ -o distmain distmain.cpp distparams.cpp `pkg-config --cflags --libs mogal`

To compile the module:

 g++ -fPIC -shared -Wl,-soname,distmodule.so -o distmodule.so distmodule.cpp distparams.cpp `pkg-config --cflags --libs mogal`

To make the program work, you'll have to do two additional things:

Note that because this example is very simple, the communication overhead that is introduced in distributing the fitness calculation actually makes it slower than when the calculation would not be distributed.

MPI example

The example is basically the same as in the previous case, but now only one file will need to be compiled:

 g++ -o mpidistmain mpidistmain.cpp `pkg-config --cflags --libs mogal`

Contact

If you have any questions, remarks or requests, you can contact me at jori(dot)liesenborgs(at)gmail(dot)com