00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef __moTS_h
00038 #define __moTS_h
00039
00040 #include <eoOp.h>
00041 #include <eoEvalFunc.h>
00042
00043 #include "moAlgo.h"
00044 #include "moSolContinue.h"
00045
00046 #include "moMoveExpl.h"
00047 #include "moTSMoveLoopExpl.h"
00048
00049
00051
00054 template < class M > class moTS:public moAlgo < typename M::EOType >
00055 {
00056
00058 typedef
00059 typename
00060 M::EOType
00061 EOT;
00062
00064 typedef
00065 typename
00066 EOT::Fitness
00067 Fitness;
00068
00069 public:
00070
00072
00083 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 >
00084 (__move_init, __next_move, __incr_eval, __tabu_list,
00085 __aspir_crit)), cont (__cont), full_eval (__full_eval)
00086 {}
00087
00089
00096 moTS (moMoveExpl < M > &__move_expl, moSolContinue < EOT > &__cont, eoEvalFunc < EOT > &__full_eval):move_expl (__move_expl),
00097 cont (__cont),
00098 full_eval (__full_eval)
00099 {}
00100
00102
00110 bool operator ()(EOT & __sol)
00111 {
00112 if (__sol.invalid ())
00113 {
00114 full_eval (__sol);
00115 }
00116
00117 M move;
00118
00119 EOT best_sol = __sol, new_sol;
00120
00121 cont.init ();
00122
00123 do
00124 {
00125
00126 new_sol = __sol;
00127
00128 try
00129 {
00130
00131 move_expl (__sol, new_sol);
00132
00133 }
00134 catch (EmptySelection & __ex)
00135 {
00136
00137 break;
00138 }
00139
00140
00141
00142 if (new_sol.fitness () > __sol.fitness ())
00143 {
00144 best_sol = new_sol;
00145 }
00146
00147 __sol = new_sol;
00148
00149 }
00150 while (cont (__sol));
00151
00152 __sol = best_sol;
00153
00154 return true;
00155 }
00156
00157 private:
00158
00160 moMoveExpl < M > &move_expl;
00161
00163 moSolContinue < EOT > &cont;
00164
00166 eoEvalFunc < EOT > &full_eval;
00167 };
00168
00169 #endif