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 #ifndef _moTSMoveLoopExpl_h
00037 #define _moTSMoveLoopExpl_h
00038
00039 #include <moMoveLoopExpl.h>
00040 #include <moMoveInit.h>
00041 #include <moNextMove.h>
00042 #include <moMoveIncrEval.h>
00043 #include <moMoveSelect.h>
00044 #include <moTabuList.h>
00045 #include <moAspirCrit.h>
00046 #include <moBestImprSelect.h>
00047
00049
00052 template < class M >
00053 class moTSMoveLoopExpl:public moMoveLoopExpl < M >
00054 {
00056 typedef typename M::EOType EOT;
00057
00059 typedef typename M::EOType::Fitness Fitness;
00060
00061 public:
00062
00064
00071 moTSMoveLoopExpl (moMoveInit < M > & _move_initializer, moNextMove < M > & _next_move_generator,
00072 moMoveIncrEval < M > & _incremental_evaluation, moTabuList < M > & _tabu_list,
00073 moAspirCrit < M > & _aspiration_criterion):
00074 move_initializer(_move_initializer), next_move_generator(_next_move_generator), incremental_evaluation(_incremental_evaluation),
00075 tabu_list(_tabu_list), aspiration_criterion(_aspiration_criterion)
00076 {
00077 tabu_list.init ();
00078 aspiration_criterion.init ();
00079 }
00080
00082
00090 void operator () (const EOT & _old_solution, EOT & _new_solution)
00091 {
00092 M move, best_move;
00093 Fitness fitness, best_move_fitness;
00094
00095 bool move_is_tabu, aspiration_criterion_is_verified, selection_update_is_ok, has_next_move;
00096
00097 if( _old_solution.invalid() )
00098 {
00099 throw std::runtime_error("[moTSMoveLoopExpl.h]: The current solution has not been evaluated.");
00100 }
00101
00102
00103 _new_solution=(EOT)_old_solution;
00104
00105
00106 move_initializer (move, _old_solution);
00107
00108 move_selection.init( _old_solution.fitness() );
00109
00110 do
00111 {
00112 fitness = incremental_evaluation(move, _old_solution);
00113
00114 move_is_tabu = tabu_list(move, _old_solution);
00115
00116 aspiration_criterion_is_verified = aspiration_criterion(move, fitness);
00117
00118 if( !move_is_tabu || aspiration_criterion_is_verified )
00119 {
00120 selection_update_is_ok = move_selection.update(move, fitness);
00121 }
00122
00123 has_next_move = next_move_generator(move, _old_solution);
00124 }
00125 while( has_next_move && selection_update_is_ok );
00126
00127 move_selection(best_move, best_move_fitness);
00128
00129
00130 best_move(_new_solution);
00131
00132
00133 _new_solution.fitness(best_move_fitness);
00134
00135
00136 tabu_list.update ();
00137
00138
00139 tabu_list.add(best_move, _new_solution);
00140 }
00141
00142 private:
00143
00145 moMoveInit < M > & move_initializer;
00146
00148 moNextMove < M > & next_move_generator;
00149
00151 moMoveIncrEval < M > & incremental_evaluation;
00152
00154 moBestImprSelect < M > move_selection;
00155
00157 moTabuList < M > & tabu_list;
00158
00160 moAspirCrit < M > & aspiration_criterion;
00161 };
00162
00163 #endif