libfgen  0.1.15
Library for optimization using a genetic algorithm or particle swarm optimization
fgenpp.h
00001 /*
00002     fgenpp.h -- C++ wrapper API header file.
00003 
00004     fgen -- Library for optimization using a genetic algorithm or particle swarm optimization.
00005     Copyright 2012, Harm Hanemaaijer
00006 
00007     This file is part of fgen.
00008 
00009     fgen is free software: you can redistribute it and/or modify it
00010     under the terms of the GNU Lesser General Public License as published
00011     by the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     fgen is distributed in the hope that it will be useful, but WITHOUT
00015     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00017     License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public
00020     License along with fgen.  If not, see <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 
00025 /*
00026  * C++ wrapper API for the libfgen library.
00027  */
00028 
00029 #ifndef __FGENPP_H__
00030 #define __FGENPP_H__
00031 
00032 #include <fgen.h>
00033 
00038 class FGEN_API FgenppIndividual : public FgenIndividual {
00039 public :
00040         double GetFitness() const {
00041                 return fitness;
00042         }
00043         unsigned char *GetBitstring() const {
00044                 return bitstring;
00045         }
00046 };
00047 
00048 class FGEN_API FgenppPopulation {
00049 private :
00050         FgenPopulation *pop;
00051 public :
00052         FGEN_API void Initialize(int population_size, int individual_size_in_bits, int data_element_size);
00053         FGEN_API void Destroy();
00054         FGEN_API virtual void GenerationCallback(int generation);
00055         FGEN_API virtual double CalculateFitness(const unsigned char *bitstring);
00056         FGEN_API virtual void Seed(unsigned char *bitstring);
00057         FGEN_API virtual void Mutate(const unsigned char *parent, unsigned char *child);
00058         FGEN_API virtual void Crossover(const unsigned char *parent1, const unsigned char *parent2,
00059                 unsigned char *child1, unsigned char *child2);
00060         FGEN_API void SeedBitstringRandom(unsigned char *bitstring);
00061         FGEN_API void MutatePerBitPlusMacroMutation(const unsigned char *parent, unsigned char *child);
00062         FGEN_API void MutatePerBit(const unsigned char *parent, unsigned char *child);
00063         FGEN_API void CrossoverOnePointPerBit(const unsigned char *parent1, const unsigned char *parent2,
00064                 unsigned char *child1, unsigned char *child2);
00065         FGEN_API void CrossoverTwoPointPerBit(const unsigned char *parent1, const unsigned char *parent2,
00066                 unsigned char *child1, unsigned char *child2);
00067         FGEN_API void CrossoverOnePointPerElement(const unsigned char *parent1, const unsigned char *parent2,
00068                 unsigned char *child1, unsigned char *child2);
00069         FGEN_API void CrossoverTwoPointPerElement(const unsigned char *parent1, const unsigned char *parent2,
00070                 unsigned char *child1, unsigned char *child2);
00071         FGEN_API void CrossoverUniformPerBit(const unsigned char *parent1, const unsigned char *parent2,
00072                 unsigned char *child1, unsigned char *child2);
00073         FGEN_API void CrossoverUniformPerElement(const unsigned char *parent1, const unsigned char *parent2,
00074                 unsigned char *child1, unsigned char *child2);
00075         FGEN_API void CrossoverNoop(const unsigned char *parent1, const unsigned char *parent2,
00076                 unsigned char *child1, unsigned char *child2);
00077         FGEN_API void SeedPermutationRandom(unsigned char *bitstring);
00078         FGEN_API void MutatePermutationSwap(const unsigned char *parent, unsigned char *child);
00079         FGEN_API void MutatePermutationInsert(const unsigned char *parent, unsigned char *child);
00080         FGEN_API void MutatePermutationInvert(const unsigned char *parent, unsigned char *child);
00081         FGEN_API void CrossoverPermutationOrderBased(const unsigned char *parent1, const unsigned char *parent2,
00082                 unsigned char *child1, unsigned char *child2);
00083         FGEN_API void CrossoverPermutationPositionBased(const unsigned char *parent1, const unsigned char *parent2,
00084                 unsigned char *child1, unsigned char *child2);
00085         FGEN_API void SetParameters(
00086                 int selection_type,
00087                 int selection_fitness_type,
00088                 float crossover_probability_float,
00089                 float mutation_per_bit_probability_float,
00090                 float macro_mutation_probability_float);
00091         FGEN_API void Run(int max_generation);
00092         FGEN_API void RunThreaded(int max_generation);
00093         FGEN_API void RunSteadyState(int max_generation);
00094         FGEN_API void SetMutationProbability(float prob);
00095         FGEN_API void SetMacroMutationProbability(float prob);
00096         FGEN_API void SetCrossoverProbability(float prob);
00097         FGEN_API void SetSelectionFitnessType(int type);
00098         FGEN_API void SetSelectionType(int type);
00099         FGEN_API void SetTournamentSize(int size);
00100         FGEN_API void SetDataElementSize(int size);
00101         FGEN_API void SetNumberOfElites(int n);
00102         FGEN_API void SetPermutationSize(int size);
00103         FGEN_API void SetMigrationInterval(int interval);
00104         FGEN_API void SetMigrationProbability(float prob);
00105         FGEN_API void SetGenerationCallbackInterval(int interval);
00106         FGEN_API FgenppIndividual *BestIndividual();
00107         FGEN_API FgenppIndividual *WorstIndividual();
00108         FGEN_API void UpdateFitness();
00109         FGEN_API void SignalStop();
00110         FGEN_API FgenRNG *GetRNG();
00111         FGEN_API int GetIndividualSizeInBytes();
00112         FGEN_API int GetIsland();
00113         friend class FgenppArchipelago;
00114 };
00115 
00116 class FGEN_API FgenppArchipelago {
00117 private :
00118         FgenPopulation **pops;
00119         int max_size;
00120         int size;
00121 public :
00122         FGEN_API FgenppArchipelago(int max_size);
00123         FGEN_API ~FgenppArchipelago();
00124         FGEN_API void AddIsland(FgenppPopulation *pop);
00125         FGEN_API void Run(int max_generation);
00126         FGEN_API void RunThreaded(int max_generation);
00127         FGEN_API void RunSteadyState(int max_generation);
00128         FGEN_API void RunSteadyStateThreaded(int max_generation);
00129         FGEN_API FgenppIndividual *BestIndividual();
00130         FGEN_API FgenppPopulation *GetPopulation(int index);
00131 };
00132 
00135 #endif
00136 
All Data Structures Functions Variables