moSimpleMoveTabuList.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 // "moSimpleMoveTabuList.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 __moSimpleMoveTabuList_h
00013 #define __moSimpleMoveTabuList_h
00014 
00015 #include <list>
00016 #include <iterator>
00017 
00018 #include "moTabuList.h"
00019 
00021 template <class M>
00022 class moSimpleMoveTabuList: public moTabuList < M >
00023 {
00024   
00025 public:
00026   
00028   typedef typename M::EOType EOT;
00029 
00031   /*
00032     \param __size The maximum size of the move tabu list.
00033    */
00034   moSimpleMoveTabuList(unsigned int __size): maxSize(__size)
00035   {
00036     currentSize=0;
00037   }
00038 
00040 
00045   bool
00046   operator () (const M & __move, const EOT & __sol) 
00047   {
00048     typename std::list<M>::iterator it;
00049     
00050     it=tabuList.begin();
00051     while(it!=tabuList.end()&&(!((*it)==__move)))
00052       {
00053         it++;
00054       }
00055     
00056     return it!=tabuList.end();
00057   }
00058   
00059   void
00060   add (const M & __move, const EOT & __sol)
00061   {
00062     if(currentSize!=0)
00063       {
00064         // Useful in the case of a move has been kept thanks to the moAspirCrit.
00065         // In this case, the move can already be in the tabuList.
00066         removeMove(__move);
00067       }
00068 
00069     tabuList.push_back(__move);
00070     
00071     if(currentSize==maxSize)
00072       {
00073         tabuList.erase(tabuList.begin());
00074       }
00075     else
00076       {
00077         currentSize++;
00078       }
00079   }
00080   
00081   void
00082   update ()
00083   {
00084     //nothing to do
00085   }
00086 
00087   void
00088   init ()
00089   {
00090     //nothing to do
00091   }
00092 
00093 private:
00094   
00096 
00099   void
00100   removeMove(const M & __move)
00101   {
00102     typename std::list<M>::iterator it;
00103     
00104     it=tabuList.begin();
00105     while(it!=tabuList.end()&&(!((*it)==__move)))
00106       {
00107         it++;
00108       }
00109 
00110     if(it!=tabuList.end())
00111       {
00112         tabuList.erase(it);
00113       }
00114   }
00115 
00117   unsigned int maxSize;
00118 
00120   unsigned int currentSize;
00121   
00123   std::list<M> tabuList;
00124 };
00125 
00126 #endif

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