UniquePop.cpp

Go to the documentation of this file.
00001 #include "UniquePop.h"
00002 #include <boost/functional/hash.hpp>
00003 #include <iomanip>
00004 UniquePop::UniquePop()
00005 {}
00006 UniquePop::~UniquePop()
00007 {}
00008 
00009 using namespace std;
00010 
00011 bool UniquePop::Insert(const tfitvec &fitness, const ttranscribed &popmember)
00012 {
00013         pair<tmemberset::iterator,bool> insertresult;
00014          
00015         insertresult = Members.insert(popmember);
00016         if ( insertresult.second) // if insert successfull
00017         {
00018                 std::size_t hash = boost::hash_range(popmember.begin(), popmember.end()); //create a hashvalue for the populationmember
00019                 FitMap.insert(make_pair(fitness,insertresult.first));
00020                 MemberHashMap.insert(make_pair(hash,fitness));
00021                 return true;
00022         }
00023         return false;
00024 }
00025 
00026 bool UniquePop::Find(const ttranscribed &popmember, tfitvec &fitness)
00027 {
00028         tmembermap::iterator pos;
00029         std::size_t hash = boost::hash_range(popmember.begin(), popmember.end());
00030         pos = MemberHashMap.find(hash);
00031         if (pos == MemberHashMap.end())
00032                 return false;
00033         fitness = pos->second;
00034         return true;    
00035 }
00036 
00037 void UniquePop::PrintAll(std::ostream &output)
00038 {
00039         tfitmap::iterator outit;
00040         
00041         for (outit = FitMap.begin(); outit !=FitMap.end(); ++outit)
00042         {
00043                 output << setprecision(10);
00044                 copy(outit->first.begin(),outit->first.end(),ostream_iterator<double>(output, " "));
00045                 output << "    ";
00046                 copy(outit->second->begin(),outit->second->end(),ostream_iterator<double>(output, " "));
00047                 output << endl;
00048         }
00049 }

Generated on Fri Jul 4 15:30:21 2008 for GPLIB++ by  doxygen 1.5.5