moSimpleSolutionTabuList.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 // "moSimpleSolutionTabuList.h"
00004 
00005 // (c) OPAC Team, LIFL, 2003-2007
00006 
00007 /* LICENCE TEXT 
00008    
00009    Contact: paradiseo-help@lists.gforge.inria.fr
00010 */
00011 
00012 #ifndef __moSimpleSolutionTabuList_h
00013 #define __moSimpleSolutionTabuList_h
00014 
00015 #include <list>
00016 #include <iterator>
00017 
00018 #include "moTabuList.h"
00019 
00021 template <class M>
00022 class moSimpleSolutionTabuList: public moTabuList < M >
00023 {
00024   
00025 public:
00026 
00028   typedef typename M::EOType EOT;
00029   
00031 
00034   moSimpleSolutionTabuList(unsigned int __size): maxSize(__size)
00035   {
00036     currentSize=0;
00037   }
00038   
00040 
00045   bool operator () (const M & __move, const EOT & __sol) 
00046   {
00047     typename std::list<EOT>::iterator it;
00048   
00049     M _move=(M)__move;
00050     EOT _sol=(EOT) __sol;
00051 
00052     _move(_sol);
00053   
00054     it=tabuList.begin();
00055     while(it!=tabuList.end()&&(!((*it)==_sol)))
00056       {
00057         it++;
00058       }
00059     
00060     return it!=tabuList.end();
00061   }
00062   
00063   void
00064   add (const M & __move, const EOT & __sol)
00065   {
00066     M _move=(M)__move;
00067     EOT _sol=(EOT) _sol;
00068     
00069     _move(_sol);
00070 
00071     if(currentSize!=0)
00072       {
00073         // Useful in the case of a solution has been kept thanks to the moAspirCrit.
00074         // In this case, the solution can already be in the tabuList.
00075         removeSolution(_sol);
00076       }
00077     
00078     tabuList.push_back(_sol);
00079     
00080     if(currentSize==maxSize)
00081       {
00082         tabuList.erase(tabuList.begin());
00083       }
00084     else
00085       {
00086         currentSize++;
00087       }
00088   }
00089 
00090   void
00091   update ()
00092   {
00093     //nothing to do
00094   }
00095 
00096   void
00097   init ()
00098   {
00099     //nothing to do
00100   }
00101 
00102 private:
00103 
00105 
00108   void
00109   removeSolution(const EOT & __sol)
00110   {
00111     typename std::list<EOT>::iterator it;
00112 
00113     it=tabuList.begin();
00114     while(it!=tabuList.end()&&(!((*it)==__sol)))
00115       {
00116         it++;
00117       }
00118 
00119     if(it!=tabuList.end())
00120       {
00121         tabuList.erase(it);
00122       }
00123   }
00124   
00126   unsigned int maxSize;
00127 
00129   unsigned int currentSize;
00130   
00132   std::list<EOT> tabuList;
00133 };
00134 
00135 #endif

Generated on Tue Jun 26 13:18:40 2007 for PARADISEO-MO by  doxygen 1.5.2