- Main Page
- Classes
- Files

- Search for |

# 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 #include <pthread.h>
    00025
    00027
    00030 template < class M > class moTS:public moAlgo < typename M::EOType >
    00031 {
    00032
    00034   typedef
    00035     typename
    00036     M::EOType
    00037     EOT;
    00038
    00040   typedef
    00041     typename
    00042     EOT::Fitness
    00043     Fitness;
    00044
    00045 public:
    00046
    00048
    00059 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 >
    00060              (__move_init, __next_move, __incr_eval, __tabu_list,
    00061               __aspir_crit)), cont (__cont), full_eval (__full_eval)
    00062   {
    00063
    00064     if (first_time)
    00065       {
    00066
    00067         pthread_mutex_init (&mutex, 0);
    00068
    00069         first_time = false;
    00070       }
    00071   }
    00072
    00074
    00081 moTS (moMoveExpl < M > &__move_expl, moSolContinue < EOT > &__cont, eoEvalFunc < EOT > &__full_eval):move_expl (__move_expl),
    00082     cont (__cont),
    00083     full_eval (__full_eval)
    00084   {
    00085
    00086     if (first_time)
    00087       {
    00088
    00089         pthread_mutex_init (&mutex, 0);
    00090
    00091         first_time = false;
    00092       }
    00093   }
    00094
    00096
    00104   bool operator   ()(EOT & __sol)
    00105   {
    00106
    00107     pthread_mutex_lock (&mutex);
    00108
    00109     if (__sol.invalid ())
    00110       {
    00111         full_eval (__sol);
    00112       }
    00113
    00114     M move;
    00115
    00116     EOT best_sol = __sol, new_sol;
    00117
    00118     cont.init ();
    00119
    00120     do
    00121       {
    00122
    00123         new_sol = __sol;
    00124
    00125         try
    00126         {
    00127
    00128           move_expl (__sol, new_sol);
    00129
    00130         }
    00131         catch (EmptySelection & __ex)
    00132         {
    00133
    00134           break;
    00135         }
    00136
    00137         /* Updating the best solution
    00138            found until now ? */
    00139         if (new_sol.fitness () > __sol.fitness ())
    00140           {
    00141             best_sol = new_sol;
    00142           }
    00143
    00144         __sol = new_sol;
    00145
    00146       }
    00147     while (cont (__sol));
    00148
    00149     __sol = best_sol;
    00150
    00151     pthread_mutex_unlock (&mutex);
    00152
    00153     return true;
    00154   }
    00155
    00156 private:
    00157
    00159   static bool first_time;
    00160
    00162   static  pthread_mutex_t  mutex;
    00163
    00165   moMoveExpl < M > &move_expl;
    00166
    00168   moSolContinue < EOT > &cont;
    00169
    00171   eoEvalFunc < EOT > &full_eval;
    00172 };
    00173
    00175 template < class EOT > pthread_mutex_t moTS < EOT >::mutex;
    00176
    00178 template < class EOT > bool moTS < EOT >::first_time = true;
    00179
    00180 #endif