ShareEmail this to someoneShare on RedditTweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn


Notification and updates about algorithm’s progress are dispatched to user code through observing framework implemented in the library. Event manager is responsible keeping list of subscribed event handlers and for notifying them when the algorithm raises an event. It is important to note that one handler can be subscribed to several events and they do not have to be events of the same event manager. Events are identified by their IDs and there is no static list of events that can be raised.

Implementation of the framework is located in Common::Observing namespace. GaEventManager class is the heart of the observing framework. It allows user to subscribe event handler to specific events by calling AddEventHandler method. Algorithm can raise these events by calling RaiseEvent and providing event data. User can unsubscribe from an event by calling RemoveEventHandler.

Since event manager is not thread-safe, it is not recommended to add or remove event handlers during the execution of the algorithm. Subscribed handlers are executed in the same thread in which the event is raised.

EventData is base class for event data that are passed from the part of algorithm that raised the event to user’s event handlers.

GaEventHandler represent base class for event handlers. Execute method is abstract and should implement actual logic of the event handler. This class also handles binding to/unbinding from handler to an event manager.

Library has two implementations of event handlers which simplify event handling for users. User can use GaNonmemberEventHandler class if a function should handle event or GaMemberEventHandler if a method of an object should handle it.

For more information see documentation of these classes:

  • GaEventData
  • GaEventHandler
  • GaNonmemberEventHandler
  • GaMemberEventHandler
  • GaEventManager


As many parts of genetic algorithms relays on random numbers, the library implements fast random number generator using multiply-with-carry (MWC) method. It also has a set of interface classes that wrap basic generator and produce random numbers of desired data type. The library also supports generating sequence of random numbers of arbitrary size as well as array shuffling. These classes and functions are located in Common::Observing namespace.

GaRandomGenerator class implements random MWC number generator. Several methods are available for generating random numbers depending on desired number type. Generate method generates unsigned int number in range [0, MAX_INT], GenerateFloat generates float in range [0, 1] and GenerateDouble generates double number in range [0, 1]. All methods that generate random numbers are thread-safe. In case that a single instance of the generator is enough, user can call GetInstance to obtain global instance of the generator.

Random number generator is not meant to be used directly but through GaRandom class. It is built on top of the basic generator and provides better control over generation of random numbers.
There are several specialization of the class for the following data types: int, long long, float, double, bool.

For more information see documentation of these classes:

Functions for random sequence generation:

  • GaGenerateRandomSequenceAsc (more) – generates sequence of random integer numbers sorted in ascending order.
  • GaGenerateRandomSequenceDsc (more) – generates sequence of random integer numbers sorted in descending order.
  • GaGenerateRandomSequence (more) – generates unsorted sequence of random integer numbers.

Functions for array shuffling:

  • GaShuffle (more) – shuffles order of items in provided array.
  • GaShuffleTo (more) – copies items from one array to another, but shuffles their order in destination array.


The library uses mergesort algorithm for sorting. It is implemented by GaMergeSortAlgorithm class, located in Common::Sorting namespace.

Single instance of the algorithm is bound to a single array. Since mergesort does not perform in-place sorting, a helper array with the same size as original array is needed. These two arrays are specified either at construction time or they can be set by calling SetArray method.

Sort methods performs actual sorting according to provided sorting criterion. The first version of the method sorts entire array, while the other sorts only specified part of the array. Method that sorts entire array has option to return sorted array in helper array instead of the original which due to internal implementation, can improve performance. If this option is enabled, the helper array will become original during next sort. This option can be controlled by SetSwapable method. Algorithm keeps track which array is used as original and which one is helper array. Sorting methods always returns pointer to the first element of the sorted array.

For more information see documentation of GaMergeSortAlgorithm class.

Sorting Criteria

Sorting criteria are provided to sorting algorithm, and they define the order of elements in the sorted array. Base class for sorting criteria is GaSortingCriteria.

  • GaAscendingSortingCriteria (more) – sorts array in ascending order. Object in the array should have operator >.
  • GaDescendingSortingCriteria (more) – sorts array in sescending. Object in the array should have operator >.
  • GaMutableSortCriteria (more) – base class for criteria that allow user to change behavior during run-time. This class is needed since the basic sort criteria are static for performance reasons.
  • GaMutableSortCriteriaAdapter (more) – implementation of mutable sorting criterion, that acts like adapter for another criterion which is used for actual comparison.
  • GaSortCriteriaConverter (more) – sorting criterion that allows users to use another criterion that expects data of different type from the ones in the array. User should specify wanted criterion and conversion between array type and the required type as template parameter.


There are several classes that allow time tracking in the library. Stopwatches allow users to measure how much time is spent for the execution of different tasks.

Interface for stopwatches is defined by GaStopwatch class. It has two methods Reset which sets stopwatch to zero and GetClock that returns current value of stopwatch in milliseconds. The library has two implementations, one for low resolution timing – GaStopwatchLowRes that is based on clock(). The second implementation is for high resolution timing and it is system dependent and is based on high resolution timer available on current platform. These classes are located in Common:Timing namespace.

For more information see documentation of these classes:

System Information

Currently the library only provides information about size of CPU’s cache line, which is needed for optimization of multithreading algorithms. GaCpuInfo class is responsible for obtaining this information. GetInstance class method returns global instance which can be used to query size of cache line.

Platform Identification

Platform.h header file is responsible for detection of C++ compiler, standard library extensions and targeted operating system. For more information see documentation of the header file.