Categories

Archive

2005 02 14

Separating fitness calculations from algorithms

Some time ago I was in a situation, where I needed to interface the algorithm I was working with (NSGA-II) to Matlab in order to perform some fitness calculations. In my attempts to find an easy way of doing this, I stumbled upon a small “server”-program which allowed me to use files for inputing and outputting my data from Matlab. This inspired me to modify the algorithm that I work with, such that it can send the individuals to external programs and read the calculated fitness values once they appear. The principle is very simple. By using one input file and one output file it becomes possible to use a “handshaking”-signal. The algorithm can signal that the file containing the individual is ready by deleting the file containing the previous calculated fitness functions. Correspondingly the fitness calculation program can signal that the calculated fitness is ready by deleting the file containing the individual. This method has allowed me to change the way fitness calculations is performed without the need for modifying or recompiling my algorithm. It is thus possible for me to use Matlab to calculate my fitness functions for some problems while using a C++ program, that uses database queries, to calculate other fitness functions. So, using this trick makes it possible to make the algorithms versatile by simply separating the algorithm from the code that is necessary to calculate the fitness.

Write a comment