moTS.h

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 // "moTS.h"
00004 
00005 // (c) OPAC Team, LIFL, 2003-2006
00006 
00007 /* LICENCE TEXT
00008       
00009    Contact: paradiseo-help@lists.gforge.inria.fr
00010 */
00011 
00012 #ifndef __moTS_h
00013 #define __moTS_h
00014 
00015 #include <eoOp.h>
00016 #include <eoEvalFunc.h>
00017 
00018 #include "moAlgo.h"
00019 #include "moSolContinue.h"
00020 
00021 #include "moMoveExpl.h"
00022 #include "moTSMoveLoopExpl.h"
00023 
00024 
00026 
00029 template < class M > class moTS:public moAlgo < typename M::EOType >
00030 {
00031 
00033   typedef
00034     typename
00035     M::EOType
00036     EOT;
00037 
00039   typedef
00040     typename
00041     EOT::Fitness
00042     Fitness;
00043 
00044 public:
00045 
00047 
00058 moTS (moMoveInit < M > &__move_init, moNextMove < M > &__next_move, moMoveIncrEval < M > &__incr_eval, moTabuList < M > &__tabu_list, moAspirCrit < M > &__aspir_crit, moSolContinue < EOT > &__cont, eoEvalFunc < EOT > &__full_eval):move_expl (*new moTSMoveLoopExpl < M >
00059              (__move_init, __next_move, __incr_eval, __tabu_list,
00060               __aspir_crit)), cont (__cont), full_eval (__full_eval)
00061       {}
00062 
00064 
00071 moTS (moMoveExpl < M > &__move_expl, moSolContinue < EOT > &__cont, eoEvalFunc < EOT > &__full_eval):move_expl (__move_expl),
00072     cont (__cont),
00073     full_eval (__full_eval)
00074     {}
00075 
00077 
00085   bool operator   ()(EOT & __sol)
00086   {
00087     if (__sol.invalid ())
00088       {
00089         full_eval (__sol);
00090       }
00091 
00092     M move;
00093 
00094     EOT best_sol, new_sol;
00095     best_sol = __sol;
00096 
00097     cont.init ();
00098 
00099     do
00100       {
00101         new_sol = __sol;
00102 
00103         try
00104         {
00105 
00106           move_expl (__sol, new_sol);
00107 
00108         }
00109         catch (EmptySelection & __ex)
00110         {
00111 
00112           break;
00113         }
00114 
00115         /* Updating the best solution found until now ? */
00116         if (new_sol.fitness () > __sol.fitness ())
00117           {
00118             best_sol = new_sol;
00119           }
00120 
00121         __sol = new_sol;
00122 
00123       }
00124     while (cont (__sol));
00125 
00126     __sol = best_sol;
00127  
00128     return true;
00129   }
00130 
00131 private:
00132 
00134   moMoveExpl < M > &move_expl;
00135 
00137   moSolContinue < EOT > &cont;
00138 
00140   eoEvalFunc < EOT > &full_eval;
00141 };
00142 
00143 #endif

Generated on Fri Sep 14 09:52:19 2007 for PARADISEO-MO by  doxygen 1.4.7