UniquePop.h

Go to the documentation of this file.
00001 #ifndef CUNIQUEPOP_H
00002 #define CUNIQUEPOP_H
00003 #include <boost/unordered_map.hpp>
00004 #include <fstream>
00005 #include "gentypes.h"
00006 namespace gplib
00007   {
00008     /** \addtogroup gainv Genetic algorithm optimization */
00009     /* @{ */
00010     //! This class stores a single unique copy of each population member that is added to it
00011     /*! In order to avoid duplicate output of inversion results at the end of the genetic algorithm
00012      * run and have a compact history of all models evaluated during the GA run, we have this class
00013      * that makes sure that we only have a single copy of each population member. This class also
00014      * stores the associated fitness values, so we can use it to look up the fitness of a member
00015      * instead of calculating it if the member has already been evaluated before.
00016      */
00017     class UniquePop
00018       {
00019     private:
00020       struct memb_equal
00021         {
00022         bool operator()(ttranscribed const& p1, ttranscribed const& p2) const
00023           {
00024             return std::equal(p1.begin(), p1.end(), p2.begin());
00025           }
00026         };
00027 
00028       struct memb_hash: std::unary_function<ttranscribed, std::size_t>
00029         {
00030         std::size_t operator()(ttranscribed const& p) const
00031           {
00032             std::size_t seed = 0;
00033             const size_t length = p.size();
00034             for (size_t i = 0; i < length; ++i)
00035               {
00036                 boost::hash_combine(seed, p(i));
00037               }
00038             return seed;
00039           }
00040         };
00041 
00042       typedef boost::unordered_map<ttranscribed, tfitvec,memb_hash,memb_equal> tmembermap;
00043       tmembermap MemberHashMap;
00044     public:
00045       bool Find(const ttranscribed &popmember, tfitvec &fitness);
00046       bool Insert(const tfitvec &fitness, const ttranscribed &popmember);
00047       void PrintAll(std::ostream &output);
00048       UniquePop();
00049       virtual ~UniquePop();
00050       };
00051   /* @} */
00052   }
00053 #endif // CUNIQUEPOP_H

Generated on Tue May 4 16:52:15 2010 for GPLIB++ by  doxygen 1.5.8