GAChromosome.H

Go to the documentation of this file.
00001 /*!@file GA/GAChromosome.H A chromosome class for genetic algorithm. */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/GA/GAChromosome.H $
00035 // $Id: GAChromosome.H 6003 2005-11-29 17:22:45Z rjpeters $
00036 //
00037 
00038 #ifndef GACHROMOSOME_H
00039 #define GACHROMOSOME_H
00040 
00041 #include <iosfwd>
00042 
00043 //! Chromosome class for genetic algorithm
00044 /*! This is a chromosome class for genetic algorithm, which is an
00045     array of genes (int with value of -1, 0 or 1). */
00046 
00047 class GAChromosome
00048 {
00049   friend std::istream& operator>>(std::istream& in, GAChromosome& c);
00050 
00051   friend std::ostream& operator<<(std::ostream& in, GAChromosome& c);
00052 
00053 public:
00054 
00055   // ############################################################
00056   /*! @name Constructor, destructor and initialization.*/
00057   //@{
00058 
00059   //! Uninitialized constructor. Need to call resize() later.
00060   GAChromosome();
00061 
00062   //! Construct from C array.
00063   GAChromosome(const int N, const int *a);
00064 
00065   //! Construct random chromosome.
00066   GAChromosome(const int N);
00067 
00068   //! Copy constructor.
00069   GAChromosome(const GAChromosome& c);
00070 
00071   //! Change size, do not initialize.
00072   void resize(const int N);
00073 
00074   //! Initialize from C array.
00075   void init(const int N, const int *a);
00076 
00077   //! Initialize randomly.
00078   void init(const int N);
00079 
00080   //! Destructor.
00081   ~GAChromosome();
00082 
00083   //@}
00084 
00085   // ############################################################
00086   /*! @name Acces functions */
00087   //@{
00088 
00089   //! Return the size of the chromosome.
00090   int get_size() const;
00091 
00092   //! Set the gene #i to a.
00093   void set_gene(const int i, const int a);
00094 
00095   //! Return the gene #i
00096   int get_gene(const int i) const;
00097 
00098   //! Set the fitness to a.
00099   void set_fitness(const float a);
00100 
00101   //! Return the fitness.
00102   float get_fitness() const;
00103 
00104   //! Set the linear fitness to a.
00105   void set_linear_fitness(const float a);
00106 
00107   //! Return the linear fitness.
00108   float get_linear_fitness() const;
00109 
00110   //! Set breedings to a.
00111   void set_breedings(const int a);
00112 
00113   //! Return the breedings.
00114   int get_breedings() const;
00115 
00116   //@}
00117 
00118   // ############################################################
00119   /*! @name Operators overloading */
00120   //@{
00121 
00122   //! Overload of assignment operator.
00123   GAChromosome& operator=(const GAChromosome& c);
00124 
00125   //! Overload of less-than operator.
00126   /*! c1 < c2 if c1 as less breedings than c2 */
00127   bool operator<(const GAChromosome& c) const;
00128 
00129   //@}
00130 
00131   // ############################################################
00132   /*! @name Evolve functions */
00133   //@{
00134 
00135   //! Change one gene randomly.
00136   void mutation();
00137 
00138   //! Add one breeding.
00139   void add_breeding();
00140 
00141   //! Use one breeding.
00142   void use_breeding();
00143 
00144   //@}
00145 
00146 private:
00147   float fitness;
00148   float linear_fitness;
00149   int breedings;
00150   int size;
00151   int *genes;
00152 };
00153 
00154 //! << overloading.
00155 std::istream& operator>> (std::istream& in, GAChromosome& c);
00156 
00157 //! >> overloading.
00158 std::ostream& operator<< (std::ostream& out, GAChromosome& c);
00159 
00160 #endif
00161 
00162 // ######################################################################
00163 /* So things look consistent in everyone's emacs... */
00164 /* Local Variables: */
00165 /* indent-tabs-mode: nil */
00166 /* End: */
Generated on Sun May 8 08:40:39 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3