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 = __sol, new_sol;
00095 
00096     cont.init ();
00097 
00098     do
00099       {
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
00116            found until now ? */
00117         if (new_sol.fitness () > __sol.fitness ())
00118           {
00119             best_sol = new_sol;
00120           }
00121 
00122         __sol = new_sol;
00123 
00124       }
00125     while (cont (__sol));
00126 
00127     __sol = best_sol;
00128  
00129     return true;
00130   }
00131 
00132 private:
00133 
00135   moMoveExpl < M > &move_expl;
00136 
00138   moSolContinue < EOT > &cont;
00139 
00141   eoEvalFunc < EOT > &full_eval;
00142 };
00143 
00144 #endif

Generated on Fri Jul 6 17:23:18 2007 for PARADISEO-MO by  doxygen 1.5.2