In this section we describe all necessery and optional steps of an external layer implementation. We call the classes that implement the external layers (for parent and child process) TExternalParent and TExternalChild. We also use an example of such implementation: diffusion external layer (classes TDiffusionGGA and TDiffusionLGA). For its implementation see module diffusion.
At first you have to decide how will your parallelisation method work. How will the child processes cooperate? In which way will your method and the actual implementation differ?
Override the last layers TLocalGA and TGlobalGA of the class hierarchy by your classes TExternalParent and TExternalChild. Change the behavior of the computation by overriding virtual methods of the lower layers. For an example: override TGACover::GABody() that defines main loop of the genetic algorithm computation. See Reference Manual of the lower layers for detailed information.
Standard implementation uses five supportive classes for the computation TGen, TPopulation, TGenCode, TFitness and TParamFile. If these classes do not fit your requirements, then override them. You can also implement your own genetic operators.
The diffusion parallel GA works with the special population so we have derrived classes TGen and TPopulation by classes TGenEx and TSubPop. We have designed special selectors, working with the grid of population (TFinger, TRndmGrid etc.). We have derrived method TGACover::GABody() to change the main loop of the computation.
Implement initialisation of your GA by overriding methods Init()
and Prepare(). For the detailed information see
Kernel Initialization Procedure.
The four fundamental classes are created and owned in the layer TLocalGA. They are constructed during initialisation from the ParamFile in method TLocalGA::CreateComponents(). If you have overriden some of these classes, then you have to override this method. Within it you have to construct the proper successors of the supportive classes.
If your layers have some parameters that can be changed during the run, then override method RereadParams() in them. In this method refresh your parameters from the incoming ParamFile.
We have implemented a special diffusion initialisation procedure as a part of standard initialisation. We have also derrived method CreateComponents() and constructed our derrived supportive classes in it.
If your layers would communicate, you have to override method Interrupt() in them. Each layer communicate on the own priority to avoid influence between them. You can send and receive messages on the priority PRIORITY_OTHER that is reserved for external layers. In method Interrupt() you have to respect actual state of the process. For more information see Process Priorities and States (it contains also template for this method).
If you want to provide some new kernel info objects (kernel's data interface), refer to Kernel Info Class.
We have overrided method Interrupt(), that receives message MT_DIFFUSION containing change in neighbour's borderland. We have also implemented global kernel info KIG_GRID containing the information about the subpopulation's grid.
To apply your new approach in the kernel processes, you should provide construction of your classes in their main() functions (their source code is in files child.cpp and parent.cpp in module summary). Add your constructors to the procedures ::CreateLGA() and ::CreateGGA() in files child.cpp and parent.cpp. In these methods proper types of GA are constructed. Every type is identified by the unique string token, given as an command-line argument to the parent process. Choose a unique token and add construction of your classes. Note that this token must be present also in ParamFile as a parameter GAType.
The token for diffusion parallel GA is "diffusion".