Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/Genetic/include/GAConfig.h

Go to the documentation of this file.
00001 /*
00002  *   $Id$
00003  */
00004  
00005 // Copyright (C) 1998 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 //
00008 // Contents: Definition of class GAConfig
00009 //
00010 // Principal Author: Dmitry Bormotov
00011 //
00012 // Status: in progress
00013 //
00014 // Description:
00015 //
00016 //    GAConfig reads commonly used parameters for genetic algorithm
00017 // from a file and provides interface for accessing their values. Additional 
00018 // parameters can be specified by subclassing GAConfig and overriding hook 
00019 // function setUserVariable(). GAConfig has no abstract functions. Possible
00020 // variables(parameters) and their values are listed in test/ga.cfg .
00021 //
00022 // Revision History:
00023 //
00024 
00025 #ifndef _GAConfig_H_
00026 #define _GAConfig_H_
00027 
00028 #include "Chars.h"
00029 
00030 
00031 // ------------------------------ GAConfig --------------------------------- //
00032 
00033 
00034 class GAConfig
00035 {
00036 public:
00037 
00038   enum ElitistSelectionType { SIMPLE, STRONG, NONE }; 
00039 
00040   /////////////////////////////////////////////////////////////////////////
00041   //                                                                     //
00042   // Constructors:                                                       //
00043   //                                                                     //
00044   /////////////////////////////////////////////////////////////////////////
00045   
00046   GAConfig( int popSize = 50, 
00047             int numOfGens = -1, 
00048             int crossChance = 100, 
00049             int mutChance = 100, 
00050             ElitistSelectionType elitType = SIMPLE, 
00051             bool fitScaling = true,
00052             int Report = 1,
00053             int FitnessPrint = 10,
00054             int PopulationPrint = 100
00055             );
00056   
00057   // copy constructor, destructor and operators =, == supplied by compiler.
00058 
00059 
00060   /////////////////////////////////////////////////////////////////////////
00061   //                                                                     //
00062   // Hook functions:                                                     //
00063   //                                                                     //
00064   /////////////////////////////////////////////////////////////////////////
00065 
00066   virtual bool setUserVariable( Chars varName, Chars value ) {  }
00067   // to be overriden in subclasses in order to accept additional
00068   // parameters; must return 'true' if successful and 'false' if either
00069   // 'varName' or 'value' are illegal
00070 
00071 
00072   /////////////////////////////////////////////////////////////////////////
00073   //                                                                     //
00074   // Accessors:                                                          //
00075   //                                                                     //
00076   /////////////////////////////////////////////////////////////////////////
00077 
00078   int populationSize( ) const { return population; }
00079 
00080   int numOfGenerations( ) const { return generations; }
00081 
00082   double chanceOfCrossover( ) const { return double(crossover)/100; }
00083   // returns value betweeen 0 and 1
00084   
00085   double chanceOfMutation( ) const { return double(mutation)/100; }
00086   // returns value betweeen 0 and 1
00087   
00088   ElitistSelectionType elitistSelectionType( ) const 
00089     { return elitistSelection; }
00090 
00091   bool haveFitnessScaling( ) const { return bFitnessScaling; }
00092 
00093   int report( ) const { return theReport; }
00094 
00095   int fitnessPrint( ) const { return theFitnessPrint; }
00096 
00097   int populationPrint( ) const { return thePopulationPrint; }
00098   
00099   
00100   /////////////////////////////////////////////////////////////////////////
00101   //                                                                     //
00102   // OI:                                                                 //
00103   //                                                                     //
00104   /////////////////////////////////////////////////////////////////////////
00105   
00106   friend ostream& operator << ( ostream& ostr, const GAConfig& C )
00107   {
00108     C.printOn(ostr);
00109     return ostr;
00110   }
00111     
00112   friend istream& operator >> ( istream& istr, GAConfig& C )
00113   {
00114     C.readFrom(istr);
00115     return istr;
00116   }
00117 
00118   virtual void readFrom( istream& istr );
00119 
00120   virtual void printOn( ostream& ostr ) const;
00121 
00122 
00123 private:
00124 
00125   /////////////////////////////////////////////////////////////////////////
00126   //                                                                     //
00127   // Private functions:                                                  //
00128   //                                                                     //
00129   /////////////////////////////////////////////////////////////////////////
00130 
00131   void setVariable( Chars varName, Chars value );
00132   // used by readFrom() to set variables
00133 
00134   void eatWhite( char* input );
00135   // kills spaces in 'input'
00136 
00137 
00138   /////////////////////////////////////////////////////////////////////////
00139   //                                                                     //
00140   // Data members:                                                       //
00141   //                                                                     //
00142   /////////////////////////////////////////////////////////////////////////
00143   
00144   int population;                         // population size
00145   int generations;                        // number of generations
00146   int crossover;                          // chance of crossover
00147   int mutation;                           // chance of mutation
00148   ElitistSelectionType elitistSelection;  // type of elitist selection
00149   bool bFitnessScaling;                   // fitness scaling: yes/no
00150   int theReport;                             // report every ... generations
00151   int theFitnessPrint;    // print all fitness values every ... generations
00152   int thePopulationPrint; // print the population every ... generations
00153 };
00154 
00155 #endif

Generated at Tue Jun 19 09:49:35 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001